From: Meino Christian Cramer Date: 2006-08-06T04:04:08+09:00 Subject: Re: Smoking hash-ish: Letter mapping... From: Joey Subject: Re: Smoking hash-ish: Letter mapping... Date: Sun, 6 Aug 2006 03:55:14 +0900 Looks good! May be I am too newbie here, but... When I do this in irb and look at encmap, both - key and value - seem to be randomnized... (and what means the "*" right at the start of the expression?) But this is not really an issue as long there is no identical mapping like "A"->"A". Ah, by the way: With an even number of items/mapping in such an Hash...there must be zero or an even number of identical mappings like described above. Is this logical correct or nonsense...? > Maybe: encmap=Hash[*('A'..'Z').to_a.sort{rand(2)}] > > and Marshal.dump and Marshal.load for storing. > > j`ey > http://www.eachmapinject.com > > On 8/5/06, Meino Christian Cramer wrote: > > > > Hi, > > > > for a *very* simplistic encryption program I want to build a > > hash, which should be dynamically build (not hardcoded). > > > > The input of the method which should do the job will be a range of > > any meaningful input, say: parameter 1: A and parameter 2: Z > > > > Then the method should create a Hash with that mapping > > "A" -> "Z" > > "B" -> "G" > > "C" -> "T" > > ... > > > > or in other words: > > The key should follow the given range, and the values should > > represent all values of that range but in random order. > > > > For arrays I learned a nice trick from this list: > > > > encmap=(A..Z).to_a.sort{rand(2)} > > > > but...how can I accomplish similiar for a hash ??? > > > > And: I sthere a simple way to store a hash in binary format and later > > load that hash again into memory ? > > > > Nice weekend! > > mcc > > > > > > > >