-
-
Save jochemstoel/1fd342a3ca8e6635a581a21d2615a348 to your computer and use it in GitHub Desktop.
Encrypt and decrypt text with a password and this simple yet effective cypher
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 RollingCypher() { | |
var chars = " qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()_+-=[]\\{}|;':\",./<>?`~\t\r\n"; | |
chars = chars.concat(chars.concat(chars)); | |
function encrypt(s, p) { | |
var o = ""; | |
s = s.split(''); | |
p = p.split(''); | |
for (var i = 0; i < s.length; i++) { | |
o += chars[chars.indexOf(s[i]) + chars.indexOf(p[i % p.length])]; | |
} | |
return o; | |
} | |
function decrypt(s, pass) { | |
var o = ""; | |
s = s.split(''); | |
pass = pass.split(''); | |
for (var i = 0; i < s.length; i++) { | |
o += chars[chars.lastIndexOf(s[i]) - chars.indexOf(pass[i % pass.length])]; | |
} | |
return o; | |
} | |
this.encrypt = encrypt; | |
this.decrypt = decrypt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment