mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-06 20:22:24 +00:00
md5sum test will now work with binary files as well.
This commit is contained in:
parent
75c155f8ec
commit
e376e59f58
1 changed files with 10 additions and 5 deletions
|
|
@ -19,25 +19,30 @@ PROCEDURE main;
|
||||||
hexDigest: ARRAY 33 OF CHAR;
|
hexDigest: ARRAY 33 OF CHAR;
|
||||||
F: Files.File;
|
F: Files.File;
|
||||||
R: Files.Rider;
|
R: Files.Rider;
|
||||||
input: ARRAY 512 OF CHAR;
|
input: POINTER TO ARRAY OF CHAR;
|
||||||
|
ilen: LONGINT;
|
||||||
ch: CHAR;
|
ch: CHAR;
|
||||||
i: INTEGER;
|
i: INTEGER;
|
||||||
BEGIN
|
BEGIN
|
||||||
F := Files.Old("hello.txt");
|
F := Files.Old("SETs.pdf");
|
||||||
IF F # NIL THEN
|
IF F # NIL THEN
|
||||||
Files.Set(R, F, 0);
|
Files.Set(R, F, 0);
|
||||||
|
ilen := Files.Length(F);
|
||||||
|
Out.String("file length is "); Out.Int(ilen, 0); Out.Ln;
|
||||||
|
NEW(input, ilen+1);
|
||||||
i := 0;
|
i := 0;
|
||||||
REPEAT
|
REPEAT
|
||||||
Files.Read(R, ch);
|
Files.Read(R, ch);
|
||||||
input[i] := ch;
|
input^[i] := ch;
|
||||||
INC(i)
|
INC(i)
|
||||||
UNTIL R.eof;
|
UNTIL R.eof;
|
||||||
dump(input);
|
(*dump(input^);*)
|
||||||
END;
|
END;
|
||||||
|
|
||||||
context := MD5.New(); (* Initialize MD5 context *)
|
context := MD5.New(); (* Initialize MD5 context *)
|
||||||
|
|
||||||
MD5.WriteBytes(context, input, Strings.Length(input)); (* Process input string *)
|
(*MD5.WriteBytes(context, input^, Strings.Length(input^));*) (* Process input string *)
|
||||||
|
MD5.WriteBytes(context, input^, LEN(input^)-1); (* Process input string *)
|
||||||
MD5.Close(context, digest); (* Finalize and get digest *)
|
MD5.Close(context, digest); (* Finalize and get digest *)
|
||||||
|
|
||||||
MD5.ToString(digest, hexDigest); (* Convert digest to hex string *)
|
MD5.ToString(digest, hexDigest); (* Convert digest to hex string *)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue