5 ms·
Basic Cryptography – The Vigenere Cipher
- FinanceAnon 5y agoThis reminds of the times when I was at school and was solving the weekly online challenges for National Cipher Challenge (UK). My program which cracked Vigenere cipher was one of my first projects when I was learning programming. My solution depended on the fact that I knew a few words which will occur in the plaintext, and I would just try these words in all possible positions in the text and get the possible keys.
- tptacek 5y agoWhy on Earth would you pass plaintext punctuation characters through to the ciphertext?
- pesciarat 5y agoBecause it’s intention is to be low barrier educational? This is like asking a child doing writing exercises, “Why on Earth would you rewrite the same letter over and over again?”
- 0xdeadb00f 5y agoIf you're genuinely critiquing the security of this implementation of the Vigenere cipher - don't worry. The Vigenere cipher itself is known to not be very secure at all. Cryptalaysis and cracking it is piss easy (at least when the message and key isn't extremely long I suppose). Nobody should be using this to secure actual sensitive information ever.
- sterlind 5y agoThis doesn't really explain Vigenere well, since what's left out is where the key comes from: * If key is the same length as plaintext, and truly random, that's a One-Time Pad. * If the message is appended to the seed key, that's an Autokey Cipher. * If the key is repeated (what the PHP does but not made clear), that's classical Vigenere. It also doesn't describe breaking them: * OTPs are unbreakable. * You can break Autokey by using crib words (e.g. "the") at different locations of the ciphertext, selecting the most phonetically plausible and working backwards to recover the earlier plaintext. * Vigenere can be attacked by trying the same shift for every Nth letter, or using cribs.
- unnouinceput 5y agoQuote: "Our decryption function is basically the same, but in reverse" and follows with a full decrypt function. A very simple optimization is to use encrypt function to decrypt the encrypted message by providing the "inverse key" as parameter, which is a 2 line function altogether. Implementation of said implementation is left as an exercise for the reader.
- mos_6502 5y agoFor 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)));
- sul_tasto 5y agoPlease help solve Kryptos: https://en.m.wikipedia.org/wiki/Kryptos https://en.m.wikipedia.org/wiki/Kryptos
- MattPalmer1086 5y agoIt's not a very nice implementation. It creates a long key as long as the message by appending the key to itself as many times as necessary. Could have just used a mod operator to cycle around the key.