3 ms·
For a course several years ago, I wrote a compact/efficient implementation of a Vigenere cipher: private static char encipherCharacter(char message_char, c
by mos_6502 5y ago
For a course several years ago, I wrote a compact/efficient implementation of a Vigenere cipher:
private static char encipherCharacter(char message_char, char key_char){
return (char)(((int)(message_char) + (int)(key_char) - 194)%26 + 97);
}
public static String encipher(String plaintext, String key){
String ciphertext = "";
for(int i = 0; i < plaintext.length(); i++)
ciphertext += encipherCharacter(plaintext.charAt(i), key.charAt((i % key.length())));
return ciphertext;
}
I'd love to see other implementations, if anyone has some to share.
https://gist.github.com/ctrezevant/8ca9e163d702af245ded35d97f522ec9 https://gist.github.com/ctrezevant/8ca9e163d702af245ded35d97...
- sterlind 5y agoThis should do it in C#: string Vigenere(string text, string key) => string.Join("", text.Select((p, k) => p < 'A' || p > 'Z' ? p : (char)((p + key[k % key.Length]) % 26 + 85)));