From: billtj@... (Bill Tj) Date: 2002-10-10T22:14:42+09:00 Subject: Using Ruby Hash for Crytography? Hi David, Exactly. That's why in the original post nbs = Hash.new([]) while line = gets if line =~ /p(\d+) -- p(\d+)/ u, v = $1.to_i, $2.to_i nbs[u] << v nbs[v] << u end end although it might seem that the "clue" was that the problem is "a single array which is shared by many hash elements", probably the more immediate problem is actually "the use of hash default value as (intended) lvalue instead of rvalue"? I am really curious whether the original poster got "overlapped arrays" problem , or "nbs.length == 0" problem, or both, when the code finished executing. This is because although nbs[12] may return a non-empty array, nbs.each_key {|key| puts key} does not print anything, as nbs.length == 0. Is this a commonly known Ruby hash feature? To summarize, it seems that "Given a right key, nbs may return something, but we cannot know what those keys are from nbs alone." :) Maybe we can use something like this for cryptography such as hiding data in our Ruby code so that the "naughty" user cannot do too much damage? :) Regards, Bill ============================================================================= dblack@candle.superlink.net wrote in message news:... > Hi -- > What you're doing is adding 'a' to that default array, rather > than setting an 'a' key. So the above is the same as if you > had done: > > hsh = Hash.new(['a']) > > hsh still doesn't have any keys, just a default value.