TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Basic Cryptography – The Vigenere Cipher

42 pointsby eamannover 3 years ago

7 comments

sterlindover 3 years ago
This doesn&#x27;t really explain Vigenere well, since what&#x27;s left out is where the key comes from:<p>* If key is the same length as plaintext, and truly random, that&#x27;s a One-Time Pad.<p>* If the message is appended to the seed key, that&#x27;s an Autokey Cipher.<p>* If the key is repeated (what the PHP does but not made clear), that&#x27;s classical Vigenere.<p>It also doesn&#x27;t describe breaking them:<p>* OTPs are unbreakable.<p>* You can break Autokey by using crib words (e.g. &quot;the&quot;) at different locations of the ciphertext, selecting the most phonetically plausible and working backwards to recover the earlier plaintext.<p>* Vigenere can be attacked by trying the same shift for every Nth letter, or using cribs.
unnouinceputover 3 years ago
Quote: &quot;Our decryption function is basically the same, but in reverse&quot; and follows with a full decrypt function.<p>A very simple optimization is to use encrypt function to decrypt the encrypted message by providing the &quot;inverse key&quot; as parameter, which is a 2 line function altogether. Implementation of said implementation is left as an exercise for the reader.
mos_6502over 3 years ago
For a course several years ago, I wrote a compact&#x2F;efficient implementation of a Vigenere cipher:<p><pre><code> 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 = &quot;&quot;; for(int i = 0; i &lt; plaintext.length(); i++) ciphertext += encipherCharacter(plaintext.charAt(i), key.charAt((i % key.length()))); return ciphertext; } </code></pre> I&#x27;d love to see other implementations, if anyone has some to share.<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;ctrezevant&#x2F;8ca9e163d702af245ded35d97f522ec9" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;ctrezevant&#x2F;8ca9e163d702af245ded35d97...</a>
评论 #30145835 未加载
FinanceAnonover 3 years ago
This 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.
tptacekover 3 years ago
Why on Earth would you pass plaintext punctuation characters through to the ciphertext?
评论 #30146766 未加载
评论 #30143500 未加载
MattPalmer1086over 3 years ago
It&#x27;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.<p>Could have just used a mod operator to cycle around the key.
sul_tastoover 3 years ago
Please help solve Kryptos: <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Kryptos" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Kryptos</a>