Last active
August 15, 2021 19:46
-
-
Save EnzoDiazDev/b71f3434367f9ca5a620fdd0cf75e867 to your computer and use it in GitHub Desktop.
vigenere with functions p5
This file contains 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
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