-
Notifications
You must be signed in to change notification settings - Fork 4
/
CRC24_FLEXRAYB.pas
85 lines (74 loc) · 3.87 KB
/
CRC24_FLEXRAYB.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_FLEXRAYB;
//CRC-24 FLEXRAY-B
//Author: domasz
//Version: 0.1 (2022-11-17)
//Licence: MIT
interface
uses SysUtils, HasherBase;
type THasherCRC24_FLEXRAYB = 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, $005D6DCB, $00BADB96, $00E7B65D, $0028DAE7, $0075B72C, $00920171, $00CF6CBA,
$0051B5CE, $000CD805, $00EB6E58, $00B60393, $00796F29, $002402E2, $00C3B4BF, $009ED974,
$00A36B9C, $00FE0657, $0019B00A, $0044DDC1, $008BB17B, $00D6DCB0, $00316AED, $006C0726,
$00F2DE52, $00AFB399, $004805C4, $0015680F, $00DA04B5, $0087697E, $0060DF23, $003DB2E8,
$001BBAF3, $0046D738, $00A16165, $00FC0CAE, $00336014, $006E0DDF, $0089BB82, $00D4D649,
$004A0F3D, $001762F6, $00F0D4AB, $00ADB960, $0062D5DA, $003FB811, $00D80E4C, $00856387,
$00B8D16F, $00E5BCA4, $00020AF9, $005F6732, $00900B88, $00CD6643, $002AD01E, $0077BDD5,
$00E964A1, $00B4096A, $0053BF37, $000ED2FC, $00C1BE46, $009CD38D, $007B65D0, $0026081B,
$003775E6, $006A182D, $008DAE70, $00D0C3BB, $001FAF01, $0042C2CA, $00A57497, $00F8195C,
$0066C028, $003BADE3, $00DC1BBE, $00817675, $004E1ACF, $00137704, $00F4C159, $00A9AC92,
$00941E7A, $00C973B1, $002EC5EC, $0073A827, $00BCC49D, $00E1A956, $00061F0B, $005B72C0,
$00C5ABB4, $0098C67F, $007F7022, $00221DE9, $00ED7153, $00B01C98, $0057AAC5, $000AC70E,
$002CCF15, $0071A2DE, $00961483, $00CB7948, $000415F2, $00597839, $00BECE64, $00E3A3AF,
$007D7ADB, $00201710, $00C7A14D, $009ACC86, $0055A03C, $0008CDF7, $00EF7BAA, $00B21661,
$008FA489, $00D2C942, $00357F1F, $006812D4, $00A77E6E, $00FA13A5, $001DA5F8, $0040C833,
$00DE1147, $00837C8C, $0064CAD1, $0039A71A, $00F6CBA0, $00ABA66B, $004C1036, $00117DFD,
$006EEBCC, $00338607, $00D4305A, $00895D91, $0046312B, $001B5CE0, $00FCEABD, $00A18776,
$003F5E02, $006233C9, $00858594, $00D8E85F, $001784E5, $004AE92E, $00AD5F73, $00F032B8,
$00CD8050, $0090ED9B, $00775BC6, $002A360D, $00E55AB7, $00B8377C, $005F8121, $0002ECEA,
$009C359E, $00C15855, $0026EE08, $007B83C3, $00B4EF79, $00E982B2, $000E34EF, $00535924,
$0075513F, $00283CF4, $00CF8AA9, $0092E762, $005D8BD8, $0000E613, $00E7504E, $00BA3D85,
$0024E4F1, $0079893A, $009E3F67, $00C352AC, $000C3E16, $005153DD, $00B6E580, $00EB884B,
$00D63AA3, $008B5768, $006CE135, $00318CFE, $00FEE044, $00A38D8F, $00443BD2, $00195619,
$00878F6D, $00DAE2A6, $003D54FB, $00603930, $00AF558A, $00F23841, $00158E1C, $0048E3D7,
$00599E2A, $0004F3E1, $00E345BC, $00BE2877, $007144CD, $002C2906, $00CB9F5B, $0096F290,
$00082BE4, $0055462F, $00B2F072, $00EF9DB9, $0020F103, $007D9CC8, $009A2A95, $00C7475E,
$00FAF5B6, $00A7987D, $00402E20, $001D43EB, $00D22F51, $008F429A, $0068F4C7, $0035990C,
$00AB4078, $00F62DB3, $00119BEE, $004CF625, $00839A9F, $00DEF754, $00394109, $00642CC2,
$004224D9, $001F4912, $00F8FF4F, $00A59284, $006AFE3E, $003793F5, $00D025A8, $008D4863,
$00139117, $004EFCDC, $00A94A81, $00F4274A, $003B4BF0, $0066263B, $00819066, $00DCFDAD,
$00E14F45, $00BC228E, $005B94D3, $0006F918, $00C995A2, $0094F869, $00734E34, $002E23FF,
$00B0FA8B, $00ED9740, $000A211D, $00574CD6, $0098206C, $00C54DA7, $0022FBFA, $007F9631
);
constructor THasherCRC24_FLEXRAYB.Create;
begin
inherited Create;
FHash := $ABCDEF;
Check := '1F23B8';
end;
procedure THasherCRC24_FLEXRAYB.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_FLEXRAYB.Final: String;
begin
FHash := FHash and $FFFFFF;
Result := IntToHex(FHash, 6);
end;
initialization
HasherList.RegisterHasher('CRC-24 FLEXRAY-B', THasherCRC24_FLEXRAYB);
end.