MD5/Implementation: Difference between revisions
→{{header|Perl 6}}: use native types where possible
(→{{header|Perl 6}}: modernize) |
(→{{header|Perl 6}}: use native types where possible) |
||
Line 2,219:
=={{header|Perl 6}}==
{{works with|rakudo|2015-09-22}}
<lang perl6>sub infix:<⊞>(uint32 $a, uint32 $b --> uint32) { ($a + $b) +& 0xffffffff }
<lang perl6>use Test;▼
sub infix:«<<<»(
▲sub infix:«<<<»(\x, \n) { (x +< n) % 2**32 +| (x +> (32-n)) }
{ $^b +^ ($^a +| +^$^c) };
constant
constant T = (floor(abs(sin($_ + 1)) * 2**32) for ^64);
constant k = flat ( $_ for ^16),
sub little-endian($w, $n, *@v) {
Line 2,255 ⟶ 2,252:
}
sub md5-block(@H
{
my uint32 ($A, $B, $C, $D) = @H;
($A, $B, $C, $D) = ($D, $B ⊞ (($A ⊞
▲ ($A, $B, $C, $D)
▲ = ($D, $B ⊞ (($A ⊞ f ⊞ T[i] ⊞ @X[k[i]]) <<< S[i]), $B, $C);
@H «⊞=» ($A, $B, $C, $D);
}
sub md5(Blob $msg --> Blob)
{
my uint32 @M = md5-pad($msg);
my uint32 @H = 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476;
md5-block(@H, @M[$_ .. $_+15]) for 0, 16 ...^ +@M;
Blob.new: little-endian(8, 4, @H);
}
plan 7;
for 'd41d8cd98f00b204e9800998ecf8427e', '',
Line 2,287 ⟶ 2,283:
{{out}}
<pre>1..7
ok 2 - 0cc175b9c0f1b6a831c399e269772661 is MD5 digest of 'a'
ok 3 - 900150983cd24fb0d6963f7d28e17f72 is MD5 digest of 'abc'
|