Created
July 14, 2020 13:31
-
-
Save JH108/323f9b74d407e2f84a80e4d1035a6f26 to your computer and use it in GitHub Desktop.
XOR A String using a key
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
// This doesn't seem like it would be secure since whatever "key" was being stored on the device | |
// would have to have either been generated by the device or requested by the device | |
export const encryptXOR = (text, key) => { | |
const bytes = utf8.encode(text); | |
const output = []; | |
for (let i = 0; i < bytes.length; i++) { | |
output[i] = String.fromCharCode( | |
bytes[i].charCodeAt(0) ^ key[i % key.length].charCodeAt(0) | |
); | |
} | |
return base64.encode(output.join('')); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment