Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- δ=0xffffffff
- λ=ord
- μ=lambda x,k:(((x)<<(k))|((x)>>(32-(k))))
- def m_(a,b,c):
- a&=δ;b&=δ;c&=δ
- a-=c;a&=δ;a^=μ(c,4); a&=δ;c+=b;c&=δ
- b-=a;b&=δ;b^=μ(a,6); b&=δ;a+=c;a&=δ
- c-=b;c&=δ;c^=μ(b,8); c&=δ;b+=a;b&=δ
- a-=c;a&=δ;a^=μ(c,16);a&=δ;c+=b;c&=δ
- b-=a;b&=δ;b^=μ(a,19);b&=δ;a+=c;a&=δ
- c-=b;c&=δ;c^=μ(b,4); c&=δ;b+=a;b&=δ
- return a,b,c
- def f_(a,b,c):
- a&=δ;b&=δ;c&=δ
- c^=b;c&=δ;c-=μ(b,14);c&=δ
- a^=c;a&=δ;a-=μ(c,11);a&=δ
- b^=a;b&=δ;b-=μ(a,25);b&=δ
- c^=b;c&=δ;c-=μ(b,16);c&=δ
- a^=c;a&=δ;a-=μ(c,4);a&=δ
- b^=a;b&=δ;b-=μ(a,14);b&=δ
- c^=b;c&=δ;c-=μ(b,24);c&=δ
- return a,b,c
- def h2_(ζ,iv=0,iv2=0):
- _l=σ=len(ζ)
- a=b=c=(0xdeadbeef+(_l)+iv)
- c+=initval2;c&=δ
- p=0
- while σ > 12:
- a+=(λ(ζ[p+0])+(λ(ζ[p+1])<<8)+(λ(ζ[p+2])<<16)+(λ(ζ[p+3])<<24));a&=δ
- b+=(λ(ζ[p+4])+(λ(ζ[p+5])<<8)+(λ(ζ[p+6])<<16)+(λ(ζ[p+7])<<24));b&=δ
- c+=(λ(ζ[p+8])+(λ(ζ[p+9])<<8)+(λ(ζ[p+10])<<16)+(λ(ζ[p+11])<<24));c&=δ
- a,b,c=m_(a,b,c)
- p+=12
- σ-=12
- if σ==12:c+=(λ(ζ[p+8])+(λ(ζ[p+9])<<8)+(λ(ζ[p+10])<<16)+(λ(ζ[p+11])<<24));b+=(λ(ζ[p+4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+4]));a+=(λ(ζ[p+0])+(λ(ζ[p+1])<<8)+(λ(ζ[p+2])<<16)+(λ(ζ[p+3])<<24));
- if σ==4:a+=(λ(ζ[p+0])+(λ(ζ[p+1])<<8)+(λ(ζ[p+2])<<16)+(λ(ζ[p+3])<<24))
- if σ==3:a+=(λ(ζ[p+0])+(λ(ζ[p+1])<<8)+(λ(ζ[p+2])<<16))
- if σ==2:a+=(λ(ζ[p+0])+(λ(ζ[p+1])<<8))
- if σ==1:a+=λ(ζ[p+0])
- a&=δ;b&=δ;c&=δ
- if σ==0:return c,b
- a,b,c=f_(a,b,c)
- return c,b
- def h_(data,initval=0):
- c,b=h2_(data,initval,0)
- return c
- if __name__=="__main__":
- import sys
- hashstr ='Four score and seven years ago'
- hashstr2='Four score und seven years ago'
- hash,hash2=h2_(hashstr,0xdeadbeef,0xdeadbeef)
- print('"%s": %x %x' % (hashstr,hash,hash2))
- hash=h_(hashstr,0)
- print('"%s": %x' % (hashstr,hash))
- hash,hash2=h2_(hashstr2,0xdeadbeef,0xdeadbeef)
- print('"%s": %x %x' % (hashstr2,hash,hash2))
- hash=h_(hashstr2,0)
- print('"%s": %x' % (hashstr2,hash))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement