Make some tests : http://outils-en-ligne.uzabnet.com/gene ... -ligne.php
Code: Select all
;{ FUNCTIONS AND MARCO }
;circular 32bits left shift
Procedure.l ROL(val, shift)
Protected v1.q = 0
PokeL(@v1,val)
v1 << shift
ProcedureReturn PeekL(@v1) | PeekL(@v1+4)
EndProcedure
Macro STRING_POINTER_(str,posPointer)
Asc(Mid(str,posPointer+1,1))
EndMacro
Macro CPY_ARRAY_(toArr,fromArr,fromArrIndex,length,dataType=Long)
CopyMemory(@fromArr(fromArrIndex),@toArr(0),SizeOf(dataType)*length)
EndMacro
;}
Procedure$ SHA1(in$)
#SHA1_ROUND1 = $5A827999 ;SHA1 Constants
#SHA1_ROUND2 = $6ED9EBA1
#SHA1_ROUND3 = $8F1BBCDC
#SHA1_ROUND4 = $CA62C1D6
Protected h0 = $67452301, h1 = $EFCDAB89, h2 = $98BADCFE ;Intermediate Hash
Protected h3 = $10325476, h4 = $C3D2E1F0 ;Intermediate Hash
Protected a,b,c,d,e ;Word buffer
Protected t ;Temporary word Value
Protected in_length.l = Len(in$)
Protected in_length_quad.q = in_length
Protected datas_length.l = (((in_length + 8) >> 6) + 1) << 4
Dim datas.l(datas_length)
For k=0 To in_length-1
datas(k >> 2) = (datas(k >> 2) << 8) | (STRING_POINTER_(in$,k) & $FF)
Next
datas(in_length >> 2) = ((datas(in_length >> 2)<< 8) | $80) << ((3 - (in_length & 3))<< 3)
datas(datas_length - 2) = (in_length_quad * 8) >> 32
datas(datas_length - 1) = (in_length_quad * 8) & $FFFFFFFF
For chunkStart=0 To datas_length-1 Step 16
a = h0 : b = h1 : c = h2 : d = h3 : e = h4
Dim w.l(80) ;Word sequence
CPY_ARRAY_(w,datas,chunkStart,16) ;Init first 16 Words
For i=16 To 79
w(i) = ROL(w(i - 3) ! w(i - 8) ! w(i - 14) ! w(i - 16), 1)
Next
;Round 1
For i=0 To 19
t = #SHA1_ROUND1 + ROL(a, 5) + (d ! (b & (c ! d))) + e + w(i)
e = d : d = c
c = ROL(b, 30)
b = a : a = t
Next
;Round 2
For i=20 To 39
t = #SHA1_ROUND2 + ROL(a, 5) + (b ! c ! d) + e + w(i)
e = d : d = c
c = ROL(b, 30)
b = a : a = t
Next
;Round 3
For i=40 To 59
t = #SHA1_ROUND3 + ROL(a, 5) + ((b & c) | (d & (b | c))) + e + w(i)
e = d : d = c
c = ROL(b, 30)
b = a : a = t
Next
;Round 4
For i=60 To 79
t = #SHA1_ROUND4 + ROL(a, 5) + (b ! c ! d) + e + w(i)
e = d : d = c
c = ROL(b, 30)
b = a : a = t
Next
h0 + a : h1 + b : h2 + c : h3 + d : h4 + e
Next
ProcedureReturn LCase(RSet(Hex(h0),8,"0") + RSet(Hex(h1),8,"0") + RSet(Hex(h2),8,"0") + RSet(Hex(h3),8,"0") + RSet(Hex(h4),8,"0"))
EndProcedure
If OpenConsole()
PrintN(SHA1("iNiQuiTy"))
PrintN("0a4dd0f633b7e5cd5520bcad12331a65f6b9dac7 ")
Input()
EndIf