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 | |
Re: Enigma machine.
by sifukurt (Hermit) on Nov 14, 2001 at 03:42 UTC |