From: Jamis Buck Date: 2004-08-21T04:44:06+09:00 Subject: Re: Neat trick for Steckerboard of Enigma needed... Meino Christian Cramer wrote: > Hi Rubyaner ! :) > > The Steckerboard is a patch panel on some models of the Enigma. > > If letters are "steckered" (oh, what do I like this language-mixed > words! GREAT! :), then they will be swapped while encoding. > > For example: If "AG" is steckered, pressing "A" on the keyboard > will feed "G" into the Enigma and -- on the way out of the Enigma, > each "G" is translated into an "A" as the last step of > encryption. Letters, which are not steckered (they are > "selfsteckered") remain unswapped. > > From the user point of view s/he will feed zero to max 13 pairs of > letters to the simulator on the commandline. Each can only appear > once. > > So I get a string, for example "AGQTRXDF" into the simulator. > > Does anyone of the Ruby gurus here know a neat trick to convert > this into a hash of the form > > steckers={ > "A" => "G", > "Q" => "T", > "R" => "X" > "D" => "F" > } > > in "one turn"? I only know a very "unrubyish" way to do this in > single steps -- kinda "slow motion" programming... ;) > Something like this, perhaps? "AGQTRXDF".scan(/(.)(.)/).inject(Hash.new) { |h,m| h[m[0]] = m[1]; h } - Jamis > As always thank you very much for your friendly help in advance! > Meino > > > > . > -- Jamis Buck jgb3@email.byu.edu http://www.jamisbuck.org/jamis "I use octal until I get to 8, and then I switch to decimal."