Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

150
Task/MD5/ALGOL-68/md5.alg Normal file
View file

@ -0,0 +1,150 @@
# Based on wikipedia article pseudocode #
# s specifies the per-round shift amounts #
[]INT 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);
[]BITS k = (16rd76aa478, 16re8c7b756, 16r242070db, 16rc1bdceee,
16rf57c0faf, 16r4787c62a, 16ra8304613, 16rfd469501,
16r698098d8, 16r8b44f7af, 16rffff5bb1, 16r895cd7be,
16r6b901122, 16rfd987193, 16ra679438e, 16r49b40821,
16rf61e2562, 16rc040b340, 16r265e5a51, 16re9b6c7aa,
16rd62f105d, 16r02441453, 16rd8a1e681, 16re7d3fbc8,
16r21e1cde6, 16rc33707d6, 16rf4d50d87, 16r455a14ed,
16ra9e3e905, 16rfcefa3f8, 16r676f02d9, 16r8d2a4c8a,
16rfffa3942, 16r8771f681, 16r6d9d6122, 16rfde5380c,
16ra4beea44, 16r4bdecfa9, 16rf6bb4b60, 16rbebfbc70,
16r289b7ec6, 16reaa127fa, 16rd4ef3085, 16r04881d05,
16rd9d4d039, 16re6db99e5, 16r1fa27cf8, 16rc4ac5665,
16rf4292244, 16r432aff97, 16rab9423a7, 16rfc93a039,
16r655b59c3, 16r8f0ccc92, 16rffeff47d, 16r85845dd1,
16r6fa87e4f, 16rfe2ce6e0, 16ra3014314, 16r4e0811a1,
16rf7537e82, 16rbd3af235, 16r2ad7d2bb, 16reb86d391);
OP + = (BITS a, b) BITS:
BEGIN
BITS c = BIN (ABS (a AND 16rffff) + ABS (b AND 16rffff));
BITS d = BIN (ABS (a SHR 16) + ABS (b SHR 16) + ABS (c SHR 16));
(c AND 16rffff) OR (d SHL 16)
END;
#[0:63]LONG INT k;
FOR i FROM 0 TO 63 DO
k[i] := ENTIER (ABS (sin(i+1)) * LONG INT(2)**32)
OD;#
PROC md5 = (STRING intext) STRING:
BEGIN
# Initialize variables: #
BITS a0 := 16r67452301,
a1 := 16refcdab89,
a2 := 16r98badcfe,
a3 := 16r10325476;
STRING text := intext;
# Pre-processing: adding a single 1 bit #
text +:= REPR 128;
# Pre-processing: padding with zeros
append "0" bit until message length in bits ≡ 448 (mod 512) #
WHILE ELEMS text MOD 64 ≠ 56 DO
text +:= REPR 0
OD;
# append original length in bits mod (2 pow 64) to message #
text +:= dec2asc (ELEMS intext * 8);
# MD5 rounds #
# Process the message in successive 512-bit chunks: #
WHILE text ≠ "" DO
# for each 512-bit (64 byte) chunk of message #
[]CHAR chunk = text[1:64]; text := text[65:];
# break chunk into sixteen 32-bit words M[j], 0 <= j <= 15 #
[0:15]BITS m;
FOR j FROM 0 TO 15 DO
m[j] := BIN (ABS chunk[j*4+1]) OR
BIN (ABS chunk[j*4+2]) SHL 8 OR
BIN (ABS chunk[j*4+3]) SHL 16 OR
BIN (ABS chunk[j*4+4]) SHL 24
OD;
INT g;
BITS a, b, c, d, f, dtemp;
# Initialize hash value for this chunk #
a := a0;
b := a1;
c := a2;
d := a3;
FOR i FROM 0 TO 63 DO
IF 0 <= i AND i <= 15 THEN
f := (b AND c) OR ((NOT b) AND d);
g := i
ELIF 16 <= i AND i <= 31 THEN
f := (d AND b) OR ((NOT d) AND c);
g := (5×i + 1) MOD 16
ELIF 32 <= i AND i <= 47 THEN
f := b XOR c XOR d;
g := (3×i + 5) MOD 16
ELIF 48 <= i AND i <= 63 THEN
f := c XOR (b OR (NOT d));
g := (7×i) MOD 16
FI;
dtemp := d;
d := c;
c := b;
b := b + leftrotate ((a + f + k[1+i] + m[g]), s[1+i]);
a := dtemp
OD;
# Add this chunk's hash to result so far #
a0 := a0 + a;
a1 := a1 + b;
a2 := a2 + c;
a3 := a3 + d
OD;
revhex (a0) + revhex (a1) + revhex (a2) + revhex (a3)
END;
PROC leftrotate = (BITS x, INT c) BITS:
(x SHL c) OR (x SHR (32-c));
# dec2asc: dec to 8 byte asc #
PROC dec2asc = (INT nn)STRING:
BEGIN
STRING h := ""; INT n := nn;
FOR i TO 8 DO
h +:= REPR (n MOD 256);
n ÷:= 256
OD;
h
END;
PROC revhex = (BITS x) STRING :
BEGIN # Convert to lowercase hexadecimal STRING #
PROC hexdig = (BITS x) CHAR: (REPR (ABS(x) <= 9 | ABS(x) + ABS("0") | ABS(x) - 10 + ABS("a")));
hexdig (x SHR 4 AND 16rf) +
hexdig (x AND 16rf) +
hexdig (x SHR 12 AND 16rf) +
hexdig (x SHR 8 AND 16rf) +
hexdig (x SHR 20 AND 16rf) +
hexdig (x SHR 16 AND 16rf) +
hexdig (x SHR 28 AND 16rf) +
hexdig (x SHR 24 AND 16rf)
END;
STRING testmsg = "The quick brown fox jumps over the lazy dog";
STRING checksum = "9e107d9d372bb6826bd81d3542a419d6";
print ((testmsg, new line));
print ((checksum, new line));
STRING test = md5 (testmsg);
IF test = checksum THEN
print (("passed", new line));
print ((test, new line))
ELSE
print (("failed"))
FI

View file

@ -1,4 +1,14 @@
(ql:quickload 'ironclad)
(defun md5 (sequence)
(defun md5 (str)
(ironclad:byte-array-to-hex-string
(ironclad:digest-sequence :md5 sequence)))
(ironclad:digest-sequence :md5
(ironclad:ascii-string-to-byte-array str))))
(defvar *tests* '(""
"a"
"abc"
"message digest"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"))
(dolist (msg *tests*)
(format T "~s: ~a~%" msg (md5 msg)))

View file

@ -1,2 +1,10 @@
CL-USER> (md5 "The quick brown fox jumped over the lazy dog's back")
"d65474514ed8865634bf8623391fe6d8" ; MD5 hash of the unicode version of the string.
(cffi:load-foreign-library "libcrypto.so")
(cffi:defcfun ("MD5" MD5) :void (string :string) (len :int) (ptr :pointer))
(let ((string-to-convert "The quick brown fox jumped over the lazy dog's back")
(ptr (cffi:foreign-alloc :unsigned-char :count 16)))
(md5 string-to-convert (length string-to-convert) ptr)
(loop for i from 0 below 16 do
(format t "~a" (write-to-string (cffi:mem-ref ptr :unsigned-char i) :base 16)))
(cffi:foreign-free ptr))

View file

@ -1,14 +0,0 @@
(ql:quickload 'ironclad)
(defun md5 (str)
(ironclad:byte-array-to-hex-string
(ironclad:digest-sequence :md5
(ironclad:ascii-string-to-byte-array str))))
(defvar *tests* '(""
"a"
"abc"
"message digest"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"))
(dolist (msg *tests*)
(format T "~s: ~a~%" msg (md5 msg)))

View file

@ -0,0 +1,9 @@
#!/usr/bin/env runhaskell
import Data.ByteString.Char8 (pack)
import System.Environment (getArgs)
import Crypto.Hash
main :: IO ()
main = print . md5 . pack . unwords =<< getArgs
where md5 x = hash x :: Digest MD5

37
Task/MD5/Julia/md5.julia Normal file
View file

@ -0,0 +1,37 @@
using Nettle
function md5sum(s::String)
bytes2hex(md5_hash(s))
end
function Base.trunc(s::String, n::Integer)
0 < n || throw(DomainError())
len = length(s)
len > n || return s
3 < n || return s[1:n]
return s[1:n-3]*"..."
end
tests = ["" => "d41d8cd98f00b204e9800998ecf8427e",
"a" => "0cc175b9c0f1b6a831c399e269772661",
"abc" => "900150983cd24fb0d6963f7d28e17f72",
"message digest" => "f96b697d7cb7938d525a2f31aaf161d0",
"abcdefghijklmnopqrstuvwxyz" => "c3fcd3d76192e4007dfb496cca67e13b",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" =>
"d174ab98d277d9f5a5611c2c9f419d9f",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890" =>
"57edf4a22be3c955ac49da2e2107b67a",
"foobad" => "3858f62230ac3c915f300c664312c63f"]
println("Testing Julia's MD5 hash against RFC 1321.")
for k in sort(collect(keys(tests)), by=(x)->length(x))
mysum = md5sum(k)
print(@sprintf(" %15s => ", trunc(k, 15)), mysum)
if mysum == tests[k]
println(" MD5 OK")
else
println(" MD5 Bad")
println(" The sum should be ", tests[k])
end
end

View file

@ -0,0 +1,17 @@
MODULE MD5;
IMPORT
Crypto:MD5,
Crypto:Utils,
Strings,
Out;
VAR
h: MD5.Hash;
str: ARRAY 128 OF CHAR;
BEGIN
h := MD5.NewHash();
h.Initialize;
str := "The quick brown fox jumped over the lazy dog's back";
h.Update(str,0,Strings.Length(str));
h.GetHash(str,0);
Out.String("MD5: ");Utils.PrintHex(str,0,h.size);Out.Ln
END MD5.

View file

@ -1,119 +1,117 @@
/*REXX program to test the MD5 procedure as per the test suite in the */
/*─── IETF RFC (1321) ─── The MD5 Message-Digest Algorithm. April 1992.*/
msg.1 = /*────────────MD5 test suite [from above doc].*/
/*REXX program tests the MD5 procedure as per the test suite in the */
/*────── IETF RFC (1321) ────── The MD5 Message─Digest Algorithm. April 1992.*/
msg.1 = /*─────MD5 test suite [from above doc].*/
msg.2 = 'a'
msg.3 = 'abc'
msg.4 = 'message digest'
msg.5 = 'abcdefghijklmnopqrstuvwxyz'
msg.6 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
msg.7 = 12345678901234567890123456789012345678901234567890123456789012345678901234567890
msg.0 = 7 /* [↑] value doesn't need quotes*/
do m=1 for msg.0 /*process each of the 7 messages.*/
say ' in =' msg.m /*display the in message. */
say 'out =' MD5(msg.m) /* " " out " */
say /* " a blank like for a sep.*/
msg.0 = 7 /* [↑] last value doesn't need quotes.*/
do m=1 for msg.0 /*process each of the seven messages. */
say ' in =' msg.m /*display the in message. */
say 'out =' MD5(msg.m) /* " " out " */
say /* " a blank like for a separator.*/
end /*m*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────MD5 subroutine──────────────────────*/
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(!) /*length of the message*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────MD5 subroutine────────────────────────────*/
MD5: procedure; parse arg !; numeric digits 20 /*insure enough decimal digs.*/
parse value '67452301'x 'efcdab89'x '98badcfe'x '10325476'x with a b c d
#=length(!) /*length of the input message*/
L=#*8 // 512; if L<448 then plus=448-L
if L>448 then plus=960-L
if L=448 then plus=512
/* [↓] a little of this, ··· */
$=!'80'x||copies("0"x,plus%8-1)reverse(right(d2c(8*#),4,'0'x))||"00000000"x
/* [↑] ··· and a little of that.*/
do j=0 to length($)%64-1 /*process message (lots of steps)*/
a_=a; b_=b; c_=c; d_=d /*save original values for later.*/
chunk=j*64 /*calculate size of the chunks. */
do k=1 for 16 /*process the message in chunks. */
!.k=reverse(substr($,chunk+1+4*(k-1),4)) /*magic stuff.*/
/* [↓] a little of this, ··· */
$=!'80'x || copies("0"x,plus%8-1)reverse(right(d2c(8*#),4,'0'x)) || "00000000"x
/* [↑] ··· and a little of that.*/
do j=0 to length($)%64-1 /*process the message (lots of steps).*/
a_=a; b_=b; c_=c; d_=d /*save the original values for later.*/
chunk=j*64 /*calculate the size of the chunks. */
do k=1 for 16 /*process the message in chunks. */
!.k=reverse(substr($,chunk+1+4*(k-1),4)) /*magic stuff.*/
end /*k*/
a = .part1( a, b, c, d, 0, 7, 3614090360) /*────1───*/
d = .part1( d, a, b, c, 1, 12, 3905402710) /*────2───*/
c = .part1( c, d, a, b, 2, 17, 606105819) /*────3───*/
b = .part1( b, c, d, a, 3, 22, 3250441966) /*────4───*/
a = .part1( a, b, c, d, 4, 7, 4118548399) /*────5───*/
d = .part1( d, a, b, c, 5, 12, 1200080426) /*────6───*/
c = .part1( c, d, a, b, 6, 17, 2821735955) /*────7───*/
b = .part1( b, c, d, a, 7, 22, 4249261313) /*────8───*/
a = .part1( a, b, c, d, 8, 7, 1770035416) /*────9───*/
d = .part1( d, a, b, c, 9, 12, 2336552879) /*───10───*/
c = .part1( c, d, a, b, 10, 17, 4294925233) /*───11───*/
b = .part1( b, c, d, a, 11, 22, 2304563134) /*───12───*/
a = .part1( a, b, c, d, 12, 7, 1804603682) /*───13───*/
d = .part1( d, a, b, c, 13, 12, 4254626195) /*───14───*/
c = .part1( c, d, a, b, 14, 17, 2792965006) /*───15───*/
b = .part1( b, c, d, a, 15, 22, 1236535329) /*───16───*/
a = .part2( a, b, c, d, 1, 5, 4129170786) /*───17───*/
d = .part2( d, a, b, c, 6, 9, 3225465664) /*───18───*/
c = .part2( c, d, a, b, 11, 14, 643717713) /*───19───*/
b = .part2( b, c, d, a, 0, 20, 3921069994) /*───20───*/
a = .part2( a, b, c, d, 5, 5, 3593408605) /*───21───*/
d = .part2( d, a, b, c, 10, 9, 38016083) /*───22───*/
c = .part2( c, d, a, b, 15, 14, 3634488961) /*───23───*/
b = .part2( b, c, d, a, 4, 20, 3889429448) /*───24───*/
a = .part2( a, b, c, d, 9, 5, 568446438) /*───25───*/
d = .part2( d, a, b, c, 14, 9, 3275163606) /*───26───*/
c = .part2( c, d, a, b, 3, 14, 4107603335) /*───27───*/
b = .part2( b, c, d, a, 8, 20, 1163531501) /*───28───*/
a = .part2( a, b, c, d, 13, 5, 2850285829) /*───29───*/
d = .part2( d, a, b, c, 2, 9, 4243563512) /*───30───*/
c = .part2( c, d, a, b, 7, 14, 1735328473) /*───31───*/
b = .part2( b, c, d, a, 12, 20, 2368359562) /*───32───*/
a = .part3( a, b, c, d, 5, 4, 4294588738) /*───33───*/
d = .part3( d, a, b, c, 8, 11, 2272392833) /*───34───*/
c = .part3( c, d, a, b, 11, 16, 1839030562) /*───35───*/
b = .part3( b, c, d, a, 14, 23, 4259657740) /*───36───*/
a = .part3( a, b, c, d, 1, 4, 2763975236) /*───37───*/
d = .part3( d, a, b, c, 4, 11, 1272893353) /*───38───*/
c = .part3( c, d, a, b, 7, 16, 4139469664) /*───39───*/
b = .part3( b, c, d, a, 10, 23, 3200236656) /*───40───*/
a = .part3( a, b, c, d, 13, 4, 681279174) /*───41───*/
d = .part3( d, a, b, c, 0, 11, 3936430074) /*───42───*/
c = .part3( c, d, a, b, 3, 16, 3572445317) /*───43───*/
b = .part3( b, c, d, a, 6, 23, 76029189) /*───44───*/
a = .part3( a, b, c, d, 9, 4, 3654602809) /*───45───*/
d = .part3( d, a, b, c, 12, 11, 3873151461) /*───46───*/
c = .part3( c, d, a, b, 15, 16, 530742520) /*───47───*/
b = .part3( b, c, d, a, 2, 23, 3299628645) /*───48───*/
a = .part4( a, b, c, d, 0, 6, 4096336452) /*───49───*/
d = .part4( d, a, b, c, 7, 10, 1126891415) /*───50───*/
c = .part4( c, d, a, b, 14, 15, 2878612391) /*───51───*/
b = .part4( b, c, d, a, 5, 21, 4237533241) /*───52───*/
a = .part4( a, b, c, d, 12, 6, 1700485571) /*───53───*/
d = .part4( d, a, b, c, 3, 10, 2399980690) /*───54───*/
c = .part4( c, d, a, b, 10, 15, 4293915773) /*───55───*/
b = .part4( b, c, d, a, 1, 21, 2240044497) /*───56───*/
a = .part4( a, b, c, d, 8, 6, 1873313359) /*───57───*/
d = .part4( d, a, b, c, 15, 10, 4264355552) /*───58───*/
c = .part4( c, d, a, b, 6, 15, 2734768916) /*───59───*/
b = .part4( b, c, d, a, 13, 21, 1309151649) /*───60───*/
a = .part4( a, b, c, d, 4, 6, 4149444226) /*───61───*/
d = .part4( d, a, b, c, 11, 10, 3174756917) /*───62───*/
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)
a = .part1( a, b, c, d, 0, 7, 3614090360) /*■■■■1■■■*/
d = .part1( d, a, b, c, 1, 12, 3905402710) /*■■■■2■■■*/
c = .part1( c, d, a, b, 2, 17, 606105819) /*■■■■3■■■*/
b = .part1( b, c, d, a, 3, 22, 3250441966) /*■■■■4■■■*/
a = .part1( a, b, c, d, 4, 7, 4118548399) /*■■■■5■■■*/
d = .part1( d, a, b, c, 5, 12, 1200080426) /*■■■■6■■■*/
c = .part1( c, d, a, b, 6, 17, 2821735955) /*■■■■7■■■*/
b = .part1( b, c, d, a, 7, 22, 4249261313) /*■■■■8■■■*/
a = .part1( a, b, c, d, 8, 7, 1770035416) /*■■■■9■■■*/
d = .part1( d, a, b, c, 9, 12, 2336552879) /*■■■10■■■*/
c = .part1( c, d, a, b, 10, 17, 4294925233) /*■■■11■■■*/
b = .part1( b, c, d, a, 11, 22, 2304563134) /*■■■12■■■*/
a = .part1( a, b, c, d, 12, 7, 1804603682) /*■■■13■■■*/
d = .part1( d, a, b, c, 13, 12, 4254626195) /*■■■14■■■*/
c = .part1( c, d, a, b, 14, 17, 2792965006) /*■■■15■■■*/
b = .part1( b, c, d, a, 15, 22, 1236535329) /*■■■16■■■*/
a = .part2( a, b, c, d, 1, 5, 4129170786) /*■■■17■■■*/
d = .part2( d, a, b, c, 6, 9, 3225465664) /*■■■18■■■*/
c = .part2( c, d, a, b, 11, 14, 643717713) /*■■■19■■■*/
b = .part2( b, c, d, a, 0, 20, 3921069994) /*■■■20■■■*/
a = .part2( a, b, c, d, 5, 5, 3593408605) /*■■■21■■■*/
d = .part2( d, a, b, c, 10, 9, 38016083) /*■■■22■■■*/
c = .part2( c, d, a, b, 15, 14, 3634488961) /*■■■23■■■*/
b = .part2( b, c, d, a, 4, 20, 3889429448) /*■■■24■■■*/
a = .part2( a, b, c, d, 9, 5, 568446438) /*■■■25■■■*/
d = .part2( d, a, b, c, 14, 9, 3275163606) /*■■■26■■■*/
c = .part2( c, d, a, b, 3, 14, 4107603335) /*■■■27■■■*/
b = .part2( b, c, d, a, 8, 20, 1163531501) /*■■■28■■■*/
a = .part2( a, b, c, d, 13, 5, 2850285829) /*■■■29■■■*/
d = .part2( d, a, b, c, 2, 9, 4243563512) /*■■■30■■■*/
c = .part2( c, d, a, b, 7, 14, 1735328473) /*■■■31■■■*/
b = .part2( b, c, d, a, 12, 20, 2368359562) /*■■■32■■■*/
a = .part3( a, b, c, d, 5, 4, 4294588738) /*■■■33■■■*/
d = .part3( d, a, b, c, 8, 11, 2272392833) /*■■■34■■■*/
c = .part3( c, d, a, b, 11, 16, 1839030562) /*■■■35■■■*/
b = .part3( b, c, d, a, 14, 23, 4259657740) /*■■■36■■■*/
a = .part3( a, b, c, d, 1, 4, 2763975236) /*■■■37■■■*/
d = .part3( d, a, b, c, 4, 11, 1272893353) /*■■■38■■■*/
c = .part3( c, d, a, b, 7, 16, 4139469664) /*■■■39■■■*/
b = .part3( b, c, d, a, 10, 23, 3200236656) /*■■■40■■■*/
a = .part3( a, b, c, d, 13, 4, 681279174) /*■■■41■■■*/
d = .part3( d, a, b, c, 0, 11, 3936430074) /*■■■42■■■*/
c = .part3( c, d, a, b, 3, 16, 3572445317) /*■■■43■■■*/
b = .part3( b, c, d, a, 6, 23, 76029189) /*■■■44■■■*/
a = .part3( a, b, c, d, 9, 4, 3654602809) /*■■■45■■■*/
d = .part3( d, a, b, c, 12, 11, 3873151461) /*■■■46■■■*/
c = .part3( c, d, a, b, 15, 16, 530742520) /*■■■47■■■*/
b = .part3( b, c, d, a, 2, 23, 3299628645) /*■■■48■■■*/
a = .part4( a, b, c, d, 0, 6, 4096336452) /*■■■49■■■*/
d = .part4( d, a, b, c, 7, 10, 1126891415) /*■■■50■■■*/
c = .part4( c, d, a, b, 14, 15, 2878612391) /*■■■51■■■*/
b = .part4( b, c, d, a, 5, 21, 4237533241) /*■■■52■■■*/
a = .part4( a, b, c, d, 12, 6, 1700485571) /*■■■53■■■*/
d = .part4( d, a, b, c, 3, 10, 2399980690) /*■■■54■■■*/
c = .part4( c, d, a, b, 10, 15, 4293915773) /*■■■55■■■*/
b = .part4( b, c, d, a, 1, 21, 2240044497) /*■■■56■■■*/
a = .part4( a, b, c, d, 8, 6, 1873313359) /*■■■57■■■*/
d = .part4( d, a, b, c, 15, 10, 4264355552) /*■■■58■■■*/
c = .part4( c, d, a, b, 6, 15, 2734768916) /*■■■59■■■*/
b = .part4( b, c, d, a, 13, 21, 1309151649) /*■■■60■■■*/
a = .part4( a, b, c, d, 4, 6, 4149444226) /*■■■61■■■*/
d = .part4( d, a, b, c, 11, 10, 3174756917) /*■■■62■■■*/
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────────────────────────────────*/
.a: return right(d2c(c2d(arg(1)) + c2d(arg(2))), 4, '0'x)
.h: procedure; parse arg x,y,z; return bitxor(bitxor(x, y), z)
.i: return bitxor(arg(2), bitor(arg(1), bitxor(arg(3), 'ffffffff'x)))
.f: procedure; parse arg x,y,z
return bitor(bitand(x,y), bitand(bitxor(x, 'ffffffff'x), z))
.g: procedure; parse arg x,y,z
return bitor(bitand(x,z), bitand(y, bitxor(z, 'ffffffff'x)))
.Lr: procedure; parse arg _,#; if #==0 then return _ /*left rotate.*/
?=x2b(c2x(_)); return x2c(b2x(right(? || left(?, #), length(?))))
/*─────────────────────────────────────subroutines─────────────────────────────────────*/
.a: return right(d2c(c2d(arg(1)) + c2d(arg(2))), 4, '0'x)
.h: return bitxor(bitxor(arg(1), arg(2)), arg(3))
.i: return bitxor(arg(2), bitor(arg(1), bitxor(arg(3), 'ffffffff'x)))
.f: return bitor(bitand(arg(1),arg(2)), bitand(bitxor(arg(1), 'ffffffff'x), arg(3)))
.g: return bitor(bitand(arg(1),arg(3)), bitand(arg(2), bitxor(arg(3), 'ffffffff'x)))
.Lr: procedure; parse arg _,#; if #==0 then return _ /*left rotate.*/
?=x2b(c2x(_)); return x2c(b2x(right(? || left(?, #), length(?))))
.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)
.part3: procedure expose !.; parse arg w,x,y,z,n,m,_; n=n+1
return .a(.Lr(right(d2c(_+c2d(w)+c2d(.h(x,y,z))+c2d(!.n)),4,'0'x),m),x)
.part4: procedure expose !.; parse arg w,x,y,z,n,m; n=n+1
return .a(.Lr(right(d2c(c2d(w)+c2d(.i(x,y,z))+c2d(!.n)+arg(7)),4,'0'x),m),x)
.part4: procedure expose !.; parse arg w,x,y,z,n,m,_; n=n+1
return .a(.Lr(right(d2c(c2d(w)+c2d(.i(x,y,z))+c2d(!.n)+_),4,'0'x),m),x)

2
Task/MD5/Rust/md5-1.rust Normal file
View file

@ -0,0 +1,2 @@
[dependencies]
rust-crypto = "0.2"

10
Task/MD5/Rust/md5-2.rust Normal file
View file

@ -0,0 +1,10 @@
extern crate crypto;
use crypto::digest::Digest;
use crypto::md5::Md5;
fn main() {
let mut sh = Md5::new();
sh.input_str("The quick brown fox jumped over the lazy dog's back");
println!("{}", sh.result_str());
}