Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: Breaking the indecipherable cipher, courtesy Charles Babbage.

by chargrill (Parson)
on May 19, 2006 at 20:29 UTC ( [id://550587]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Breaking the indecipherable cipher, courtesy Charles Babbage.
in thread Breaking the indecipherable cipher, courtesy Charles Babbage.

Yeah - perfect example: The following text, taken from Simon Singh's Code Challenge:

K Q O W E F V J P U J U U N U K G L M E K J I N M W U X F Q M K J B G W R L F N F G H U D W U U M B S V L P S N C M U E K Q C T E S W R E E K O Y S S I W C T U A X Y O T A P X P L W P N T C G O J B G F Q H T D W X I Z A Y G F F N S X C S E Y N C T S S P N T U J N Y T G G W Z G R W U U N E J U U Q E A P Y M E K Q H U I D U X F P G U Y T S M T F F S H N U O C Z G M R U W E Y T R G K M E E D C T V R E C F B D J Q C U S W V B P N L G O Y L S K M T E F V J J T W W M F M W P N M E M T M H R S P X F S S K F F S T N U O C Z G M D O E O Y E E K C P J R G P M U R S K H F R S E I U E V G O Y C W X I Z A Y G O S A A N Y D O E O Y J L W U N H A M E B F E L X Y V L W N O J N S I O F R W U C C E S W K V I D G M U C G O C R U W G N M A A F F V N S I U D E K Q H C E U C P F C M P V S U D G A V E M N Y M A M V L F M A O Y F N T Q C U A F V F J N X K L N E I W C W O D C C U L W R I F T W G M U S W O V M A T N Y B U H T C O C W F Y T N M G Y T Q M K B B N L G F B T W O J F T W G N T E J K N E E D C L D H W T V B U V G F B I J G Y Y I D G M V R D G M P L S W G J L A G O E E K J O F E K N Y N O L R I V R W V U H E I W U U R W G M U T J C D B N K G M B I D G M E E Y G U O T D G G Q E U J Y O T V G G B R U J Y S

... fails miserably, but if I save it as "trajan" and run the following:

$ cat trajan | perl -pe 's/\W|\s//gm' | perl babbage.pl

It works like a champ. But this treatment can also foil my "best guess" as to the key length:

$ tail -12 vigenere.pl | perl -pe 's/\W|\s//gm' \ | perl vigenere.pl - | perl babbage.pl

... the "key" found is "vrgpn", and the plaintext is then shown as "tyekipelepetiehnrinmwebnsxmcaqlvcwio..."

All of which makes me think I need to do some refactoring to look out for these kinds of problems, or at the very least add some interactivity along the lines of the posted solution to the code challenge mentioned above.



--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^5: Breaking the indecipherable cipher, courtesy Charles Babbage.
by turo (Friar) on May 20, 2006 at 03:15 UTC

    automation is right ;) ...

    i did the same as you did, but i've obtained the correct result ...

    turo@somewhere:~# tail -12 vigenere.pl | perl -pe 's/\W|\s//gm' | pe +rl vigenere.pl - | perl babbage.pl Key: vigenerepl Plaintext: thevigenerecipherknownbysomeaslechiffreindechiffrable ...

    The more bizarre thing, is that if i rename the file to chargrill and do the same, the result is wrong

    turo@somewhere:~# tail -12 chargrill | perl -pe 's/\W|\s//gm' | perl + chargrill - | perl babbage.pl Key: a Plaintext: voemoxmyptlczvymcvpvwehpazxghscktptqhyeztumnskmfigstpqtl ...

    Maybe the solution is to choose a keylengh (and key), get the result for the bests fits, and pass some test to see if the result is right or not (based on letter frequencies) ... or something like that

    turo

    PS: only one more question, which book did you bought? (I've got the David Khan's Codebreakers; but is too big) ... Is the Sinmon Singh's one? ... woff, woff

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://550587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-25 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found