|
I am currently doing some encryption part of a cipher. The length of the ciphertext(encrypted text) is supposed to of the same length of the plaintext(original text). However, the ciphertext that I get is very long. I am using a textfile to contain the plaintext. Below is main code the for the read file and encryption part:
try {
input = new FileInputStream("/forum/input.txt");
bin = new BufferedInputStream(input);
int buffer;
int i = 0;
while((buffer = bin.read()) != -1) {
long l = (int)buffer;
long ciphertext = l ^ keystream;
String str = Long.toString(ciphertext);
for ( int x = 0; x < str.length(); ++x ) {
char ascii = str.charAt(x);
int y = (int) ascii;
System.out.print(y);
}
System.out.println();
if(i < 15)
{i++;}
else
{i = 0;}
}
} catch(Exception ex) {ex.printStackTrace();}
I am using string to get the plaintext and then convert it to long. I am using long so that I can perform the XOR operation with the keystream(in long[]).
Someone please help!!! I am running out of ideas on this >__<
|
|
|
Your inner loop seems to be running from the beginning to the end of the string on each character being read from the buffer in the outer loop.
semper fi...
|
|
|
I had managed to solve this problem by converting the keystream into 1 string and use substring to extract the bits that I want. Then, I convert back into their decimal values and perform XOR operation
|
|
|
|
|
|
|
|