I have this method which takes a BigInteger, makes another BigInteger (via rsa algorithm) then thats converted to binary, then thats broken up into blocks of 8 where i get the ascii value for that binary string.
ALL OF THAT WORKS
but im having trouble getting the ascii chars that i get from each binary string and making a new string out of them. Im trying to use the concat method built in but it doesnt seem to be working!
public static String Decrypt( BigInteger ct, BigInteger d, BigInteger mod ){ String pt = null; BigInteger message = ct.modPow(d, mod); //the decrypted message M but still in BigInteger form String plaintext = message.toString(2); if( plaintext.length() % 8 != 0 ){ plaintext = "00000000".substring( plaintext.length() % 8 ) + plaintext; } String c; int charCode = 0; for( int i = (plaintext.length()/8) - 1 ; i >= 0; i--){ charCode = Integer.parseInt((plaintext.substring(i*8, (i*8)+8)) , 2) ; c = new Character( (char) charCode).toString(); System.out.print(c); // here is where i need something like pt.concat(c) or something like that, I dont really want it printed } // i just want all of these chars to be put into the string pt System.out.println(); return pt; } as you can see in the comments thats what i am talking about, I mean by looking at the API for concat it seems what I am doing is right, but it just wont work!
Thanks if you could explain / show whats wrong!
String pt = null, so you are getting a null pointerString pt = "";and havept += c;at the place of interest. Also, you could skipc = new Character(...)and just do this:pt += "" + (char)charCode;BigInteger.toByteArray(). Drop the first byte if it is zero. Then use the remaining bytes to construct aStringfrom these. This will be a lot shorter and faster, but more difficult to debug in case anything goes wrong.