Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created December 5, 2013 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakenickels/7799638 to your computer and use it in GitHub Desktop.
Save fakenickels/7799638 to your computer and use it in GitHub Desktop.
Simple Encrypt-Decrypt Algorithm
var key = 'heuehueheubrbrbrprasswithlasers333';
/*
* Simple Encrypt-Decrypt Algorithm
* mode = 1 or -1
* 1 -> Encrypt mode
* -1 -> Decrypt mode
*/
function simpleED( str, mode ){
var j = 0, temp, parsed = '';
for( var i = 0, count = str.length; i < count; i++ ){
j++;
temp = str[i].charCodeAt(0) + ( mode * key[j].charCodeAt(0) );
if( key.length-1 === j ){ j = 1; }
if( temp > 255 ){ temp -= 256 }
parsed += String.fromCharCode(temp)
}
return parsed;
}
// ...
simpleED('brazilianday', 1) // returns ÇçÆâÞÑÑÆãÆÓÛ;
simpleED('ÇçÆâÞÑÑÆãÆÓÛ', -1)// returns brazilian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment