Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: iterate values of hex string Date: Sun, 30 Sep 2012 17:22:31 +0200 Lines: 44 Message-ID: References: <53a8e9db-186b-488e-97cf-7a54fa899a79@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net RzcHgp1yxI1Pd6nkTRS+LQ7SuoCIr2T3lJWWbIWlsTKR23sFthrfoQb8RkwtPa4+Q= Cancel-Lock: sha1:IXIY2Uxq7I9fdHWNmcRflDUNChg= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: <53a8e9db-186b-488e-97cf-7a54fa899a79@googlegroups.com> Xref: csiph.com comp.lang.ruby:6630 On 30.09.2012 08:49, eggie5 wrote: > Can somebody please suggest a getter way of doing this? Did you mean "better"? > hmac = "0000000000000000000000000000000000000000" > #40 is length of hmac > #255 is values of each byte to try > (0..40).step(2) do |i| > (0..255).each do |j| > hmac[i..i+1]="%02x" % j > p hmac > end > end > > > It just iterates all the values of a 20 byte array as a string from left to right. e.g.: > > 000000000000000000000000000000000000000 > 0100000000000000000000000000000000000000 > 0200000000000000000000000000000000000000 > . > . > . > FD00000000000000000000000000000000000000 > FE00000000000000000000000000000000000000 > FF00000000000000000000000000000000000000 > . > . > . > FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF > (2**(20*8)).times {|x| printf "%040x\n", x} You get a different order though. What do you need that for? robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/