MD5/Implementation: Difference between revisions

Content added Content deleted
(→‎{{header|Scala}}: mark as incorrect)
Line 1,602: Line 1,602:
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
len md5k[] 64
len md5k[] 64
len md5s[] 64.
func md5init . .
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
call md5init
#
#
func md5 inp$ . s$ .
func md5 inp$ . s$ .
subr addinp
subr addinp
if inp4 = 1
if inp4 = 1
inp[] &= 0
inp[] &= 0
.
.
inp[len inp[]] += b * inp4
inp[len inp[]] += b * inp4
inp4 *= 0x100
inp4 *= 0x100
if inp4 = 0x100000000
if inp4 = 0x100000000
inp4 = 1
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 = 1
inp[] = [ ]
for i = 1 to len inp$
inp4 = 1
b = strcode substr inp$ i 1
for i = 1 to len inp$
b = strcode substr inp$ i 1
call addinp
call addinp
.
b = 0x80
.
b = 0x80
call addinp
call addinp
while len inp[] mod 16 <> 14 or inp4 <> 1
while len inp[] mod 16 <> 14 or inp4 <> 1
b = 0
call addinp
b = 0
call addinp
.
.
h = len inp$ * 8
h = len inp$ * 8
for i range0 4
b = h mod 0x100
for i = 1 to 4
b = h mod 0x100
call addinp
h = h div 0x100
call addinp
h = h div 0x100
.
inp[] &= 0
.
#
inp[] &= 0
a0 = 0x67452301
#
b0 = 0xefcdab89
a0 = 0x67452301
c0 = 0x98badcfe
b0 = 0xefcdab89
d0 = 0x10325476
c0 = 0x98badcfe
d0 = 0x10325476
for chunk = 1 step 16 to len inp[] - 15
a = a0 ; b = b0 ; c = c0 ; d = d0
for chunk = 1 step 16 to len inp[] - 15
for i = 1 to 64
a = a0 ; b = b0 ; c = c0 ; d = d0
if i <= 16
for i = 1 to 64
h1 = bitand b c
if i <= 16
h2 = bitand bitnot b d
h1 = bitand b c
f = bitor h1 h2
h2 = bitand bitnot b d
g = i - 1
f = bitor h1 h2
elif i <= 32
g = i - 1
h1 = bitand d b
elif i <= 32
h2 = bitand bitnot d c
h1 = bitand d b
f = bitor h1 h2
h2 = bitand bitnot d c
g = (5 * i - 4) mod 16
f = bitor h1 h2
elif i <= 48
g = (5 * i - 4) mod 16
h1 = bitxor b c
elif i <= 48
f = bitxor h1 d
h1 = bitxor b c
g = (3 * i + 2) mod 16
f = bitxor h1 d
g = (3 * i + 2) mod 16
else
h1 = bitor b bitnot d
else
f = bitxor c h1
h1 = bitor b bitnot d
g = (7 * i - 7) mod 16
f = bitxor c h1
g = (7 * i - 7) mod 16
.
f = (f + a + md5k[i] + inp[chunk + g])
a = d
d = c
c = b
h1 = bitshift f s[i]
h2 = bitshift f (s[i] - 32)
b = (b + h1 + h2)
.
.
f = (f + a + md5k[i] + inp[chunk + g])
a0 += a ; b0 += b ; c0 += c ; d0 += d
a = d
.
d = c
s$ = ""
c = b
for a in [ a0 b0 c0 d0 ]
h1 = bitshift f md5s[i]
for i = 1 to 4
h2 = bitshift f (md5s[i] - 32)
b = a mod 256
b = (b + h1 + h2)
a = a div 256
for h in [ b div 16 b mod 16 ]
.
a0 += a ; b0 += b ; c0 += c ; d0 += d
h += 48
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
repeat
s$ = input
s$ = input
until error = 1
until error = 1
call md5 s$ h$
call md5 s$ h$
print h$
print h$
.
.
input_data
input_data