简体   繁体   中英

how to convert 4 by 4 matrix of hexa decimal values in to plaintext?

String Res[][]={{"af","ea","ff","ea"},  
{"ea","ba","cc","aa"},
{"aa","cb","bc","cc"},
{"0a","ad","da","ff"}}; 

I am implementing AES 128 bit key.while decryption i am getting 4 by 4 matrix of hexa decimal values.How to convert this into string?

If you want something like that "afeaffeaeabaccaaaacbbccc0aaddaff", there it is :

    String Res[][]={{"af","ea","ff","ea"},  
    {"ea","ba","cc","aa"},
    {"aa","cb","bc","cc"},
    {"0a","ad","da","ff"}};
    StringBuilder strBldr = new StringBuilder();
    for(String[] ar : Res) {
        for(String str : ar) {
            strBldr.append(str);
        }
    }
    System.out.println(strBldr.toString());

http://ideone.com/2jfMob

If you meant to convert it to characters, can replace in loop:

strBldr.append((char) Integer.parseInt(str, 16));

That supposes characters are represented by one byte. If not, see for ex. this: http://ideone.com/kg2ZN5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM