Created
December 5, 2013 03:22
-
-
Save fakenickels/7799638 to your computer and use it in GitHub Desktop.
Simple Encrypt-Decrypt Algorithm
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 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