-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathxor16.pas
54 lines (42 loc) · 958 Bytes
/
xor16.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
52
53
54
unit XOR16;
//XOR16
//Author: domasz
//Version: 0.1 (2022-11-17)
//Licence: MIT
interface
uses SysUtils, HasherBase;
type THasherXOR16 = class(THasherbase)
private
FHash: Cardinal;
public
constructor Create; override;
procedure Update(Msg: PByte; Length: Integer); override;
function Final: String; override;
end;
implementation
constructor THasherXOR16.Create;
begin
inherited Create;
Check := '0839';
FHash := 0;
end;
procedure THasherXOR16.Update(Msg: PByte; Length: Integer);
var i: Integer;
L: Byte;
begin
L := 0;
for i:=0 to Length-1 do begin
FHash := FHash xor (Msg^ shl L);
Inc(L, 8);
if L = 32 then L := 0;
Inc(Msg);
end;
end;
function THasherXOR16.Final: String;
begin
FHash := (FHash and $FFFF) xor (FHash shr 16);
Result := IntToHex(FHash, 4);
end;
initialization
HasherList.RegisterHasher('XOR16', THasherXOR16);
end.