-
Notifications
You must be signed in to change notification settings - Fork 4
/
CRC24_OPENPGP.pas
85 lines (74 loc) · 3.85 KB
/
CRC24_OPENPGP.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
83
84
85
unit CRC24_OPENPGP;
//CRC-24 OPENPGP
//Author: domasz
//Version: 0.1 (2022-11-17)
//Licence: MIT
interface
uses SysUtils, HasherBase;
type THasherCRC24_OPENPGP = class(THasherBase)
private
FHash: Cardinal;
public
constructor Create; override;
procedure Update(Msg: PByte; Length: Integer); override;
function Final: String; override;
end;
implementation
var Table: array[0..255] of LongInt = (
$00000000, $00864CFB, $008AD50D, $000C99F6, $0093E6E1, $0015AA1A, $001933EC, $009F7F17,
$00A18139, $0027CDC2, $002B5434, $00AD18CF, $003267D8, $00B42B23, $00B8B2D5, $003EFE2E,
$00C54E89, $00430272, $004F9B84, $00C9D77F, $0056A868, $00D0E493, $00DC7D65, $005A319E,
$0064CFB0, $00E2834B, $00EE1ABD, $00685646, $00F72951, $007165AA, $007DFC5C, $00FBB0A7,
$000CD1E9, $008A9D12, $008604E4, $0000481F, $009F3708, $00197BF3, $0015E205, $0093AEFE,
$00AD50D0, $002B1C2B, $002785DD, $00A1C926, $003EB631, $00B8FACA, $00B4633C, $00322FC7,
$00C99F60, $004FD39B, $00434A6D, $00C50696, $005A7981, $00DC357A, $00D0AC8C, $0056E077,
$00681E59, $00EE52A2, $00E2CB54, $006487AF, $00FBF8B8, $007DB443, $00712DB5, $00F7614E,
$0019A3D2, $009FEF29, $009376DF, $00153A24, $008A4533, $000C09C8, $0000903E, $0086DCC5,
$00B822EB, $003E6E10, $0032F7E6, $00B4BB1D, $002BC40A, $00AD88F1, $00A11107, $00275DFC,
$00DCED5B, $005AA1A0, $00563856, $00D074AD, $004F0BBA, $00C94741, $00C5DEB7, $0043924C,
$007D6C62, $00FB2099, $00F7B96F, $0071F594, $00EE8A83, $0068C678, $00645F8E, $00E21375,
$0015723B, $00933EC0, $009FA736, $0019EBCD, $008694DA, $0000D821, $000C41D7, $008A0D2C,
$00B4F302, $0032BFF9, $003E260F, $00B86AF4, $002715E3, $00A15918, $00ADC0EE, $002B8C15,
$00D03CB2, $00567049, $005AE9BF, $00DCA544, $0043DA53, $00C596A8, $00C90F5E, $004F43A5,
$0071BD8B, $00F7F170, $00FB6886, $007D247D, $00E25B6A, $00641791, $00688E67, $00EEC29C,
$003347A4, $00B50B5F, $00B992A9, $003FDE52, $00A0A145, $0026EDBE, $002A7448, $00AC38B3,
$0092C69D, $00148A66, $00181390, $009E5F6B, $0001207C, $00876C87, $008BF571, $000DB98A,
$00F6092D, $007045D6, $007CDC20, $00FA90DB, $0065EFCC, $00E3A337, $00EF3AC1, $0069763A,
$00578814, $00D1C4EF, $00DD5D19, $005B11E2, $00C46EF5, $0042220E, $004EBBF8, $00C8F703,
$003F964D, $00B9DAB6, $00B54340, $00330FBB, $00AC70AC, $002A3C57, $0026A5A1, $00A0E95A,
$009E1774, $00185B8F, $0014C279, $00928E82, $000DF195, $008BBD6E, $00872498, $00016863,
$00FAD8C4, $007C943F, $00700DC9, $00F64132, $00693E25, $00EF72DE, $00E3EB28, $0065A7D3,
$005B59FD, $00DD1506, $00D18CF0, $0057C00B, $00C8BF1C, $004EF3E7, $00426A11, $00C426EA,
$002AE476, $00ACA88D, $00A0317B, $00267D80, $00B90297, $003F4E6C, $0033D79A, $00B59B61,
$008B654F, $000D29B4, $0001B042, $0087FCB9, $001883AE, $009ECF55, $009256A3, $00141A58,
$00EFAAFF, $0069E604, $00657FF2, $00E33309, $007C4C1E, $00FA00E5, $00F69913, $0070D5E8,
$004E2BC6, $00C8673D, $00C4FECB, $0042B230, $00DDCD27, $005B81DC, $0057182A, $00D154D1,
$0026359F, $00A07964, $00ACE092, $002AAC69, $00B5D37E, $00339F85, $003F0673, $00B94A88,
$0087B4A6, $0001F85D, $000D61AB, $008B2D50, $00145247, $00921EBC, $009E874A, $0018CBB1,
$00E37B16, $006537ED, $0069AE1B, $00EFE2E0, $00709DF7, $00F6D10C, $00FA48FA, $007C0401,
$0042FA2F, $00C4B6D4, $00C82F22, $004E63D9, $00D11CCE, $00575035, $005BC9C3, $00DD8538
);
constructor THasherCRC24_OPENPGP.Create;
begin
inherited Create;
FHash := $B704CE;
Check := '21CF02';
end;
procedure THasherCRC24_OPENPGP.Update(Msg: PByte; Length: Integer);
var i: Integer;
Index: Cardinal;
begin
for i:=0 to Length-1 do begin
Index := (Msg^ xor (FHash shr 16)) and $FF;
FHash := (FHash shl 8) xor Table[index];
Inc(Msg);
end;
end;
function THasherCRC24_OPENPGP.Final: String;
begin
FHash := FHash and $FFFFFF;
Result := IntToHex(FHash, 6);
end;
initialization
HasherList.RegisterHasher('CRC-24 OPENPGP', THasherCRC24_OPENPGP);
end.