http://qs1969.pair.com?node_id=549415

A slightly less simple obfuscation for a slightly less simple substitution cipher. My next stop in old forgotten encryption ciphers is the Vigenére cipher. This is a slightly more obfuscated encryption cipher than my last one - In case you haven't noticed, I'm increasing the obfuscation level as the encryption algorithm increases. This either takes a file as a parameter to encrypt in vigenere, or provided no input encrypts it's __DATA__.

Note: if you save this locally (and I don't know how you might run it otherwise) be sure to give it a filename of a good number of characters ( > 5) - The longer the filename, the better the encryption key.

#!/usr/bin/perl $ ..=$ _ for qw|$ @=/b..u\;/_@ =vqv \?qvcl+FOTO ,_@:_$;kbv($_@ =$ @;jd +/_;++\(d qR_"/2. ._;\(vz xH$ _@,xHjdy$ _@)) )$ @;$. =kbv[$ _@] ,_0= ~{}w {g|;$ +_=$ . ,y ,/FO\\{vzlu}\$dqR_Hjk\@yq(xybRc),(DA)/punz\\\@for\$him_to{stare},,s.. +$ _.gee; print map { map { $ %= 0 ;s '([A-Z])(?{$ %=1})'lc$ 1'e ;$ ;=$ .[ $ *] +[ - 97 + ord ]; $ *+= $ *== @ .-1? -$ *:1 ;ord> 96?$ %? uc$ ; :$ ; :$ _ }split/ +/}<DATA> __DATA__ The Vigenere cipher, known by some as 'le chiffre indechiffrable' (Fre +nch for 'the indecipherable cipher') is a method of encryption that uses a ser +ies of different Caesar ciphers based on the letters of a keyword, though the +re is some argument among cryptographic circles as to which incarnation of t +his particular polyalphabetic substitution can accurately be attributed to + Blaise de Vigenere. This implementation is a simple form of a polyalphabetic substitution. To encipher, a table of alphabets can be used, termed a + tabula recta, or Vigenere table. It consists of the alphabet written out 26 +times in different rows, each alphabet shifted cyclicly to the left compared + to the previous alphabet. Incidentally, there's a good chance that this plai +ntext is long enough to display the cryptographical weakness of this particu +lar algorithm. Can you spot it?

I'm currently working on the brute-force decryption for texts encrypted with this algorithm. It's working now, but I'd like to clean it up and make it more general, as well as optionally display HTML output.

I've found a somewhat reliable method for letter distribution frequency analysis that seems to work for a good number of test cases - Letter frequency analysis is the obvious weakness of this cipher. I'll post a followup with the cracking script a bit later...



--chargrill
$,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}

Replies are listed 'Best First'.
Re: Vigenére cipher
by teamster_jr (Curate) on May 15, 2006 at 13:48 UTC
    Thoroughly enjoying this series of obfu's ++chargrill.

    i mentioned this to you in /msg but thought other might be interested.
    I went to a really interesting lecture at the royal society by simon singh, author of the code book, about almost exactly what you're doing - going through different cyphers through history.
    He set a challenge for teams to crack 10 increasingly difficult cyphers.
    stage 4 was Vigenère
    running up to DES and RSA.
    very interesting.

      I just bought that book a few weeks ago (after I got my algorithm down for the vigenere cipher, but before I fully obfuscated it) because my other source of information/inspiration for additional algorithms was running dry, and I was trying to figure out a few things:

      1. Next stops for my tour through old encryption ciphers
      2. How to 'break' the 'undecipherable cipher'. I had an idea or two from reading the entry on wikipedia, but was left wanting a more in depth discussion of letter frequency analysis.

      I'm glad you posted the link to the book, I was able to get my hands on an electronic version of the ciphertext from the book (I wasn't about to type it all in by hand!) and run my cracking script against it - I was pretty happy to find that I was able to decipher the keyword used to encode that ciphertext, though I wouldn't've recognized the plaintext because it's in french :)

      I'm now trying to figure out how to easily get from having the encoding key and the ciphertext and working backwards to get the original plaintext - it's unfortunately not as much of a slam dunk as I thought it would be - but I guess I now know what I'll be working on tonight.

      Update: I've finished the breaking script, but it's turned into a monster (what the the optional html formatted output). I was intending to either obfuscate it and post it separately, or post it as a followup to the original node, but I'm thinking instead of posting it to the code section, now that I've started a long way towards cleaning it up, passing strict and warnings, and even documented it with some POD. Comments welcome. End update

      I also read up on how the "official" solution for that particular ciphertext was arrived upon, and I am a little embarassed to say that my method for extracting a likely encoding key isn't quite as sophisticated as theirs. I just search for repeating strings, find the greatest common denominator factor for the intervals between the repeats, build a little data structure and "compare" it to a standard letter distribution frequency for plaintext of a similar size. Or something like that.



      --chargrill
      $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}
Re: Vigenére cipher
by turo (Friar) on May 15, 2006 at 22:33 UTC

    Yeah!!!, i like very much this stuff chargrill!!! ^_^>, old-school criptography is a very interesting issue, insecure but very very intersting!! (a little more difficult to comprehend when is obfuscated though)

    greetings!

    perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'