forked from tangentstorm/coinops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsha256_dcp.pas
More file actions
36 lines (33 loc) · 953 Bytes
/
sha256_dcp.pas
File metadata and controls
36 lines (33 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{$mode delphi}{$h+}
program sha256_dcp;
uses sysutils, dateutils, DCPcrypt2, DCPsha256, uSHA256;
var i : integer; t : TDateTime; d : T256BitDigest;
const
s = '0123456789ABCDEF0123456789ABCDEF';
n = 65536;
function CalcSha256(s : string) : T256BitDigest; overload;
var sha : TDCP_sha256;
begin
sha := TDCP_sha256.Create(nil);
sha.Init;
sha.UpdateStr(s);
sha.Final(result);
sha.Free;
end;
function CalcSha256(var buf; len : word ) : T256BitDigest; overload;
var sha : TDCP_sha256;
begin
sha := TDCP_sha256.Create(nil);
sha.Init;
sha.Update(buf, len);
sha.Final(result);
sha.Free;
end;
begin
t := now;
d := CalcSHA256(s);
for i := 2 to n do d := CalcSHA256(d, 32);
writeln('recursively applied SHA256 to "', s, '" ', n, ' times in ',
Format('%0.3n',[MilliSecondsBetween( now, t )/1000]) : 3, 's.');
writeln(SHA256DigestToHexW(d));
end.