Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Enigma machine.

by frankus (Priest)
on Nov 12, 2001 at 18:46 UTC ( [id://124834]=CUFP: print w/replies, xml ) Need Help??

I was looking for a reasonably good method of encrypting stuff that was okay to use on an ipaq,
RSA seems a bit too heavy, and the RSA dolphin requires stuff that hasn't yet been ported...
I toyed with using Solitaire (p480 of Cryptonomicon)
I've got some C code for GOST, but I've not tried it, instead for a laugh:

It's an enigma machine, that'll take a varying number of rotors. I've tested it reasonably thouroughly, please report any errors ;), as it was only tested on 5.6.1.

Notes
The enigma machine here, can 'emulate' most types of enigma, from the pre-war (3 rotor w/o plug-board (AKA Steckerboard)) to the 4 Rotor, plug-boarded enigma used on submarines).

  • rotorN represents a disc with a jumbled alphabet corresponding to an ordered alphabet
  • reflect represents a partial rotor where letters correspond to other letters and the other letter back (i.e) A->M, M->A.
  • Order is the order of occurence of the rotors, since they're interchangeable, except the reflector
  • position is the starting letter for each rotor.
  • Plug is the plug board where letters are mapped to other letters, as with the reflector

Using a programming language it seemed redundant to retain ring-settings.

#!/usr/bin/perl use strict; sub r{ my($r,$p,$c,$n)=@_; $r=~s/([a-z])/$n=uc($1),uc($1)/eg && $r=~s/(.*)($p)(.*)/$2$3$1 +/; sub{ if($_[0]=~/^-(.)$/){$p=('A'..'Z')[index($r,$1)]} + else{$r=~s/(.{$_[1]})(.*)/$2$1/ if $#_>0;$p=substr($r, +ord($_[0])-65,1)} ($p,eval $c) } } my $d=0; %_=map{chomp;(split/:/,$_,2)}<DATA>; # These four lines read the setti +ng data ;) $_{$_}=[split/ /,$_{$_}] for qw(position plug order); $_{'plug'}={map{@_=(split//);@_[0,1,1,0]}@{$_{'plug'}} }; $_{'switch'}=['$n eq $p','$d=($n eq $p),$d','$d?!($d=0):0','0']; @_=map{ &r($_{$_{'order'}->[$_]}, $_{'position'}->[$_], $_{'switch'}->[$_]) }(0..$#{$_{'order'}}); s/([a-z])/$_=uc($1); # Enigma takes only a +lpha chars. my($a,$i)=(1);$_=$_{'plug'}->{$_}|| $_; # go through stecker +plugs. for $i(0..$#_){($_,$a)=&{$_[$i]}($_,$a)} # go through rotors. $_=substr($_{'reflect'},ord($_)-65,1); # go through reflecto +r plate. for($i=$#_;$i>=0;){($_,$a)=&{$_[$i--]}("-$_")} # go back through rot +ors $_=$_{'plug'}->{$_}|| $_/eigx && print while(<>) # undergo steckering. + __END__ rotor1:EKMFLGDqVZXNTOWYHUSPAIBRCJ rotor3:AJDKSIRUXBLHWTMCQGZNPYFVOe rotor2:BDFHJLCPRTXvZNYEIWGAKMUSQO rotor4:ESOVPZjAYQUIRHXlNFTGKDCMWB reflect:YRUHQSLDPXNGOKMIEBFZCWVJAT order:rotor1 rotor3 rotor2 position:D M Z A plug: AT MX CD GR

Update: Bwahahaha.. I was going to write GOST in Perl and someones already done it, look... :(

Update: You know how it is when you keep whittling away at something : It's a Shark

--

Brother Frankus. (TJRX OSDKVMG YPBO PKGHZP)

¤

Replies are listed 'Best First'.
Go to Bletchley Park! Re: Enigma machine.
by andye (Curate) on Nov 12, 2001 at 19:29 UTC
    Speaking of which, I was at Bletchley Park over the w/end, looking at (and playing with) Enigma machines.

    Most monks probably know about BP already, but for those who don't, it was one of the 3 cryptanalysis centers used by the allies in WWII. It played a very important part in the outcome of the war, particularly the Battle of the Atlantic. Alan Turing worked there on the forerunners to digital computers.

    It's a fascinating site: first surprise is that it's *huge*. There's more stuff there than you can really see in one visit, as the (many) outlying buildings host various related organisations.

    Highlighs for me included the Enigma and similar machines, the Turing Bombes, the Colossus rebuild project (more) and the computer conservation society.

    S.O., who is less into technology and more into political and social history, found loads to interest her as well.

    A certain amount of hardware has been recently restored or mocked-up for the film Enigma - the turret of a U-boat is sitting outside one of the huts.

    I'd urge all monks in or visiting the UK to go along to Bletchley, if you can. It's *definitely* worth visiting.

    It relies on entrance money to keep going (it's not funded by the government) so by visiting, you're helping to keep it open.

    andy.

    OBPerl: BP was used as a location by Neal Stephenson in his book Cryptonomicon, which contains a Perl script to implement the encryption algorithm 'Pontifex' (Solitaire).

Re: Enigma machine.
by sifukurt (Hermit) on Nov 14, 2001 at 03:42 UTC
    For what it is worth, I've used Crypt::RC4, Crypt::Solitaire (which implements the Pontifex cipher from Cryptonomicon), Crypt::Rijndael_PP, and Crypt::Blowfish_PP all on my HP Jornada. Not an ipaq, I know, but both run Windows CE, so I would think that if it works on the Jornada it'll work on the Ipaq. There is a LOT of crunching that goes on with both Crypt::Blowfish_PP and Crypt::Rijndael_PP, so performance suffers a bit.
    ___________________
    Kurt

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-03-29 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found