iterate values of hex string

E

eggie5

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
 
R

Robert Klemme

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top