From: "Ara.T.Howard" Date: 2004-08-18T02:40:59+09:00 Subject: Re: POT (partly offtopic) Re: Q: Shifting a hash anf and array On Wed, 18 Aug 2004, Meino Christian Cramer wrote: > Three days ago I saw a british film on TV about the decyphering of the > Enigma machine in Blechtley Park...FASZINATING! Very good film! > > What follows was a googling party "in search of the Enigma".... ;) > > I found a bash script, which implements a lot of different Enigmas > and I thought it would be a good opportunity to learn more Ruby to > implement the Enigma in Ruby. > > One of the basic concepts of the Enigma machine are the wheels. Those > wheels had 26 input terminals on the one side and 26 output terminals > on the other side. Each terminal was representing one letter. The > connnection between the front and back terminals were "crossed wired" > -- or irregular (right word?). What was put as an "A" on the front > came out as (fro example) "Q" on the back. > > Three or four wheels were packed on one axis. Which each letter input > the wheels were rotated one position (I haven't figured out, how > exactly this works until now...). That means: "AAA" came out as (for > example) "QZF" and not as "QQQ". > > I thought of implementing the wheels as such > not-integer-but-ordered-indexed "arrays". And my question about all > this rotating and shiofting stuff was to figure out how to "rotate" > my wheel-arrays. > > There much other stuff to figure out...there was also a "Reflector" > (whatever it was used for) and a so called "Steckerboard" ("Stecker" > is german for "plug", but every site about the Enigma calls this a > "Steckerboard" and "...the code was steckered..." ("connected" or > "plugged in" or so in English) > > OT: If anyone knows a good site with detailed description of the > mechanical "inside" and the meachnisms of the different Enigma > machines...hu,hu...me! Here, please! :))) > > Sorry for this longish "book about the Enigma" :))). > > But I thought it could be interesting. very. something like this perhaps? jib:~ > cat b.rb require 'arrayfields' module Enigma class Wheel < Array FORWARD = 0 BACKWARD = 1 attr :terminals def initialize terminals self.fields = *terminals self.replace terminals end def rotate! direction = FORWARD if direction == FORWARD push shift else unshift pop end end def inspect fields.inject(''){|s,f| s << "#{ f } - #{ self[f] }\n"} end end end w = Enigma::Wheel.new %w(A B C D E F) p w w.rotate! p w jib:~ > ruby b.rb A - A B - B C - C D - D E - E F - F A - B B - C C - D D - E E - F F - A keep us tuned! -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================