Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: 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)

¤


In reply to Enigma machine. by frankus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (5)
    As of 2015-07-04 03:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (57 votes), past polls