Skip to content

Instantly share code, notes, and snippets.

@seveniu
Created May 5, 2015 04:33
Show Gist options
  • Save seveniu/dd9932c6cc04a59eb586 to your computer and use it in GitHub Desktop.
Save seveniu/dd9932c6cc04a59eb586 to your computer and use it in GitHub Desktop.
string xor
public static String xorString(String text,String key) {
byte[] textBytes = text.getBytes();
byte[] keyBytes = key.getBytes();
byte[] newCharArray = new byte[textBytes.length];
for (int i = 0; i < textBytes.length; i++) {
byte c = textBytes[i];
int strIndex = i%(keyBytes.length);
newCharArray[i] = (byte)(c ^ keyBytes[strIndex]);
}
return new String(newCharArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment