-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfletcher32.pas
51 lines (40 loc) · 990 Bytes
/
fletcher32.pas
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
unit fletcher32;
//Fletcher-32
//Author: domasz
//Version: 0.1 (2022-11-17)
//Licence: MIT
interface
uses SysUtils, HasherBase;
type THasherFletcher32 = class(THasherbase)
private
FHash, FHash2: Cardinal;
public
constructor Create; override;
procedure Update(Msg: PByte; Length: Integer); override;
function Final: String; override;
end;
implementation
constructor THasherFletcher32.Create;
begin
inherited Create;
Check := '091501DD';
FHash := 0;
FHash2 := 0;
end;
procedure THasherFletcher32.Update(Msg: PByte; Length: Integer);
var i: Integer;
begin
for i:=0 to Length-1 do begin
FHash := (FHash + Msg^) mod 65535;
FHash2 := (FHash2 + FHash) mod 65535;
Inc(Msg);
end;
end;
function THasherFletcher32.Final: String;
begin
FHash := (FHash2 shl 16) or FHash;
Result := IntToHex(FHash, 8);
end;
initialization
HasherList.RegisterHasher('Fletcher-32', THasherFletcher32);
end.