Created
May 5, 2015 04:33
-
-
Save seveniu/dd9932c6cc04a59eb586 to your computer and use it in GitHub Desktop.
string xor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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