From: Meino Christian Cramer Date: 2006-08-07T13:29:13+09:00 Subject: Slightly OT: Wanted -- the most rubyish way to do this... Hi, sorry for being -- may be -- a little offtopic. Currently I am playing around with """""encryption""""" -- the meaning of all those "'s is: "Encryption" in the sense of "convert readable text into unreadable text" not in the sense of "Bullet proof encryption suitable for secret service agents". Just something to play around with... What I need is the following "device": Input is a freely defineable range of anything a byte can stand for. Output is again a value of the same range. This mapping from an input to an output value should be made variable in two manners: First is to change the mapping itsself the second way is to define an offset. This should work as follows: Without offset: With offset 3: A -> Z A -> I // wrapped around from the end B -> H B -> B // of the previously defined C -> L C -> Q // range D -> P D -> Z E -> F E -> H F -> D F -> L . G -> P . H -> F . I -> D The offset should be changeable at each new mapping action. My first idea was to define an Hash which maps an input range to an index. To this index it is easy to add an offset. The second step would be an array, which maps the new calculated index (old index + offset) to the same range again, but this time the range was "sorted" by sort{rand} st initialization time. But when I do a "a=device.new", what should I return as an obejct to the caller ??? TWO objects -- the hash AND the array ? I am curious whether there are better, more elegant ways to accomplish this in a more rubyish way. I would be happy to read of your ideas how to implement this! :) Thank you very much in advance for any help and any idea ! Ruby! :) mcc