Skip to content

Instantly share code, notes, and snippets.

@EnzoDiazDev
Last active August 15, 2021 19:46
Show Gist options
  • Save EnzoDiazDev/b71f3434367f9ca5a620fdd0cf75e867 to your computer and use it in GitHub Desktop.
Save EnzoDiazDev/b71f3434367f9ca5a620fdd0cf75e867 to your computer and use it in GitHub Desktop.
vigenere with functions p5
function vigenere_cipher(alphabet:string, key:string): (str:string, equation:cipher_equation) => string {
const L = alphabet.length;
return function(str, equation) { // this is the previous 'vigenere_cipher' function but as an anonymous function.
const repeated_key = repeat_key(str.length, key);
return str
.split("")
.map((C, i) => {
const Ci = alphabet.indexOf(C);
const K = repeated_key[i];
const Ki = alphabet.indexOf(K);
if(Ci === -1) return C;
const Ri = equation(Ci, Ki, L);
return alphabet[Ri];
})
.join("");
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment