MD5/Implementation: Difference between revisions
Content deleted Content added
Added Python |
m →{{header|REXX}}: added DO-END labels, added/changed comments. -- ~~~~ |
||
Line 1,977:
=={{header|REXX}}==
<lang rexx>/*REXX program to test the MD5 procedure as per the test suite in the */▼
▲/*REXX program to test the MD5 procedure as per the test suite in the */
/* IETF RFC (1321) ─── The MD5 Message─Digest Algorithm. April 1992. */
/*─────────────────────────────────────Md5 test suite (from above doc). */
msg.1=''
Line 1,990 ⟶ 1,989:
msg.7='12345678901234567890123456789012345678901234567890123456789012345678901234567890'
msg.0=7
do m=1 for msg.0
say ' in =' msg.m
say 'out =' MD5(msg.m)
say
end /*m*/
/*──────────────────────────────────MD5 subroutine──────────────────────*/
parse value '67452301'x 'efcdab89'x '98badcfe'x '10325476'x with a b c d▼
▲MD5: procedure; parse arg !; numeric digits 20 /*insure enough digits.*/
▲parse value '67452301'x 'efcdab89'x '98badcfe'x '10325476'x with a b c d
#=length(!)
L=#*8 // 512
select▼
▲ select
when L
when L
end /*select*/
▲ when L=448 then plus=512
$=!||'80'x||copies('0'x,plus%8-1)reverse(right(d2c(8*#),4,'0'x))||'00000000'x
do j=0 to length($)%64-1
a_=a; b_=b; c_=c; d_=d
chunk=j*64
do k=1 for 16 /*process the message in chunks. */
!.k=reverse(substr($,chunk+1+4*(k-1),4))▼
▲ do k=1 for 16 /*process the message in chunks. */
end /*k*/
▲ !.k=reverse(substr($,chunk+1+4*(k-1),4))
a=.part1(a,b,c,d, 0, 7,3614090360) /* 1*/
d=.part1(d,a,b,c, 1,12,3905402710) /* 2*/
Line 2,083 ⟶ 2,079:
c=.part4(c,d,a,b, 2,15, 718787259) /*63*/
b=.part4(b,c,d,a, 9,21,3951481745) /*64*/
a=.a(a_,a); b=.a(b_,b); c=.a(c_,c); d=.a(d_,d)
end /*j*/
return c2x(reverse(a))c2x(reverse(b))c2x(reverse(c))c2x(reverse(d))
/*─────────────────────────────────────subroutines──────────────────────*/
.part1: procedure expose !.; parse arg w,x,y,z,n,m,_; n=n+1
return .a(.lR(right(d2c(_+c2d(w)+c2d(.f(x,y,z))+c2d(!.n)),4,'0'x),m),x)
.part2: procedure expose !.; parse arg w,x,y,z,n,m,_; n=n+1▼
return .a(.lR(right(d2c(_+c2d(w)+c2d(.g(x,y,z))+c2d(!.n)),4,'0'x),m),x)▼
▲.part2: procedure expose !.; parse arg w,x,y,z,n,m,_; n=n+1
▲return .a(.lR(right(d2c(_+c2d(w)+c2d(.g(x,y,z))+c2d(!.n)),4,'0'x),m),x)
return .a(.lR(right(d2c(_+c2d(w)+c2d(.h(x,y,z))+c2d(!.n)),4,'0'x),m),x)
.
return .a(.lR(right(d2c(
.i: return bitxor(arg(2),bitor(arg(1),bitxor(arg(3),'ffffffff'x)))▼
▲.part4: procedure expose !.; parse arg w,x,y,z,n,m; n=n+1
.a: return
.g: procedure; parse arg x,y,z
▲.i: return bitxor(arg(2),bitor(arg(1),bitxor(arg(3),'ffffffff'x)))
.
?=x2b(c2x(_)); return x2c(b2x(right(?||left(?,#),length(?))))</lang>▼
'''output'''
▲.g: procedure; parse arg x,y,z
▲.lR: procedure; parse arg _,#; if #==0 then return _ /*left rotate.*/
▲?=x2b(c2x(_)); return x2c(b2x(right(?||left(?,#),length(?))))
▲<pre style="height:25ex;overflow:scroll">
in =
out = D41D8CD98F00B204E9800998ECF8427E
|