Created
July 27, 2024 13:08
-
-
Save un4ckn0wl3z/55c811e61190ff618aa4fdc05a5bbcc5 to your computer and use it in GitHub Desktop.
xorDecrypt.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 xorDecrypt(cipherText, hexKey) { | |
// Convert the hexadecimal key to a byte array | |
let key = hexKey.match(/.{1,2}/g).map(byte => parseInt(byte, 16)); | |
// Decode the base64 encoded cipher text to a byte array | |
let cipherBytes = atob(cipherText).split('').map(char => char.charCodeAt(0)); | |
// XOR decryption | |
let plainBytes = cipherBytes.map((byte, index) => byte ^ key[index % key.length]); | |
// Convert the byte array to a string | |
let plainText = String.fromCharCode.apply(null, plainBytes); | |
return plainText; | |
} | |
// Example usage | |
let cipherText = 'U29tZUVuY3J5cHRlZERhdGE='; // base64 encoded XOR encrypted text | |
let hexKey = '1a2b3c4d'; // hexadecimal key | |
let decryptedText = xorDecrypt(cipherText, hexKey); | |
console.log(decryptedText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment