Created
January 31, 2018 03:32
-
-
Save ril3y/501020a4e3923f3422253a5501eff6fe to your computer and use it in GitHub Desktop.
Simple Javascript String XOR utility
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
var xor_str = function(s,K) | |
{ | |
c = ''; | |
for(i=0; i<str.length; i++) { | |
for(ik=0; ik<K.length; ik++){ | |
c += String.fromCharCode(str[i].charCodeAt(0).toString(10) ^ key.charCodeAt(0).toString(10)); // XORing with letter 'K' | |
} | |
} | |
return c; | |
} |
function xorString(init) {
const initArr = Array.from(init);
const initLength = initArr.length;
return function * (input) {
let idx = 0;
for (const ch of input) {
yield initLength === 0 ? ch : String.fromCharCode(ch.charCodeAt(0) ^ initArr[(idx ++) % initLength].charCodeAt(0));
}
}
}
const xorStrings = (str1, str2) => {
str1 = str1.split("");
str2= str2.split("");
let betw=0;
for(let i = 0; i<str1.length; i++)
betw=str1[i].charCodeAt(0)^str2[i].charCodeAt(0)^betw;
return betw == 0 ? true : false;
};
@TimofeyOpal please use markdown
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome! Thanks!