mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
Added JavaScript implementationg
This commit is contained in:
parent
5fe7d2481d
commit
9149a65457
17
JavaScript/XOREncryption.js
Normal file
17
JavaScript/XOREncryption.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
function encryptDecrypt(input) {
|
||||||
|
var key = ['K', 'C', 'Q']; //Can be any chars, and any size array
|
||||||
|
var output = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < input.length; i++) {
|
||||||
|
var charCode = input.charCodeAt(i) ^ key[i % key.length].charCodeAt(0);
|
||||||
|
output.push(String.fromCharCode(charCode));
|
||||||
|
}
|
||||||
|
return output.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var encrypted = encryptDecrypt("kylewbanks.com");
|
||||||
|
console.log("Encrypted:"+encrypted);
|
||||||
|
|
||||||
|
var decrypted = encryptDecrypt(encrypted);
|
||||||
|
console.log("Decrypted:"+decrypted);
|
Loading…
Reference in New Issue
Block a user