MD5/Implementation: Difference between revisions

(→‎{{header|Scala}}: mark as incorrect)
Line 1,602:
<syntaxhighlight lang="text">
len md5k[] 64
len md5s[] 64.
func md5init . .
for i = 1 to 64
s[] = [ 7 12 17 22 5 9 14 20 4 11 16 23 6 10 15 21 ]
md5k[i] = floor (0x100000000 * abs sin (i * 180 / pi))
for i = 1 to 64
.
md5k[i] = floor (0x100000000 * abs sin (i * 180 / pi))
.
for i = 0 to 3
for j = 0 to 3
for k = 0 to 3
md5s[i * 16 + j * 4 + k + 1] = s[i * 4 + k + 1]
.
.
.
.
call md5init
#
func md5 inp$ . s$ .
subr addinp
if inp4 = 1
inp[] &= 0
.
inp[len inp[]] += b * inp4
inp4 *= 0x100
if inp4 = 0x100000000
inp4 = 1
.
.
s[] = [ 7 12 17 22 7 12 17 22 7 12 17 22 7 12 17 22 5 9 14 20 5 9 14 20 5 9 14 20 5 9 14 20 4 11 16 23 4 11 16 23 4 11 16 23 4 11 16 23 6 10 15 21 6 10 15 21 6 10 15 21 6 10 15 21 ]
inp[] = [ ]
inp4 inp[] = 1[ ]
for iinp4 = 1 to len inp$
for bi = strcode1 substrto len inp$ i 1
b = strcode substr inp$ i 1
call addinp
call addinp
.
b = 0x80.
b = 00x80
call addinp
call addinp
while len inp[] mod 16 <> 14 or inp4 <> 1
b = 0
call addinp b = 0
call addinp
.
.
h = len inp$ * 8
for i range0 4
for bi = h1 modto 0x1004
ab = ah divmod 2560x100
call addinp
h = hcall div 0x100addinp
h = h +=div 480x100
.
inp[] &= 0.
# inp[] &= 0
a0 =# 0x67452301
b0 a0 = 0xefcdab890x67452301
c0 b0 = 0x98badcfe0xefcdab89
d0 c0 = 0x103254760x98badcfe
d0 = 0x10325476
for chunk = 1 step 16 to len inp[] - 15
for achunk = a01 ;step b16 =to b0len ;inp[] c = c0 ; d =- d015
for i a = 1a0 to; b = b0 ; c = c0 ; d = 64d0
iffor i <= 161 to 64
h1 =if bitandi b<= c16
h2 h1 = bitand bitnot b dc
f = bitor h1 h2 = bitand bitnot b d
g f = ibitor -h1 1h2
elif i < g = 32i - 1
h1 =elif bitandi d<= b32
h2 h1 = bitand bitnot d cb
f = bitor h1 h2 = bitand bitnot d c
g = (5 * if -= 4)bitor modh1 16h2
elif i < g = 48(5 * i - 4) mod 16
h1 =elif bitxori b<= c48
f h1 = bitxor h1b dc
g = (3 * if += 2)bitxor modh1 16d
for h in [ b div 16g b= (3 * i + 2) mod 16 ]
else
h1 = bitor b bitnot delse
f = bitxor c h1 = bitor b bitnot d
g = (7 * if -= 7)bitxor modc 16h1
g = (7 * i - 7) mod 16
for j = 0 to 3.
md5s[i *f 16= + j * 4(f + ka + 1] = smd5k[i * 4] + kinp[chunk + 1g])
for k = 0a to= 3d
else d = c
c h += 39b
h1 = bitshift f s[i]
h2 = bitshift f (s[i] - 32)
s$ &b = strchar(b + h1 + hh2)
.
fa0 += (fa +; ab0 += md5k[i]b ; c0 += inp[chunkc ; d0 += g])d
a = d.
ds$ = c""
for a in c[ =a0 bb0 c0 d0 ]
h1for i = bitshift1 fto md5s[i]4
h2 = bitshift fb = (md5s[i]a -mod 32)256
b = (b +a = h1a +div h2)256
for h in [ b div 16 b mod 16 ]
.
a0 += a ; b0 += b ; c0 += c ; d0h += d48
if h > 57
.
s$ h += ""39
for a in [ a0 b0 c0 d0 ] .
s$ &= strchar h
for i range0 4
b = a mod 256.
a = a div 256
for h in [ b div 16 b mod 16 ]
h += 48
if h > 57
h += 39
.
s$ &= strchar h
.
.
.
.
repeat
s$ = input
until error = 1
call md5 s$ h$
print h$
.
input_data
1,995

edits