mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
Added Java/Android implementation
This commit is contained in:
parent
485328c9cb
commit
c03cc34023
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.class
|
||||||
|
*.out
|
21
Java (Android compatible)/XOREncryption.java
Normal file
21
Java (Android compatible)/XOREncryption.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
public class XOREncryption {
|
||||||
|
|
||||||
|
private static String encryptDecrypt(String input) {
|
||||||
|
char[] key = {'K', 'C', 'Q'}; //Can be any chars, and any length array
|
||||||
|
StringBuilder output = new StringBuilder();
|
||||||
|
|
||||||
|
for(int i = 0; i < input.length(); i++) {
|
||||||
|
output.append((char) (input.charAt(i) ^ key[i % key.length]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String encrypted = XOREncryption.encryptDecrypt("kylewbanks.com");
|
||||||
|
System.out.println("Encrypted:" + encrypted);
|
||||||
|
|
||||||
|
String decrypted = XOREncryption.encryptDecrypt(encrypted);
|
||||||
|
System.out.println("Decrypted:" + decrypted);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user