|
Post by Eric on Nov 15, 2005 2:43:16 GMT
Well, I got a stupid letter from a university, anyways they explained a cipher on it. So... I decided to make a script. Here it is: String.prototype.Vigenere = function(key, side) { str = this.toLowerCase(); key = key.toLowerCase(); var alph = 'abcdefghijklmnopqrstuvwxyz'; var enc = ''; var k = 0; var temp = 0; for(var s = 0; s < str.length; s++) { if(alph.indexOf(str.charAt(s)) != -1) { if(side) { temp = alph.indexOf(str.charAt(s)) - alph.indexOf(key.charAt(k)); if(temp < 0) temp += 26; } else { temp = alph.indexOf(str.charAt(s)) + alph.indexOf(key.charAt(k)); if(temp > 25) temp -= 26; } enc += alph.charAt(temp); if(k < key.length - 1) k++; else k = 0; } else { enc += str.charAt(s); } } return enc; }Ex: var testStr = 'test message'; document.write(testStr.viginere("foo", 0)); // Encrypt key: What you use to encrypt, must be the same to encrypt and decrypt side: As in which side of the encryption process (enc or dec). Anyways, use a true or false/1 or 0 value. 0 is encrypt, 1 is decrypt. Have fun!
|
|
|
Post by acoolie530 on Nov 15, 2005 21:56:44 GMT
Its kinda like the php str_rot13 function except its more like str_rot-1 :-P
|
|