Brian Candler wrote:
> > 
> The only answer I can give is trite: "because there is a bug in your 
> program", or "because you are doing something wrong". If you don't post 
> the code, then we cannot guess what you are doing wrong.
> 
> At a guess: your input by this stage should consist of an array of 80 
> 32-bit integers, and you should be indexing this array to obtain w[i]. 
> Possibly you have set up this array wrongly.
> 
> Arrays in Ruby are of unlimited size (subject only to available RAM).
> 
> FWIW, I have attached a direct translation of the pseudocode on 
> Wikipedia. It seems to work for the handful of test vectors I've tried.
> 
> $ echo -n "" | sha1sum
> da39a3ee5e6b4b0d3255bfef95601890afd80709  -
> $ echo -n "hello" | sha1sum
> aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d  -
> $ echo -n "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
> | sha1sum
> 06ced2e070e58c2c4ed9f2b8cb890f0c512ce60d  -

The following is the code that I have set.... I figured that the fix for 
that array limit is padding more 00s and then ripping it to a 80 row 
array...
The thing is the code perfectly.. works but my shasum is not the say 
that I am supposed to get.. well thats the issue...

here is the code

#!/usr/bin/ruby -w

h0=0x67452301
h1=0xefcdab89
h2=0x98badcfe
h3=0x10325476
h4=0xc3d2e1f0

message='abcde'

bit=message.size
message << '80'.hex

if(bit>64) then
        newbitlength=bit%64
else
        newbitlength=bit
end

while (newbitlength<=61) do
        message <<'00'.hex
        newbitlength=newbitlength+1
end

message << (('%016X' %(bit*8)).hex)

for i in (0..79)
        message<<'00'.hex
end
message.unpack('H8'*80)

a=h0
b=h1
c=h2
d=h3
e=h4

for i in (0..79)
        if (i>=16 or  i<=79) then
                message[i]=(((message[i-3]) ^ (message[i-8]) ^ 
(message[i-14]) ^ (message[i-16]))<<1)
                tempmessage=(message[i])>>31
                message[i]=(message[i]<<1)+tempmessage
        end

        if (i>=0 or i<=19) then
                f=((b&c)|((~b)&d))
                k=0x5A827999
       elsif (i>=20 or i<=39) then
                f=b^c^d
                k=0x6ED9EBA1
        elsif (i>=40 or i<=59) then
                f=(b&c)|(b&d)|(c&d)
                k=0x8F1BBCDC
        else
                f=b^c^d
                k=0xCA62C1D6
        end

tempvaluea=a>>27
arot=(a<<5)+tempvaluea

temp = (arot+f+e+k+(message[i]))%(2**32)



e=d
d=c
tempvalueb=b>>2
brot=(b<<30)+tempvalueb
c=brot
b=a
a=temp

h0=(h0+a)%(2**32)
h1=(h1+b)%(2**32)
h2=(h2+c)%(2**32)
h3=(h3+d)%(2**32)
h4=(h4+e)%(2**32)

puts i
puts "The value of H0:"<<h0.to_s(base=16)
puts "The value of H1:"<<h1.to_s(base=16)
puts "The value of H2:"<<h2.to_s(base=16)
puts "The value of H3:"<<h3.to_s(base=16)
puts "The value of H4:"<<h4.to_s(base=16)
end


puts "The digest for the given input is 
:"<<h0.to_s(base=16)<<h1.to_s(base=16)<<h2.to_s(base=16)<<h3.to_s(base=16)<<h4.to_s(base=16)


Regards,Ashrith
-- 
Posted via http://www.ruby-forum.com/.