### Comment on

 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!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• 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: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
 [Lady_Aleena]: \$ grep --include=*.p[lm] -Ern 'get_(array|hash| data)' does not do multiline search. [Discipulus]: focus on Perl LA; you can already search multiline patterns [erix]: grep is a program, not a regex-engine [Tanktalus]: perldigious: I'm 20 years in, and I don't want to move ;) [Lady_Aleena]: erix, right, it searches files for a pattern. pcregrep is supposed to do the same thing with the addition of being able to search multiline. [erix]: ah, pcregrep is a stanalone program? [Lady_Aleena]: erix, yes. [Lady_Aleena]: pcre stands for 'Perl Compatible Regular Expressions'. [erix]: ok, ok, I thought you meant the engine [perldigious]: Tanktalus: Ha, understandable, that does make it harder when you don't want to move. I assume you are looking at remote work from home jobs too?

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2017-05-23 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favorite model of computation is ...

Results (181 votes). Check out past polls.