Skip to content

Instantly share code, notes, and snippets.

@MarcoPolo
Created October 11, 2011 04:58
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 MarcoPolo/1277332 to your computer and use it in GitHub Desktop.
Save MarcoPolo/1277332 to your computer and use it in GitHub Desktop.
vignere in 25 lines of js
function encrypt(mess, key){
var i = (mess.length)/(key.length);
while (i>0){
key +=key;
i--;
}
key = key.substring(0, mess.length);
console.log('message is',mess)
console.log('key is',key.length);
var result = ''
for (var i=0; i < key.length; i++){
var column = key.charCodeAt(i);
var row = mess.charCodeAt(i)-97; //subtract 97 to just get the difference from a
var sum=row+column;
if (sum > 122){
sum=((row+column - 123) + 97);
console.log('too big');
}
result += String.fromCharCode(sum)
}
console.log(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment