Skip to content

Instantly share code, notes, and snippets.

@SethVandebrooke
Created September 27, 2019 14:59
Show Gist options
  • Save SethVandebrooke/4909d0b68dbd7590948e01de8161818f to your computer and use it in GitHub Desktop.
Save SethVandebrooke/4909d0b68dbd7590948e01de8161818f to your computer and use it in GitHub Desktop.
Encrypt and decrypt text with a password and this simple yet effective cypher
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