-
Notifications
You must be signed in to change notification settings - Fork 4
/
CRC6_DARC.pas
82 lines (71 loc) · 2.22 KB
/
CRC6_DARC.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
unit CRC6_DARC;
//CRC-6 DARC
//Author: domasz
//Version: 0.1 (2022-11-17)
//Licence: MIT
interface
uses SysUtils, HasherBase;
type THasherCRC6_DARC = class(THasherbase)
private
FHash: Byte;
public
constructor Create; override;
procedure Update(Msg: PByte; Length: Integer); override;
function Final: String; override;
end;
implementation
var Table: array[0..255] of Byte = (
$00, $32, $29, $1B, $1F, $2D, $36, $04,
$3E, $0C, $17, $25, $21, $13, $08, $3A,
$31, $03, $18, $2A, $2E, $1C, $07, $35,
$0F, $3D, $26, $14, $10, $22, $39, $0B,
$2F, $1D, $06, $34, $30, $02, $19, $2B,
$11, $23, $38, $0A, $0E, $3C, $27, $15,
$1E, $2C, $37, $05, $01, $33, $28, $1A,
$20, $12, $09, $3B, $3F, $0D, $16, $24,
$13, $21, $3A, $08, $0C, $3E, $25, $17,
$2D, $1F, $04, $36, $32, $00, $1B, $29,
$22, $10, $0B, $39, $3D, $0F, $14, $26,
$1C, $2E, $35, $07, $03, $31, $2A, $18,
$3C, $0E, $15, $27, $23, $11, $0A, $38,
$02, $30, $2B, $19, $1D, $2F, $34, $06,
$0D, $3F, $24, $16, $12, $20, $3B, $09,
$33, $01, $1A, $28, $2C, $1E, $05, $37,
$26, $14, $0F, $3D, $39, $0B, $10, $22,
$18, $2A, $31, $03, $07, $35, $2E, $1C,
$17, $25, $3E, $0C, $08, $3A, $21, $13,
$29, $1B, $00, $32, $36, $04, $1F, $2D,
$09, $3B, $20, $12, $16, $24, $3F, $0D,
$37, $05, $1E, $2C, $28, $1A, $01, $33,
$38, $0A, $11, $23, $27, $15, $0E, $3C,
$06, $34, $2F, $1D, $19, $2B, $30, $02,
$35, $07, $1C, $2E, $2A, $18, $03, $31,
$0B, $39, $22, $10, $14, $26, $3D, $0F,
$04, $36, $2D, $1F, $1B, $29, $32, $00,
$3A, $08, $13, $21, $25, $17, $0C, $3E,
$1A, $28, $33, $01, $05, $37, $2C, $1E,
$24, $16, $0D, $3F, $3B, $09, $12, $20,
$2B, $19, $02, $30, $34, $06, $1D, $2F,
$15, $27, $3C, $0E, $0A, $38, $23, $11
);
constructor THasherCRC6_DARC.Create;
begin
inherited Create;
FHash := $00;
Check := '26';
end;
procedure THasherCRC6_DARC.Update(Msg: PByte; Length: Integer);
var i: Integer;
begin
for i:=0 to Length-1 do begin
FHash := Table[($FF and (FHash xor Msg^))];
Inc(Msg);
end;
end;
function THasherCRC6_DARC.Final: String;
begin
Result := IntToHex(FHash, 2);
end;
initialization
HasherList.RegisterHasher('CRC-6 DARC', THasherCRC6_DARC);
end.