public class MyClass {
static String XOREncryption(String s, String key) {
int slen = s.length(), keylen = key.length();
char[] result = new char[slen];
for (int i = 0; i < slen; i++) {
result[i] = (char)(s.charAt(i) ^ key.charAt(i % keylen));
}
return new String(result);
}
public static void main(String args[]) {
String s = "Java is a high-level class-based object-oriented programming language";
String key = "secretkey";
String cipher = XOREncryption(s, key);
System.out.println(cipher);
String noncipher = XOREncryption(cipher, key);
System.out.println(noncipher);
}
}
/*
run:
9EES
Y C TT
RK
Java is a high-level class-based object-oriented programming language
*/