-
Notifications
You must be signed in to change notification settings - Fork 3
/
CRC24_BLE.pas
85 lines (73 loc) · 3.79 KB
/
CRC24_BLE.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_BLE;
//CRC-24 BLE
//Author: domasz
//Last Update: 2022-11-22
//Licence: MIT
interface
uses SysUtils, HasherBase;
type THasherCRC24_BLE = 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, $0001B4C0, $00036980, $0002DD40, $0006D300, $000767C0, $0005BA80, $00040E40,
$000DA600, $000C12C0, $000ECF80, $000F7B40, $000B7500, $000AC1C0, $00081C80, $0009A840,
$001B4C00, $001AF8C0, $00182580, $00199140, $001D9F00, $001C2BC0, $001EF680, $001F4240,
$0016EA00, $00175EC0, $00158380, $00143740, $00103900, $00118DC0, $00135080, $0012E440,
$00369800, $00372CC0, $0035F180, $00344540, $00304B00, $0031FFC0, $00332280, $00329640,
$003B3E00, $003A8AC0, $00385780, $0039E340, $003DED00, $003C59C0, $003E8480, $003F3040,
$002DD400, $002C60C0, $002EBD80, $002F0940, $002B0700, $002AB3C0, $00286E80, $0029DA40,
$00207200, $0021C6C0, $00231B80, $0022AF40, $0026A100, $002715C0, $0025C880, $00247C40,
$006D3000, $006C84C0, $006E5980, $006FED40, $006BE300, $006A57C0, $00688A80, $00693E40,
$00609600, $006122C0, $0063FF80, $00624B40, $00664500, $0067F1C0, $00652C80, $00649840,
$00767C00, $0077C8C0, $00751580, $0074A140, $0070AF00, $00711BC0, $0073C680, $00727240,
$007BDA00, $007A6EC0, $0078B380, $00790740, $007D0900, $007CBDC0, $007E6080, $007FD440,
$005BA800, $005A1CC0, $0058C180, $00597540, $005D7B00, $005CCFC0, $005E1280, $005FA640,
$00560E00, $0057BAC0, $00556780, $0054D340, $0050DD00, $005169C0, $0053B480, $00520040,
$0040E400, $004150C0, $00438D80, $00423940, $00463700, $004783C0, $00455E80, $0044EA40,
$004D4200, $004CF6C0, $004E2B80, $004F9F40, $004B9100, $004A25C0, $0048F880, $00494C40,
$00DA6000, $00DBD4C0, $00D90980, $00D8BD40, $00DCB300, $00DD07C0, $00DFDA80, $00DE6E40,
$00D7C600, $00D672C0, $00D4AF80, $00D51B40, $00D11500, $00D0A1C0, $00D27C80, $00D3C840,
$00C12C00, $00C098C0, $00C24580, $00C3F140, $00C7FF00, $00C64BC0, $00C49680, $00C52240,
$00CC8A00, $00CD3EC0, $00CFE380, $00CE5740, $00CA5900, $00CBEDC0, $00C93080, $00C88440,
$00ECF800, $00ED4CC0, $00EF9180, $00EE2540, $00EA2B00, $00EB9FC0, $00E94280, $00E8F640,
$00E15E00, $00E0EAC0, $00E23780, $00E38340, $00E78D00, $00E639C0, $00E4E480, $00E55040,
$00F7B400, $00F600C0, $00F4DD80, $00F56940, $00F16700, $00F0D3C0, $00F20E80, $00F3BA40,
$00FA1200, $00FBA6C0, $00F97B80, $00F8CF40, $00FCC100, $00FD75C0, $00FFA880, $00FE1C40,
$00B75000, $00B6E4C0, $00B43980, $00B58D40, $00B18300, $00B037C0, $00B2EA80, $00B35E40,
$00BAF600, $00BB42C0, $00B99F80, $00B82B40, $00BC2500, $00BD91C0, $00BF4C80, $00BEF840,
$00AC1C00, $00ADA8C0, $00AF7580, $00AEC140, $00AACF00, $00AB7BC0, $00A9A680, $00A81240,
$00A1BA00, $00A00EC0, $00A2D380, $00A36740, $00A76900, $00A6DDC0, $00A40080, $00A5B440,
$0081C800, $00807CC0, $0082A180, $00831540, $00871B00, $0086AFC0, $00847280, $0085C640,
$008C6E00, $008DDAC0, $008F0780, $008EB340, $008ABD00, $008B09C0, $0089D480, $00886040,
$009A8400, $009B30C0, $0099ED80, $00985940, $009C5700, $009DE3C0, $009F3E80, $009E8A40,
$00972200, $009696C0, $00944B80, $0095FF40, $0091F100, $009045C0, $00929880, $00932C40
);
constructor THasherCRC24_BLE.Create;
begin
inherited Create;
Check := 'C25A56';
FHash := $AAAAAA;
end;
procedure THasherCRC24_BLE.Update(Msg: PByte; Length: Integer);
var i: Integer;
Index: Cardinal;
begin
for i:=0 to Length-1 do begin
FHash := (FHash shr 8) xor Table[byte(FHash) xor Msg^];
Inc(Msg);
end;
end;
function THasherCRC24_BLE.Final: String;
begin
FHash := FHash and $FFFFFF;
Result := IntToHex(FHash, 6);
end;
initialization
HasherList.RegisterHasher('CRC-24 BLE', THasherCRC24_BLE);
end.