Created
May 17, 2022 10:47
-
-
Save danibram/4cc4e77d58d5d67c8d9c51781004f437 to your computer and use it in GitHub Desktop.
XOR encode decode browser
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
const s1 = `` | |
const s2 = `` | |
function utf8_to_b64( str ) { | |
return btoa(unescape(encodeURIComponent( str ))); | |
} | |
function b64_to_utf8( str ) { | |
return decodeURIComponent(escape(atob( str ))); | |
} | |
function xor (input, key) { | |
let output = '' | |
for (let i = 0; i < input.length; i++) { | |
output += String.fromCharCode(input.charCodeAt(i) ^ key.charCodeAt(i % key.length)) | |
} | |
return output | |
} | |
function encode(text) { | |
const messageDecipher = xor(xor(utf8_to_b64(text), s1), s2) | |
return utf8_to_b64(messageDecipher) | |
} | |
function decode(text) { | |
const messageDecipher = b64_to_utf8(xor(xor(b64_to_utf8(text), s2), s1)) | |
return messageDecipher | |
} | |
let text = "wedc" | |
let enc = encode(text) | |
console.log(">>>",enc) | |
console.log("<<<",decode(enc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment