Skip to content

Instantly share code, notes, and snippets.

@JH108
Created July 14, 2020 13:31
Show Gist options
  • Save JH108/323f9b74d407e2f84a80e4d1035a6f26 to your computer and use it in GitHub Desktop.
Save JH108/323f9b74d407e2f84a80e4d1035a6f26 to your computer and use it in GitHub Desktop.
XOR A String using a key
// 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