Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > iterate values of hex string

Reply
Thread Tools

iterate values of hex string

 
 
eggie5
Guest
Posts: n/a
 
      09-30-2012
Can somebody please suggest a getter way of doing this?

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
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      09-30-2012
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*).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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to iterate 2 nested collections w <logic:iterate> without a"getter" John Java 4 04-01-2008 09:46 AM
nested:iterate or logic: iterate with multibox?? runescience Java 0 02-09-2006 12:57 AM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
<logic:iterate /> iterate beyond items in the collection Gogo Java 1 09-04-2003 08:40 PM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments