-
-
Save anonymous/a110621fe731facb40ff to your computer and use it in GitHub Desktop.
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
function encrypt(s, pw) { | |
var a=0, i=0, myString='', textLen=s.length, pwLen=pw.length; | |
for (i=0; i<textLen; i++) { | |
a = parseInt(s.charCodeAt(i), 10); | |
a = a^(pw.charCodeAt(i % pwLen)); | |
a = a + ""; | |
while (a.length<3) { | |
a='0'+a; | |
} | |
myString += a; | |
} | |
return myString; // returned encrypted string | |
} | |
function decrypt(s, pw) { | |
var myString='', | |
a=0, i=0, pwLen=pw.length, | |
textLen=s.length, myHolder=""; | |
while(i < s.length-2) { | |
myHolder = s.charAt(i) + s.charAt(i+1) + s.charAt(i+2); | |
if (s.charAt(i) === '0') { | |
myHolder = s.charAt(i+1) + s.charAt(i+2); | |
} | |
if ((s.charAt(i) ==='0') && (s.charAt(i+1) === '0')) { | |
myHolder = s.charAt(i+2); | |
} | |
a = parseInt(myHolder, 10); | |
a = a^(pw.charCodeAt((i/3) % pwLen)); | |
myString += String.fromCharCode(a); | |
i+=3; | |
} | |
return myString; // returned decrypted string | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment