-
-
Save Wostafa/c3732ea41ce5f5184fdff5a01d66e205 to your computer and use it in GitHub Desktop.
javascript.xor.encryption.js
This file contains hidden or 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
| function EncodeB64(str) { | |
| return window.btoa(unescape(encodeURIComponent(str))); | |
| } | |
| function DecodeB64(str) { | |
| return decodeURIComponent(escape(window.atob(str))); | |
| } | |
| function XorEncrypt(data, salt) { | |
| data = EncodeB64(data); | |
| let salts = Array.from(salt); | |
| let output = []; | |
| for (let i = 0; i < data.length; i++) { | |
| let charCode = data.charCodeAt(i) ^ salts[i % salts.length].charCodeAt(0); | |
| output.push(String.fromCharCode(charCode)); | |
| } | |
| let result = output.join(""); | |
| return EncodeB64(result); | |
| } | |
| function XorDecrypt(data, salt) { | |
| data = DecodeB64(data); | |
| let salts = Array.from(salt); | |
| let output = []; | |
| for (let i = 0; i < data.length; i++) { | |
| let charCode = data.charCodeAt(i) ^ salts[i % salts.length].charCodeAt(0); | |
| output.push(String.fromCharCode(charCode)); | |
| } | |
| let res = output.join(""); | |
| return DecodeB64(res); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment