Answer the question
In order to leave comments, you need to log in
What is the correct way to change the encryption algorithm based on XOR?
Good day.
I have an implementation of an encryption algorithm:
String mesage = "Привет мир";
byte[] m = Calculate.encrypt(mesage, "тостер");
for (byte i : m) System.out.print(i);
System.out.println();
System.out.println(Calculate.decrypt(m, "тостер"));
public class Calculate {
public static byte[] encrypt(String text, String keyWord)
{
byte[] arr = text.getBytes();
byte[] keyarr = keyWord.getBytes();
byte[] result = new byte[arr.length];
for(int i = 0; i< arr.length; i++)
{
result[i] = (byte) (arr[i] ^ keyarr[i % keyarr.length]);
}
return result;
}
public static String decrypt(byte[] text, String keyWord)
{
byte[] result = new byte[text.length];
byte[] keyarr = keyWord.getBytes();
for(int i = 0; i < text.length;i++)
{
result[i] = (byte) (text[i] ^ keyarr[i% keyarr.length]);
}
return new String(result);
}
}
m
. Answer the question
In order to leave comments, you need to log in
The most normal option is to encode the ciphertext in base64 .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question