From: "Robert Klemme" <bob.news / gmx.net>
Subject: Re: POT (partly offtopic) Re: Q: Shifting a hash anf and array
Date: Wed, 18 Aug 2004 19:10:56 +0900

> 
> >  I dont know, what I like most: Ruby or its mailing list people ! :O)
> 
> :-))

  I only can repeat what I said previously about my inabillity to
  decide between both ! :O)

> >  I thought of implementing the wheels as such
> >  not-integer-but-ordered-indexed "arrays". And my question about all
> >  this rotating and shifting stuff was to figure out how to "rotate"
> >  my wheel-arrays.
> 
> IMHO rotating is much too inefficient.  I'd rather use a changing offset
> like this:
> 
> module Enigma
>   class Wheel
>     def initialize(mapping)
>       @code = mapping
>       @offset = 0
>     end
> 
>     def rotate
>       @offset = (@offset + 1) % @code.size
>     end
> 
>     def encode(char)
>       @code[(normalize(char) + @offset) % @code.size]
>     end
> 
> private
>     def normalize(char)
>       case char
>         when String
>           char.upcase[0] - ?A
>         when ?a..?z
>           char - ?a
>         when ?A..?Z
>           char - ?A
>         else
>           raise ArgumentError, "Dunno what to do with #{char.inspect}"
>       end
>     end
>   end
> end
> 
> 
> wheel = Enigma::Wheel.new [?x, ?z, ?e]
> p( wheel.encode( ?A ).chr )
> wheel.rotate
> p( wheel.encode( ?A ).chr )
> p( wheel.encode( "A" ).chr )

  
  Ok, this looks more like the Enigma++ or Enigma Pro or Enigma Deluxe
  ;) (by the way...currently it seems that there were 17 different
  models of the encyphering machine...)

  Unfortunately there is not only the one offset needed for rotating
  the wheels -- there is also one offset to be take into account for
  the outer ring or "tyre" of the wheels which was used to adjust the
  alphabet against the internal wireing and an additional offset for
  the start positions of the wheels.

  I think I will do first "rotate" the "wheels" into the initial
  position takeing the outer ring position and the start position of the
  wheels into account. This only happens once.

  And then I will "robertize" the "wheels" according to your code
  above, Robert. Since this happens for each letter to encypher it is
  far more important for this part of the code to be fast. And the
  code does not get too complex because of haveing three different
  offsets to be calculated each time.

  What do you think, Robert?

  Thank you very much for all the help I got from this list.
  
  Hopefully I will find the rest of informations I need about the
  technical specs of the different Enigmas.

> 
> Kind regards
> 
>     robert
> 
> 

Ruby.use!
Meino