hex - I have written the following program for XORing 2 cipher texts in hexadecimal using java. How do i convert output to ASCII -


i have written following program xoring 2 cipher texts in hexadecimal using java. output not correct. how convert output in ascii?

public class javaapplication1 {               public static void main(string[] args) {     string y="a12104c6134e57914f104f2521ba4422c4d7b184f4815541f80484e1e24161d64d54ba2210194510164d4f3a0534304e43e1e1da524612171b11701be45431cc1d16a52d11744e1961a114de55174f84e54371";     string z="32510ba9babebbbefd001547a810e67149caee11d945cd7fc81a05e9f85aac650e9052ba6a8cd8257bf14d13e6f0a803b54fde9e77472dbff89d71b57bddef121336cb85ccb8f3315f4b52e301d16e9f52f904";     string d;         string s="a";         char strfory[] = new char[2];        char strforz[] = new char[2];        string stry,strz;        for(int i=0; i<y.length();i+=2)         {         strfory[0]=y.charat(i);         strfory[1]=y.charat(i+1);         strforz[0]=z.charat(i);         strforz[1]=z.charat(i+1);         stry = new string(strfory);         strz = new string(strforz);         int a=integer.parseint(stry,16);         int b=integer.parseint(strz,16);         int c=a^b;         d=integer.tohexstring(c);         s=s.concat(d);     }     system.out.println(s);     } } 

try use java.math.biginteger:

import java.io.unsupportedencodingexception; import java.math.biginteger; import java.util.arrays;  class example {      private static final int values_radix = 16;     private static final string first_value = "a12104c6134e57914f104f2521ba4422c4d7b184f4815541f80484e1e24161d64d54ba2210194510164d4f3a0534304e43e1e1da524612171b11701be45431cc1d16a52d11744e1961a114de55174f84e54371";     private static final string second_value = "32510ba9babebbbefd001547a810e67149caee11d945cd7fc81a05e9f85aac650e9052ba6a8cd8257bf14d13e6f0a803b54fde9e77472dbff89d71b57bddef121336cb85ccb8f3315f4b52e301d16e9f52f904";      public static void main(string[] args) {         biginteger firstvaluetoxor = new biginteger(first_value, values_radix);         biginteger secondvaluetoxor = new biginteger(second_value, values_radix);         biginteger result = firstvaluetoxor.xor(secondvaluetoxor);         string stringresultrepresentation = result.tostring(values_radix);         system.out.println(stringresultrepresentation);          try {             byte[] asciiresultrepresentation = stringresultrepresentation.getbytes("us-ascii");             system.out.println(arrays.tostring(asciiresultrepresentation));         } catch (unsupportedencodingexception e) {             e.printstacktrace();         }     } } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -