diff --git a/CRC8_CDMA2000.pas b/CRC8_CDMA2000.pas new file mode 100644 index 0000000..36ba047 --- /dev/null +++ b/CRC8_CDMA2000.pas @@ -0,0 +1,82 @@ +unit CRC8_CDMA2000; +//CRC-8 CDMA2000 +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_CDMA2000 = 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, $9B, $AD, $36, $C1, $5A, $6C, $F7, +$19, $82, $B4, $2F, $D8, $43, $75, $EE, +$32, $A9, $9F, $04, $F3, $68, $5E, $C5, +$2B, $B0, $86, $1D, $EA, $71, $47, $DC, +$64, $FF, $C9, $52, $A5, $3E, $08, $93, +$7D, $E6, $D0, $4B, $BC, $27, $11, $8A, +$56, $CD, $FB, $60, $97, $0C, $3A, $A1, +$4F, $D4, $E2, $79, $8E, $15, $23, $B8, +$C8, $53, $65, $FE, $09, $92, $A4, $3F, +$D1, $4A, $7C, $E7, $10, $8B, $BD, $26, +$FA, $61, $57, $CC, $3B, $A0, $96, $0D, +$E3, $78, $4E, $D5, $22, $B9, $8F, $14, +$AC, $37, $01, $9A, $6D, $F6, $C0, $5B, +$B5, $2E, $18, $83, $74, $EF, $D9, $42, +$9E, $05, $33, $A8, $5F, $C4, $F2, $69, +$87, $1C, $2A, $B1, $46, $DD, $EB, $70, +$0B, $90, $A6, $3D, $CA, $51, $67, $FC, +$12, $89, $BF, $24, $D3, $48, $7E, $E5, +$39, $A2, $94, $0F, $F8, $63, $55, $CE, +$20, $BB, $8D, $16, $E1, $7A, $4C, $D7, +$6F, $F4, $C2, $59, $AE, $35, $03, $98, +$76, $ED, $DB, $40, $B7, $2C, $1A, $81, +$5D, $C6, $F0, $6B, $9C, $07, $31, $AA, +$44, $DF, $E9, $72, $85, $1E, $28, $B3, +$C3, $58, $6E, $F5, $02, $99, $AF, $34, +$DA, $41, $77, $EC, $1B, $80, $B6, $2D, +$F1, $6A, $5C, $C7, $30, $AB, $9D, $06, +$E8, $73, $45, $DE, $29, $B2, $84, $1F, +$A7, $3C, $0A, $91, $66, $FD, $CB, $50, +$BE, $25, $13, $88, $7F, $E4, $D2, $49, +$95, $0E, $38, $A3, $54, $CF, $F9, $62, +$8C, $17, $21, $BA, $4D, $D6, $E0, $7B +); + +constructor THasherCRC8_CDMA2000.Create; +begin + inherited Create; + FHash := $FF; + Check := 'DA'; +end; + +procedure THasherCRC8_CDMA2000.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_CDMA2000.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 CDMA2000', THasherCRC8_CDMA2000); + +end. diff --git a/CRC8_DARC.pas b/CRC8_DARC.pas new file mode 100644 index 0000000..1e9338f --- /dev/null +++ b/CRC8_DARC.pas @@ -0,0 +1,82 @@ +unit CRC8_DARC; +//CRC-8 DARC +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_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, $72, $E4, $96, $F1, $83, $15, $67, +$DB, $A9, $3F, $4D, $2A, $58, $CE, $BC, +$8F, $FD, $6B, $19, $7E, $0C, $9A, $E8, +$54, $26, $B0, $C2, $A5, $D7, $41, $33, +$27, $55, $C3, $B1, $D6, $A4, $32, $40, +$FC, $8E, $18, $6A, $0D, $7F, $E9, $9B, +$A8, $DA, $4C, $3E, $59, $2B, $BD, $CF, +$73, $01, $97, $E5, $82, $F0, $66, $14, +$4E, $3C, $AA, $D8, $BF, $CD, $5B, $29, +$95, $E7, $71, $03, $64, $16, $80, $F2, +$C1, $B3, $25, $57, $30, $42, $D4, $A6, +$1A, $68, $FE, $8C, $EB, $99, $0F, $7D, +$69, $1B, $8D, $FF, $98, $EA, $7C, $0E, +$B2, $C0, $56, $24, $43, $31, $A7, $D5, +$E6, $94, $02, $70, $17, $65, $F3, $81, +$3D, $4F, $D9, $AB, $CC, $BE, $28, $5A, +$9C, $EE, $78, $0A, $6D, $1F, $89, $FB, +$47, $35, $A3, $D1, $B6, $C4, $52, $20, +$13, $61, $F7, $85, $E2, $90, $06, $74, +$C8, $BA, $2C, $5E, $39, $4B, $DD, $AF, +$BB, $C9, $5F, $2D, $4A, $38, $AE, $DC, +$60, $12, $84, $F6, $91, $E3, $75, $07, +$34, $46, $D0, $A2, $C5, $B7, $21, $53, +$EF, $9D, $0B, $79, $1E, $6C, $FA, $88, +$D2, $A0, $36, $44, $23, $51, $C7, $B5, +$09, $7B, $ED, $9F, $F8, $8A, $1C, $6E, +$5D, $2F, $B9, $CB, $AC, $DE, $48, $3A, +$86, $F4, $62, $10, $77, $05, $93, $E1, +$F5, $87, $11, $63, $04, $76, $E0, $92, +$2E, $5C, $CA, $B8, $DF, $AD, $3B, $49, +$7A, $08, $9E, $EC, $8B, $F9, $6F, $1D, +$A1, $D3, $45, $37, $50, $22, $B4, $C6 +); + +constructor THasherCRC8_DARC.Create; +begin + inherited Create; + FHash := $00; + Check := '15'; +end; + +procedure THasherCRC8_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 THasherCRC8_DARC.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 DARC', THasherCRC8_DARC); + +end. diff --git a/CRC8_DVBS2.pas b/CRC8_DVBS2.pas new file mode 100644 index 0000000..00a86b2 --- /dev/null +++ b/CRC8_DVBS2.pas @@ -0,0 +1,82 @@ +unit CRC8_DVBS2; +//CRC-8 DVB-S2 +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_DVBS2 = 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, $D5, $7F, $AA, $FE, $2B, $81, $54, +$29, $FC, $56, $83, $D7, $02, $A8, $7D, +$52, $87, $2D, $F8, $AC, $79, $D3, $06, +$7B, $AE, $04, $D1, $85, $50, $FA, $2F, +$A4, $71, $DB, $0E, $5A, $8F, $25, $F0, +$8D, $58, $F2, $27, $73, $A6, $0C, $D9, +$F6, $23, $89, $5C, $08, $DD, $77, $A2, +$DF, $0A, $A0, $75, $21, $F4, $5E, $8B, +$9D, $48, $E2, $37, $63, $B6, $1C, $C9, +$B4, $61, $CB, $1E, $4A, $9F, $35, $E0, +$CF, $1A, $B0, $65, $31, $E4, $4E, $9B, +$E6, $33, $99, $4C, $18, $CD, $67, $B2, +$39, $EC, $46, $93, $C7, $12, $B8, $6D, +$10, $C5, $6F, $BA, $EE, $3B, $91, $44, +$6B, $BE, $14, $C1, $95, $40, $EA, $3F, +$42, $97, $3D, $E8, $BC, $69, $C3, $16, +$EF, $3A, $90, $45, $11, $C4, $6E, $BB, +$C6, $13, $B9, $6C, $38, $ED, $47, $92, +$BD, $68, $C2, $17, $43, $96, $3C, $E9, +$94, $41, $EB, $3E, $6A, $BF, $15, $C0, +$4B, $9E, $34, $E1, $B5, $60, $CA, $1F, +$62, $B7, $1D, $C8, $9C, $49, $E3, $36, +$19, $CC, $66, $B3, $E7, $32, $98, $4D, +$30, $E5, $4F, $9A, $CE, $1B, $B1, $64, +$72, $A7, $0D, $D8, $8C, $59, $F3, $26, +$5B, $8E, $24, $F1, $A5, $70, $DA, $0F, +$20, $F5, $5F, $8A, $DE, $0B, $A1, $74, +$09, $DC, $76, $A3, $F7, $22, $88, $5D, +$D6, $03, $A9, $7C, $28, $FD, $57, $82, +$FF, $2A, $80, $55, $01, $D4, $7E, $AB, +$84, $51, $FB, $2E, $7A, $AF, $05, $D0, +$AD, $78, $D2, $07, $53, $86, $2C, $F9 +); + +constructor THasherCRC8_DVBS2.Create; +begin + inherited Create; + FHash := $00; + Check := 'BC'; +end; + +procedure THasherCRC8_DVBS2.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_DVBS2.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 DVB-S2', THasherCRC8_DVBS2); + +end. diff --git a/CRC8_GSMA.pas b/CRC8_GSMA.pas new file mode 100644 index 0000000..0ba90a3 --- /dev/null +++ b/CRC8_GSMA.pas @@ -0,0 +1,82 @@ +unit CRC8_GSMA; +//CRC-8 GSM-A +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_GSMA = 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, $1D, $3A, $27, $74, $69, $4E, $53, +$E8, $F5, $D2, $CF, $9C, $81, $A6, $BB, +$CD, $D0, $F7, $EA, $B9, $A4, $83, $9E, +$25, $38, $1F, $02, $51, $4C, $6B, $76, +$87, $9A, $BD, $A0, $F3, $EE, $C9, $D4, +$6F, $72, $55, $48, $1B, $06, $21, $3C, +$4A, $57, $70, $6D, $3E, $23, $04, $19, +$A2, $BF, $98, $85, $D6, $CB, $EC, $F1, +$13, $0E, $29, $34, $67, $7A, $5D, $40, +$FB, $E6, $C1, $DC, $8F, $92, $B5, $A8, +$DE, $C3, $E4, $F9, $AA, $B7, $90, $8D, +$36, $2B, $0C, $11, $42, $5F, $78, $65, +$94, $89, $AE, $B3, $E0, $FD, $DA, $C7, +$7C, $61, $46, $5B, $08, $15, $32, $2F, +$59, $44, $63, $7E, $2D, $30, $17, $0A, +$B1, $AC, $8B, $96, $C5, $D8, $FF, $E2, +$26, $3B, $1C, $01, $52, $4F, $68, $75, +$CE, $D3, $F4, $E9, $BA, $A7, $80, $9D, +$EB, $F6, $D1, $CC, $9F, $82, $A5, $B8, +$03, $1E, $39, $24, $77, $6A, $4D, $50, +$A1, $BC, $9B, $86, $D5, $C8, $EF, $F2, +$49, $54, $73, $6E, $3D, $20, $07, $1A, +$6C, $71, $56, $4B, $18, $05, $22, $3F, +$84, $99, $BE, $A3, $F0, $ED, $CA, $D7, +$35, $28, $0F, $12, $41, $5C, $7B, $66, +$DD, $C0, $E7, $FA, $A9, $B4, $93, $8E, +$F8, $E5, $C2, $DF, $8C, $91, $B6, $AB, +$10, $0D, $2A, $37, $64, $79, $5E, $43, +$B2, $AF, $88, $95, $C6, $DB, $FC, $E1, +$5A, $47, $60, $7D, $2E, $33, $14, $09, +$7F, $62, $45, $58, $0B, $16, $31, $2C, +$97, $8A, $AD, $B0, $E3, $FE, $D9, $C4 +); + +constructor THasherCRC8_GSMA.Create; +begin + inherited Create; + FHash := $00; + Check := '37'; +end; + +procedure THasherCRC8_GSMA.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_GSMA.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 GSM-A', THasherCRC8_GSMA); + +end. diff --git a/CRC8_GSMB.pas b/CRC8_GSMB.pas new file mode 100644 index 0000000..0d27662 --- /dev/null +++ b/CRC8_GSMB.pas @@ -0,0 +1,82 @@ +unit CRC8_GSMB; +//CRC-8 GSM-B +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_GSMB = 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, $49, $92, $DB, $6D, $24, $FF, $B6, +$DA, $93, $48, $01, $B7, $FE, $25, $6C, +$FD, $B4, $6F, $26, $90, $D9, $02, $4B, +$27, $6E, $B5, $FC, $4A, $03, $D8, $91, +$B3, $FA, $21, $68, $DE, $97, $4C, $05, +$69, $20, $FB, $B2, $04, $4D, $96, $DF, +$4E, $07, $DC, $95, $23, $6A, $B1, $F8, +$94, $DD, $06, $4F, $F9, $B0, $6B, $22, +$2F, $66, $BD, $F4, $42, $0B, $D0, $99, +$F5, $BC, $67, $2E, $98, $D1, $0A, $43, +$D2, $9B, $40, $09, $BF, $F6, $2D, $64, +$08, $41, $9A, $D3, $65, $2C, $F7, $BE, +$9C, $D5, $0E, $47, $F1, $B8, $63, $2A, +$46, $0F, $D4, $9D, $2B, $62, $B9, $F0, +$61, $28, $F3, $BA, $0C, $45, $9E, $D7, +$BB, $F2, $29, $60, $D6, $9F, $44, $0D, +$5E, $17, $CC, $85, $33, $7A, $A1, $E8, +$84, $CD, $16, $5F, $E9, $A0, $7B, $32, +$A3, $EA, $31, $78, $CE, $87, $5C, $15, +$79, $30, $EB, $A2, $14, $5D, $86, $CF, +$ED, $A4, $7F, $36, $80, $C9, $12, $5B, +$37, $7E, $A5, $EC, $5A, $13, $C8, $81, +$10, $59, $82, $CB, $7D, $34, $EF, $A6, +$CA, $83, $58, $11, $A7, $EE, $35, $7C, +$71, $38, $E3, $AA, $1C, $55, $8E, $C7, +$AB, $E2, $39, $70, $C6, $8F, $54, $1D, +$8C, $C5, $1E, $57, $E1, $A8, $73, $3A, +$56, $1F, $C4, $8D, $3B, $72, $A9, $E0, +$C2, $8B, $50, $19, $AF, $E6, $3D, $74, +$18, $51, $8A, $C3, $75, $3C, $E7, $AE, +$3F, $76, $AD, $E4, $52, $1B, $C0, $89, +$E5, $AC, $77, $3E, $88, $C1, $1A, $53 +); + +constructor THasherCRC8_GSMB.Create; +begin + inherited Create; + FHash := $00; + Check := '94'; +end; + +procedure THasherCRC8_GSMB.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_GSMB.Final: String; +begin + FHash := FHash xor $FF; + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 GSM-B', THasherCRC8_GSMB); + +end. diff --git a/CRC8_HITAG.pas b/CRC8_HITAG.pas new file mode 100644 index 0000000..78487e3 --- /dev/null +++ b/CRC8_HITAG.pas @@ -0,0 +1,82 @@ +unit CRC8_HITAG; +//CRC-8 HITAG +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_HITAG = 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, $1D, $3A, $27, $74, $69, $4E, $53, +$E8, $F5, $D2, $CF, $9C, $81, $A6, $BB, +$CD, $D0, $F7, $EA, $B9, $A4, $83, $9E, +$25, $38, $1F, $02, $51, $4C, $6B, $76, +$87, $9A, $BD, $A0, $F3, $EE, $C9, $D4, +$6F, $72, $55, $48, $1B, $06, $21, $3C, +$4A, $57, $70, $6D, $3E, $23, $04, $19, +$A2, $BF, $98, $85, $D6, $CB, $EC, $F1, +$13, $0E, $29, $34, $67, $7A, $5D, $40, +$FB, $E6, $C1, $DC, $8F, $92, $B5, $A8, +$DE, $C3, $E4, $F9, $AA, $B7, $90, $8D, +$36, $2B, $0C, $11, $42, $5F, $78, $65, +$94, $89, $AE, $B3, $E0, $FD, $DA, $C7, +$7C, $61, $46, $5B, $08, $15, $32, $2F, +$59, $44, $63, $7E, $2D, $30, $17, $0A, +$B1, $AC, $8B, $96, $C5, $D8, $FF, $E2, +$26, $3B, $1C, $01, $52, $4F, $68, $75, +$CE, $D3, $F4, $E9, $BA, $A7, $80, $9D, +$EB, $F6, $D1, $CC, $9F, $82, $A5, $B8, +$03, $1E, $39, $24, $77, $6A, $4D, $50, +$A1, $BC, $9B, $86, $D5, $C8, $EF, $F2, +$49, $54, $73, $6E, $3D, $20, $07, $1A, +$6C, $71, $56, $4B, $18, $05, $22, $3F, +$84, $99, $BE, $A3, $F0, $ED, $CA, $D7, +$35, $28, $0F, $12, $41, $5C, $7B, $66, +$DD, $C0, $E7, $FA, $A9, $B4, $93, $8E, +$F8, $E5, $C2, $DF, $8C, $91, $B6, $AB, +$10, $0D, $2A, $37, $64, $79, $5E, $43, +$B2, $AF, $88, $95, $C6, $DB, $FC, $E1, +$5A, $47, $60, $7D, $2E, $33, $14, $09, +$7F, $62, $45, $58, $0B, $16, $31, $2C, +$97, $8A, $AD, $B0, $E3, $FE, $D9, $C4 +); + +constructor THasherCRC8_HITAG.Create; +begin + inherited Create; + FHash := $FF; + Check := 'B4'; +end; + +procedure THasherCRC8_HITAG.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_HITAG.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 HITAG', THasherCRC8_HITAG); + +end. diff --git a/CRC8_I4321.pas b/CRC8_I4321.pas new file mode 100644 index 0000000..9ce1de5 --- /dev/null +++ b/CRC8_I4321.pas @@ -0,0 +1,82 @@ +unit CRC8_I4321; +//CRC-8 I-432-1 +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_I4321 = 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, $07, $0E, $09, $1C, $1B, $12, $15, +$38, $3F, $36, $31, $24, $23, $2A, $2D, +$70, $77, $7E, $79, $6C, $6B, $62, $65, +$48, $4F, $46, $41, $54, $53, $5A, $5D, +$E0, $E7, $EE, $E9, $FC, $FB, $F2, $F5, +$D8, $DF, $D6, $D1, $C4, $C3, $CA, $CD, +$90, $97, $9E, $99, $8C, $8B, $82, $85, +$A8, $AF, $A6, $A1, $B4, $B3, $BA, $BD, +$C7, $C0, $C9, $CE, $DB, $DC, $D5, $D2, +$FF, $F8, $F1, $F6, $E3, $E4, $ED, $EA, +$B7, $B0, $B9, $BE, $AB, $AC, $A5, $A2, +$8F, $88, $81, $86, $93, $94, $9D, $9A, +$27, $20, $29, $2E, $3B, $3C, $35, $32, +$1F, $18, $11, $16, $03, $04, $0D, $0A, +$57, $50, $59, $5E, $4B, $4C, $45, $42, +$6F, $68, $61, $66, $73, $74, $7D, $7A, +$89, $8E, $87, $80, $95, $92, $9B, $9C, +$B1, $B6, $BF, $B8, $AD, $AA, $A3, $A4, +$F9, $FE, $F7, $F0, $E5, $E2, $EB, $EC, +$C1, $C6, $CF, $C8, $DD, $DA, $D3, $D4, +$69, $6E, $67, $60, $75, $72, $7B, $7C, +$51, $56, $5F, $58, $4D, $4A, $43, $44, +$19, $1E, $17, $10, $05, $02, $0B, $0C, +$21, $26, $2F, $28, $3D, $3A, $33, $34, +$4E, $49, $40, $47, $52, $55, $5C, $5B, +$76, $71, $78, $7F, $6A, $6D, $64, $63, +$3E, $39, $30, $37, $22, $25, $2C, $2B, +$06, $01, $08, $0F, $1A, $1D, $14, $13, +$AE, $A9, $A0, $A7, $B2, $B5, $BC, $BB, +$96, $91, $98, $9F, $8A, $8D, $84, $83, +$DE, $D9, $D0, $D7, $C2, $C5, $CC, $CB, +$E6, $E1, $E8, $EF, $FA, $FD, $F4, $F3 +); + +constructor THasherCRC8_I4321.Create; +begin + inherited Create; + FHash := $00; + Check := 'A1'; +end; + +procedure THasherCRC8_I4321.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_I4321.Final: String; +begin + FHash := FHash xor $55; + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 I-432-1', THasherCRC8_I4321); + +end. diff --git a/CRC8_ICODE.pas b/CRC8_ICODE.pas new file mode 100644 index 0000000..f062d8f --- /dev/null +++ b/CRC8_ICODE.pas @@ -0,0 +1,82 @@ +unit CRC8_ICODE; +//CRC-8 I-CODE +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_ICODE = 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, $1D, $3A, $27, $74, $69, $4E, $53, +$E8, $F5, $D2, $CF, $9C, $81, $A6, $BB, +$CD, $D0, $F7, $EA, $B9, $A4, $83, $9E, +$25, $38, $1F, $02, $51, $4C, $6B, $76, +$87, $9A, $BD, $A0, $F3, $EE, $C9, $D4, +$6F, $72, $55, $48, $1B, $06, $21, $3C, +$4A, $57, $70, $6D, $3E, $23, $04, $19, +$A2, $BF, $98, $85, $D6, $CB, $EC, $F1, +$13, $0E, $29, $34, $67, $7A, $5D, $40, +$FB, $E6, $C1, $DC, $8F, $92, $B5, $A8, +$DE, $C3, $E4, $F9, $AA, $B7, $90, $8D, +$36, $2B, $0C, $11, $42, $5F, $78, $65, +$94, $89, $AE, $B3, $E0, $FD, $DA, $C7, +$7C, $61, $46, $5B, $08, $15, $32, $2F, +$59, $44, $63, $7E, $2D, $30, $17, $0A, +$B1, $AC, $8B, $96, $C5, $D8, $FF, $E2, +$26, $3B, $1C, $01, $52, $4F, $68, $75, +$CE, $D3, $F4, $E9, $BA, $A7, $80, $9D, +$EB, $F6, $D1, $CC, $9F, $82, $A5, $B8, +$03, $1E, $39, $24, $77, $6A, $4D, $50, +$A1, $BC, $9B, $86, $D5, $C8, $EF, $F2, +$49, $54, $73, $6E, $3D, $20, $07, $1A, +$6C, $71, $56, $4B, $18, $05, $22, $3F, +$84, $99, $BE, $A3, $F0, $ED, $CA, $D7, +$35, $28, $0F, $12, $41, $5C, $7B, $66, +$DD, $C0, $E7, $FA, $A9, $B4, $93, $8E, +$F8, $E5, $C2, $DF, $8C, $91, $B6, $AB, +$10, $0D, $2A, $37, $64, $79, $5E, $43, +$B2, $AF, $88, $95, $C6, $DB, $FC, $E1, +$5A, $47, $60, $7D, $2E, $33, $14, $09, +$7F, $62, $45, $58, $0B, $16, $31, $2C, +$97, $8A, $AD, $B0, $E3, $FE, $D9, $C4 +); + +constructor THasherCRC8_ICODE.Create; +begin + inherited Create; + FHash := $FD; + Check := '7E'; +end; + +procedure THasherCRC8_ICODE.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_ICODE.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 I-CODE', THasherCRC8_ICODE); + +end. diff --git a/CRC8_LTE.pas b/CRC8_LTE.pas new file mode 100644 index 0000000..96b7819 --- /dev/null +++ b/CRC8_LTE.pas @@ -0,0 +1,82 @@ +unit CRC8_LTE; +//CRC-8 LTE +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_LTE = 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, $9B, $AD, $36, $C1, $5A, $6C, $F7, +$19, $82, $B4, $2F, $D8, $43, $75, $EE, +$32, $A9, $9F, $04, $F3, $68, $5E, $C5, +$2B, $B0, $86, $1D, $EA, $71, $47, $DC, +$64, $FF, $C9, $52, $A5, $3E, $08, $93, +$7D, $E6, $D0, $4B, $BC, $27, $11, $8A, +$56, $CD, $FB, $60, $97, $0C, $3A, $A1, +$4F, $D4, $E2, $79, $8E, $15, $23, $B8, +$C8, $53, $65, $FE, $09, $92, $A4, $3F, +$D1, $4A, $7C, $E7, $10, $8B, $BD, $26, +$FA, $61, $57, $CC, $3B, $A0, $96, $0D, +$E3, $78, $4E, $D5, $22, $B9, $8F, $14, +$AC, $37, $01, $9A, $6D, $F6, $C0, $5B, +$B5, $2E, $18, $83, $74, $EF, $D9, $42, +$9E, $05, $33, $A8, $5F, $C4, $F2, $69, +$87, $1C, $2A, $B1, $46, $DD, $EB, $70, +$0B, $90, $A6, $3D, $CA, $51, $67, $FC, +$12, $89, $BF, $24, $D3, $48, $7E, $E5, +$39, $A2, $94, $0F, $F8, $63, $55, $CE, +$20, $BB, $8D, $16, $E1, $7A, $4C, $D7, +$6F, $F4, $C2, $59, $AE, $35, $03, $98, +$76, $ED, $DB, $40, $B7, $2C, $1A, $81, +$5D, $C6, $F0, $6B, $9C, $07, $31, $AA, +$44, $DF, $E9, $72, $85, $1E, $28, $B3, +$C3, $58, $6E, $F5, $02, $99, $AF, $34, +$DA, $41, $77, $EC, $1B, $80, $B6, $2D, +$F1, $6A, $5C, $C7, $30, $AB, $9D, $06, +$E8, $73, $45, $DE, $29, $B2, $84, $1F, +$A7, $3C, $0A, $91, $66, $FD, $CB, $50, +$BE, $25, $13, $88, $7F, $E4, $D2, $49, +$95, $0E, $38, $A3, $54, $CF, $F9, $62, +$8C, $17, $21, $BA, $4D, $D6, $E0, $7B +); + +constructor THasherCRC8_LTE.Create; +begin + inherited Create; + FHash := $00; + Check := 'EA'; +end; + +procedure THasherCRC8_LTE.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_LTE.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 LTE', THasherCRC8_LTE); + +end. diff --git a/CRC8_MAXIMDOW.pas b/CRC8_MAXIMDOW.pas new file mode 100644 index 0000000..4b5d302 --- /dev/null +++ b/CRC8_MAXIMDOW.pas @@ -0,0 +1,82 @@ +unit CRC8_MAXIMDOW; +//CRC-8 MAXIM-DOW +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_MAXIMDOW = 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, $5E, $BC, $E2, $61, $3F, $DD, $83, +$C2, $9C, $7E, $20, $A3, $FD, $1F, $41, +$9D, $C3, $21, $7F, $FC, $A2, $40, $1E, +$5F, $01, $E3, $BD, $3E, $60, $82, $DC, +$23, $7D, $9F, $C1, $42, $1C, $FE, $A0, +$E1, $BF, $5D, $03, $80, $DE, $3C, $62, +$BE, $E0, $02, $5C, $DF, $81, $63, $3D, +$7C, $22, $C0, $9E, $1D, $43, $A1, $FF, +$46, $18, $FA, $A4, $27, $79, $9B, $C5, +$84, $DA, $38, $66, $E5, $BB, $59, $07, +$DB, $85, $67, $39, $BA, $E4, $06, $58, +$19, $47, $A5, $FB, $78, $26, $C4, $9A, +$65, $3B, $D9, $87, $04, $5A, $B8, $E6, +$A7, $F9, $1B, $45, $C6, $98, $7A, $24, +$F8, $A6, $44, $1A, $99, $C7, $25, $7B, +$3A, $64, $86, $D8, $5B, $05, $E7, $B9, +$8C, $D2, $30, $6E, $ED, $B3, $51, $0F, +$4E, $10, $F2, $AC, $2F, $71, $93, $CD, +$11, $4F, $AD, $F3, $70, $2E, $CC, $92, +$D3, $8D, $6F, $31, $B2, $EC, $0E, $50, +$AF, $F1, $13, $4D, $CE, $90, $72, $2C, +$6D, $33, $D1, $8F, $0C, $52, $B0, $EE, +$32, $6C, $8E, $D0, $53, $0D, $EF, $B1, +$F0, $AE, $4C, $12, $91, $CF, $2D, $73, +$CA, $94, $76, $28, $AB, $F5, $17, $49, +$08, $56, $B4, $EA, $69, $37, $D5, $8B, +$57, $09, $EB, $B5, $36, $68, $8A, $D4, +$95, $CB, $29, $77, $F4, $AA, $48, $16, +$E9, $B7, $55, $0B, $88, $D6, $34, $6A, +$2B, $75, $97, $C9, $4A, $14, $F6, $A8, +$74, $2A, $C8, $96, $15, $4B, $A9, $F7, +$B6, $E8, $0A, $54, $D7, $89, $6B, $35 +); + +constructor THasherCRC8_MAXIMDOW.Create; +begin + inherited Create; + FHash := $00; + Check := 'A1'; +end; + +procedure THasherCRC8_MAXIMDOW.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 THasherCRC8_MAXIMDOW.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 MAXIM-DOW', THasherCRC8_MAXIMDOW); + +end. diff --git a/CRC8_MIFAREMAD.pas b/CRC8_MIFAREMAD.pas new file mode 100644 index 0000000..f1068e2 --- /dev/null +++ b/CRC8_MIFAREMAD.pas @@ -0,0 +1,82 @@ +unit CRC8_MIFAREMAD; +//CRC-8 MIFARE-MAD +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_MIFAREMAD = 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, $1D, $3A, $27, $74, $69, $4E, $53, +$E8, $F5, $D2, $CF, $9C, $81, $A6, $BB, +$CD, $D0, $F7, $EA, $B9, $A4, $83, $9E, +$25, $38, $1F, $02, $51, $4C, $6B, $76, +$87, $9A, $BD, $A0, $F3, $EE, $C9, $D4, +$6F, $72, $55, $48, $1B, $06, $21, $3C, +$4A, $57, $70, $6D, $3E, $23, $04, $19, +$A2, $BF, $98, $85, $D6, $CB, $EC, $F1, +$13, $0E, $29, $34, $67, $7A, $5D, $40, +$FB, $E6, $C1, $DC, $8F, $92, $B5, $A8, +$DE, $C3, $E4, $F9, $AA, $B7, $90, $8D, +$36, $2B, $0C, $11, $42, $5F, $78, $65, +$94, $89, $AE, $B3, $E0, $FD, $DA, $C7, +$7C, $61, $46, $5B, $08, $15, $32, $2F, +$59, $44, $63, $7E, $2D, $30, $17, $0A, +$B1, $AC, $8B, $96, $C5, $D8, $FF, $E2, +$26, $3B, $1C, $01, $52, $4F, $68, $75, +$CE, $D3, $F4, $E9, $BA, $A7, $80, $9D, +$EB, $F6, $D1, $CC, $9F, $82, $A5, $B8, +$03, $1E, $39, $24, $77, $6A, $4D, $50, +$A1, $BC, $9B, $86, $D5, $C8, $EF, $F2, +$49, $54, $73, $6E, $3D, $20, $07, $1A, +$6C, $71, $56, $4B, $18, $05, $22, $3F, +$84, $99, $BE, $A3, $F0, $ED, $CA, $D7, +$35, $28, $0F, $12, $41, $5C, $7B, $66, +$DD, $C0, $E7, $FA, $A9, $B4, $93, $8E, +$F8, $E5, $C2, $DF, $8C, $91, $B6, $AB, +$10, $0D, $2A, $37, $64, $79, $5E, $43, +$B2, $AF, $88, $95, $C6, $DB, $FC, $E1, +$5A, $47, $60, $7D, $2E, $33, $14, $09, +$7F, $62, $45, $58, $0B, $16, $31, $2C, +$97, $8A, $AD, $B0, $E3, $FE, $D9, $C4 +); + +constructor THasherCRC8_MIFAREMAD.Create; +begin + inherited Create; + FHash := $C7; + Check := '99'; +end; + +procedure THasherCRC8_MIFAREMAD.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_MIFAREMAD.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 MIFARE-MAD', THasherCRC8_MIFAREMAD); + +end. diff --git a/CRC8_NRSC5.pas b/CRC8_NRSC5.pas new file mode 100644 index 0000000..eee62be --- /dev/null +++ b/CRC8_NRSC5.pas @@ -0,0 +1,82 @@ +unit CRC8_NRSC5; +//CRC-8 NRSC-5 +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_NRSC5 = 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, $31, $62, $53, $C4, $F5, $A6, $97, +$B9, $88, $DB, $EA, $7D, $4C, $1F, $2E, +$43, $72, $21, $10, $87, $B6, $E5, $D4, +$FA, $CB, $98, $A9, $3E, $0F, $5C, $6D, +$86, $B7, $E4, $D5, $42, $73, $20, $11, +$3F, $0E, $5D, $6C, $FB, $CA, $99, $A8, +$C5, $F4, $A7, $96, $01, $30, $63, $52, +$7C, $4D, $1E, $2F, $B8, $89, $DA, $EB, +$3D, $0C, $5F, $6E, $F9, $C8, $9B, $AA, +$84, $B5, $E6, $D7, $40, $71, $22, $13, +$7E, $4F, $1C, $2D, $BA, $8B, $D8, $E9, +$C7, $F6, $A5, $94, $03, $32, $61, $50, +$BB, $8A, $D9, $E8, $7F, $4E, $1D, $2C, +$02, $33, $60, $51, $C6, $F7, $A4, $95, +$F8, $C9, $9A, $AB, $3C, $0D, $5E, $6F, +$41, $70, $23, $12, $85, $B4, $E7, $D6, +$7A, $4B, $18, $29, $BE, $8F, $DC, $ED, +$C3, $F2, $A1, $90, $07, $36, $65, $54, +$39, $08, $5B, $6A, $FD, $CC, $9F, $AE, +$80, $B1, $E2, $D3, $44, $75, $26, $17, +$FC, $CD, $9E, $AF, $38, $09, $5A, $6B, +$45, $74, $27, $16, $81, $B0, $E3, $D2, +$BF, $8E, $DD, $EC, $7B, $4A, $19, $28, +$06, $37, $64, $55, $C2, $F3, $A0, $91, +$47, $76, $25, $14, $83, $B2, $E1, $D0, +$FE, $CF, $9C, $AD, $3A, $0B, $58, $69, +$04, $35, $66, $57, $C0, $F1, $A2, $93, +$BD, $8C, $DF, $EE, $79, $48, $1B, $2A, +$C1, $F0, $A3, $92, $05, $34, $67, $56, +$78, $49, $1A, $2B, $BC, $8D, $DE, $EF, +$82, $B3, $E0, $D1, $46, $77, $24, $15, +$3B, $0A, $59, $68, $FF, $CE, $9D, $AC +); + +constructor THasherCRC8_NRSC5.Create; +begin + inherited Create; + FHash := $FF; + Check := 'F7'; +end; + +procedure THasherCRC8_NRSC5.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_NRSC5.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 NRSC-5', THasherCRC8_NRSC5); + +end. diff --git a/CRC8_OPENSAFETY.pas b/CRC8_OPENSAFETY.pas new file mode 100644 index 0000000..66cdd46 --- /dev/null +++ b/CRC8_OPENSAFETY.pas @@ -0,0 +1,82 @@ +unit CRC8_OPENSAFETY; +//CRC-8 OPENSAFETY +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_OPENSAFETY = 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, $2F, $5E, $71, $BC, $93, $E2, $CD, +$57, $78, $09, $26, $EB, $C4, $B5, $9A, +$AE, $81, $F0, $DF, $12, $3D, $4C, $63, +$F9, $D6, $A7, $88, $45, $6A, $1B, $34, +$73, $5C, $2D, $02, $CF, $E0, $91, $BE, +$24, $0B, $7A, $55, $98, $B7, $C6, $E9, +$DD, $F2, $83, $AC, $61, $4E, $3F, $10, +$8A, $A5, $D4, $FB, $36, $19, $68, $47, +$E6, $C9, $B8, $97, $5A, $75, $04, $2B, +$B1, $9E, $EF, $C0, $0D, $22, $53, $7C, +$48, $67, $16, $39, $F4, $DB, $AA, $85, +$1F, $30, $41, $6E, $A3, $8C, $FD, $D2, +$95, $BA, $CB, $E4, $29, $06, $77, $58, +$C2, $ED, $9C, $B3, $7E, $51, $20, $0F, +$3B, $14, $65, $4A, $87, $A8, $D9, $F6, +$6C, $43, $32, $1D, $D0, $FF, $8E, $A1, +$E3, $CC, $BD, $92, $5F, $70, $01, $2E, +$B4, $9B, $EA, $C5, $08, $27, $56, $79, +$4D, $62, $13, $3C, $F1, $DE, $AF, $80, +$1A, $35, $44, $6B, $A6, $89, $F8, $D7, +$90, $BF, $CE, $E1, $2C, $03, $72, $5D, +$C7, $E8, $99, $B6, $7B, $54, $25, $0A, +$3E, $11, $60, $4F, $82, $AD, $DC, $F3, +$69, $46, $37, $18, $D5, $FA, $8B, $A4, +$05, $2A, $5B, $74, $B9, $96, $E7, $C8, +$52, $7D, $0C, $23, $EE, $C1, $B0, $9F, +$AB, $84, $F5, $DA, $17, $38, $49, $66, +$FC, $D3, $A2, $8D, $40, $6F, $1E, $31, +$76, $59, $28, $07, $CA, $E5, $94, $BB, +$21, $0E, $7F, $50, $9D, $B2, $C3, $EC, +$D8, $F7, $86, $A9, $64, $4B, $3A, $15, +$8F, $A0, $D1, $FE, $33, $1C, $6D, $42 +); + +constructor THasherCRC8_OPENSAFETY.Create; +begin + inherited Create; + FHash := $00; + Check := '3E'; +end; + +procedure THasherCRC8_OPENSAFETY.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_OPENSAFETY.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 OPENSAFETY', THasherCRC8_OPENSAFETY); + +end. diff --git a/CRC8_ROHC.pas b/CRC8_ROHC.pas new file mode 100644 index 0000000..753ae41 --- /dev/null +++ b/CRC8_ROHC.pas @@ -0,0 +1,82 @@ +unit CRC8_ROHC; +//CRC-8 ROHC +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_ROHC = 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, $91, $E3, $72, $07, $96, $E4, $75, +$0E, $9F, $ED, $7C, $09, $98, $EA, $7B, +$1C, $8D, $FF, $6E, $1B, $8A, $F8, $69, +$12, $83, $F1, $60, $15, $84, $F6, $67, +$38, $A9, $DB, $4A, $3F, $AE, $DC, $4D, +$36, $A7, $D5, $44, $31, $A0, $D2, $43, +$24, $B5, $C7, $56, $23, $B2, $C0, $51, +$2A, $BB, $C9, $58, $2D, $BC, $CE, $5F, +$70, $E1, $93, $02, $77, $E6, $94, $05, +$7E, $EF, $9D, $0C, $79, $E8, $9A, $0B, +$6C, $FD, $8F, $1E, $6B, $FA, $88, $19, +$62, $F3, $81, $10, $65, $F4, $86, $17, +$48, $D9, $AB, $3A, $4F, $DE, $AC, $3D, +$46, $D7, $A5, $34, $41, $D0, $A2, $33, +$54, $C5, $B7, $26, $53, $C2, $B0, $21, +$5A, $CB, $B9, $28, $5D, $CC, $BE, $2F, +$E0, $71, $03, $92, $E7, $76, $04, $95, +$EE, $7F, $0D, $9C, $E9, $78, $0A, $9B, +$FC, $6D, $1F, $8E, $FB, $6A, $18, $89, +$F2, $63, $11, $80, $F5, $64, $16, $87, +$D8, $49, $3B, $AA, $DF, $4E, $3C, $AD, +$D6, $47, $35, $A4, $D1, $40, $32, $A3, +$C4, $55, $27, $B6, $C3, $52, $20, $B1, +$CA, $5B, $29, $B8, $CD, $5C, $2E, $BF, +$90, $01, $73, $E2, $97, $06, $74, $E5, +$9E, $0F, $7D, $EC, $99, $08, $7A, $EB, +$8C, $1D, $6F, $FE, $8B, $1A, $68, $F9, +$82, $13, $61, $F0, $85, $14, $66, $F7, +$A8, $39, $4B, $DA, $AF, $3E, $4C, $DD, +$A6, $37, $45, $D4, $A1, $30, $42, $D3, +$B4, $25, $57, $C6, $B3, $22, $50, $C1, +$BA, $2B, $59, $C8, $BD, $2C, $5E, $CF +); + +constructor THasherCRC8_ROHC.Create; +begin + inherited Create; + FHash := $FF; + Check := 'D0'; +end; + +procedure THasherCRC8_ROHC.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 THasherCRC8_ROHC.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 ROHC', THasherCRC8_ROHC); + +end. diff --git a/CRC8_SAEJ1850.pas b/CRC8_SAEJ1850.pas new file mode 100644 index 0000000..be3f174 --- /dev/null +++ b/CRC8_SAEJ1850.pas @@ -0,0 +1,82 @@ +unit CRC8_SAEJ1850; +//CRC-8 SAE-J1850 +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_SAEJ1850 = 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, $1D, $3A, $27, $74, $69, $4E, $53, +$E8, $F5, $D2, $CF, $9C, $81, $A6, $BB, +$CD, $D0, $F7, $EA, $B9, $A4, $83, $9E, +$25, $38, $1F, $02, $51, $4C, $6B, $76, +$87, $9A, $BD, $A0, $F3, $EE, $C9, $D4, +$6F, $72, $55, $48, $1B, $06, $21, $3C, +$4A, $57, $70, $6D, $3E, $23, $04, $19, +$A2, $BF, $98, $85, $D6, $CB, $EC, $F1, +$13, $0E, $29, $34, $67, $7A, $5D, $40, +$FB, $E6, $C1, $DC, $8F, $92, $B5, $A8, +$DE, $C3, $E4, $F9, $AA, $B7, $90, $8D, +$36, $2B, $0C, $11, $42, $5F, $78, $65, +$94, $89, $AE, $B3, $E0, $FD, $DA, $C7, +$7C, $61, $46, $5B, $08, $15, $32, $2F, +$59, $44, $63, $7E, $2D, $30, $17, $0A, +$B1, $AC, $8B, $96, $C5, $D8, $FF, $E2, +$26, $3B, $1C, $01, $52, $4F, $68, $75, +$CE, $D3, $F4, $E9, $BA, $A7, $80, $9D, +$EB, $F6, $D1, $CC, $9F, $82, $A5, $B8, +$03, $1E, $39, $24, $77, $6A, $4D, $50, +$A1, $BC, $9B, $86, $D5, $C8, $EF, $F2, +$49, $54, $73, $6E, $3D, $20, $07, $1A, +$6C, $71, $56, $4B, $18, $05, $22, $3F, +$84, $99, $BE, $A3, $F0, $ED, $CA, $D7, +$35, $28, $0F, $12, $41, $5C, $7B, $66, +$DD, $C0, $E7, $FA, $A9, $B4, $93, $8E, +$F8, $E5, $C2, $DF, $8C, $91, $B6, $AB, +$10, $0D, $2A, $37, $64, $79, $5E, $43, +$B2, $AF, $88, $95, $C6, $DB, $FC, $E1, +$5A, $47, $60, $7D, $2E, $33, $14, $09, +$7F, $62, $45, $58, $0B, $16, $31, $2C, +$97, $8A, $AD, $B0, $E3, $FE, $D9, $C4 +); + +constructor THasherCRC8_SAEJ1850.Create; +begin + inherited Create; + FHash := $FF; + Check := '4B'; +end; + +procedure THasherCRC8_SAEJ1850.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_SAEJ1850.Final: String; +begin + FHash := FHash xor $FF; + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 SAE-J1850', THasherCRC8_SAEJ1850); + +end. diff --git a/CRC8_SMBUS.pas b/CRC8_SMBUS.pas new file mode 100644 index 0000000..399a7cd --- /dev/null +++ b/CRC8_SMBUS.pas @@ -0,0 +1,82 @@ +unit CRC8_SMBUS; +//CRC-8 SMBUS +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_SMBUS = 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, $07, $0E, $09, $1C, $1B, $12, $15, +$38, $3F, $36, $31, $24, $23, $2A, $2D, +$70, $77, $7E, $79, $6C, $6B, $62, $65, +$48, $4F, $46, $41, $54, $53, $5A, $5D, +$E0, $E7, $EE, $E9, $FC, $FB, $F2, $F5, +$D8, $DF, $D6, $D1, $C4, $C3, $CA, $CD, +$90, $97, $9E, $99, $8C, $8B, $82, $85, +$A8, $AF, $A6, $A1, $B4, $B3, $BA, $BD, +$C7, $C0, $C9, $CE, $DB, $DC, $D5, $D2, +$FF, $F8, $F1, $F6, $E3, $E4, $ED, $EA, +$B7, $B0, $B9, $BE, $AB, $AC, $A5, $A2, +$8F, $88, $81, $86, $93, $94, $9D, $9A, +$27, $20, $29, $2E, $3B, $3C, $35, $32, +$1F, $18, $11, $16, $03, $04, $0D, $0A, +$57, $50, $59, $5E, $4B, $4C, $45, $42, +$6F, $68, $61, $66, $73, $74, $7D, $7A, +$89, $8E, $87, $80, $95, $92, $9B, $9C, +$B1, $B6, $BF, $B8, $AD, $AA, $A3, $A4, +$F9, $FE, $F7, $F0, $E5, $E2, $EB, $EC, +$C1, $C6, $CF, $C8, $DD, $DA, $D3, $D4, +$69, $6E, $67, $60, $75, $72, $7B, $7C, +$51, $56, $5F, $58, $4D, $4A, $43, $44, +$19, $1E, $17, $10, $05, $02, $0B, $0C, +$21, $26, $2F, $28, $3D, $3A, $33, $34, +$4E, $49, $40, $47, $52, $55, $5C, $5B, +$76, $71, $78, $7F, $6A, $6D, $64, $63, +$3E, $39, $30, $37, $22, $25, $2C, $2B, +$06, $01, $08, $0F, $1A, $1D, $14, $13, +$AE, $A9, $A0, $A7, $B2, $B5, $BC, $BB, +$96, $91, $98, $9F, $8A, $8D, $84, $83, +$DE, $D9, $D0, $D7, $C2, $C5, $CC, $CB, +$E6, $E1, $E8, $EF, $FA, $FD, $F4, $F3 +); + +constructor THasherCRC8_SMBUS.Create; +begin + inherited Create; + FHash := $00; + Check := 'F4'; +end; + +procedure THasherCRC8_SMBUS.Update(Msg: PByte; Length: Integer); +var i: Integer; +begin + for i:=0 to Length-1 do begin + FHash := (FHash shl 8) xor Table[(Msg^ xor FHash) and $FF]; + Inc(Msg); + end; +end; + +function THasherCRC8_SMBUS.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 SMBUS', THasherCRC8_SMBUS); + +end. diff --git a/CRC8_TECH3250.pas b/CRC8_TECH3250.pas new file mode 100644 index 0000000..50acc0b --- /dev/null +++ b/CRC8_TECH3250.pas @@ -0,0 +1,82 @@ +unit CRC8_TECH3250; +//CRC-8 TECH-3250 +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_TECH3250 = 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, $64, $C8, $AC, $E1, $85, $29, $4D, +$B3, $D7, $7B, $1F, $52, $36, $9A, $FE, +$17, $73, $DF, $BB, $F6, $92, $3E, $5A, +$A4, $C0, $6C, $08, $45, $21, $8D, $E9, +$2E, $4A, $E6, $82, $CF, $AB, $07, $63, +$9D, $F9, $55, $31, $7C, $18, $B4, $D0, +$39, $5D, $F1, $95, $D8, $BC, $10, $74, +$8A, $EE, $42, $26, $6B, $0F, $A3, $C7, +$5C, $38, $94, $F0, $BD, $D9, $75, $11, +$EF, $8B, $27, $43, $0E, $6A, $C6, $A2, +$4B, $2F, $83, $E7, $AA, $CE, $62, $06, +$F8, $9C, $30, $54, $19, $7D, $D1, $B5, +$72, $16, $BA, $DE, $93, $F7, $5B, $3F, +$C1, $A5, $09, $6D, $20, $44, $E8, $8C, +$65, $01, $AD, $C9, $84, $E0, $4C, $28, +$D6, $B2, $1E, $7A, $37, $53, $FF, $9B, +$B8, $DC, $70, $14, $59, $3D, $91, $F5, +$0B, $6F, $C3, $A7, $EA, $8E, $22, $46, +$AF, $CB, $67, $03, $4E, $2A, $86, $E2, +$1C, $78, $D4, $B0, $FD, $99, $35, $51, +$96, $F2, $5E, $3A, $77, $13, $BF, $DB, +$25, $41, $ED, $89, $C4, $A0, $0C, $68, +$81, $E5, $49, $2D, $60, $04, $A8, $CC, +$32, $56, $FA, $9E, $D3, $B7, $1B, $7F, +$E4, $80, $2C, $48, $05, $61, $CD, $A9, +$57, $33, $9F, $FB, $B6, $D2, $7E, $1A, +$F3, $97, $3B, $5F, $12, $76, $DA, $BE, +$40, $24, $88, $EC, $A1, $C5, $69, $0D, +$CA, $AE, $02, $66, $2B, $4F, $E3, $87, +$79, $1D, $B1, $D5, $98, $FC, $50, $34, +$DD, $B9, $15, $71, $3C, $58, $F4, $90, +$6E, $0A, $A6, $C2, $8F, $EB, $47, $23 +); + +constructor THasherCRC8_TECH3250.Create; +begin + inherited Create; + FHash := $FF; + Check := '97'; +end; + +procedure THasherCRC8_TECH3250.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 THasherCRC8_TECH3250.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 TECH-3250', THasherCRC8_TECH3250); + +end. diff --git a/CRC8_WCDMA.pas b/CRC8_WCDMA.pas new file mode 100644 index 0000000..a6bcfc0 --- /dev/null +++ b/CRC8_WCDMA.pas @@ -0,0 +1,82 @@ +unit CRC8_WCDMA; +//CRC-8 WCDMA +//Author: domasz +//Version: 0.1 (2022-11-17) +//Licence: MIT + +interface + +uses SysUtils, HasherBase; + +type THasherCRC8_WCDMA = 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, $D0, $13, $C3, $26, $F6, $35, $E5, +$4C, $9C, $5F, $8F, $6A, $BA, $79, $A9, +$98, $48, $8B, $5B, $BE, $6E, $AD, $7D, +$D4, $04, $C7, $17, $F2, $22, $E1, $31, +$83, $53, $90, $40, $A5, $75, $B6, $66, +$CF, $1F, $DC, $0C, $E9, $39, $FA, $2A, +$1B, $CB, $08, $D8, $3D, $ED, $2E, $FE, +$57, $87, $44, $94, $71, $A1, $62, $B2, +$B5, $65, $A6, $76, $93, $43, $80, $50, +$F9, $29, $EA, $3A, $DF, $0F, $CC, $1C, +$2D, $FD, $3E, $EE, $0B, $DB, $18, $C8, +$61, $B1, $72, $A2, $47, $97, $54, $84, +$36, $E6, $25, $F5, $10, $C0, $03, $D3, +$7A, $AA, $69, $B9, $5C, $8C, $4F, $9F, +$AE, $7E, $BD, $6D, $88, $58, $9B, $4B, +$E2, $32, $F1, $21, $C4, $14, $D7, $07, +$D9, $09, $CA, $1A, $FF, $2F, $EC, $3C, +$95, $45, $86, $56, $B3, $63, $A0, $70, +$41, $91, $52, $82, $67, $B7, $74, $A4, +$0D, $DD, $1E, $CE, $2B, $FB, $38, $E8, +$5A, $8A, $49, $99, $7C, $AC, $6F, $BF, +$16, $C6, $05, $D5, $30, $E0, $23, $F3, +$C2, $12, $D1, $01, $E4, $34, $F7, $27, +$8E, $5E, $9D, $4D, $A8, $78, $BB, $6B, +$6C, $BC, $7F, $AF, $4A, $9A, $59, $89, +$20, $F0, $33, $E3, $06, $D6, $15, $C5, +$F4, $24, $E7, $37, $D2, $02, $C1, $11, +$B8, $68, $AB, $7B, $9E, $4E, $8D, $5D, +$EF, $3F, $FC, $2C, $C9, $19, $DA, $0A, +$A3, $73, $B0, $60, $85, $55, $96, $46, +$77, $A7, $64, $B4, $51, $81, $42, $92, +$3B, $EB, $28, $F8, $1D, $CD, $0E, $DE +); + +constructor THasherCRC8_WCDMA.Create; +begin + inherited Create; + FHash := $00; + Check := '25'; +end; + +procedure THasherCRC8_WCDMA.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 THasherCRC8_WCDMA.Final: String; +begin + + Result := IntToHex(FHash, 2); +end; + +initialization + HasherList.RegisterHasher('CRC-8 WCDMA', THasherCRC8_WCDMA); + +end. diff --git a/Hasher.pas b/Hasher.pas index f9dc3d1..03a8d17 100644 --- a/Hasher.pas +++ b/Hasher.pas @@ -5,11 +5,16 @@ interface -uses SysUtils, Classes, Bufstream, HasherBase, +uses SysUtils, Classes, Bufstream, HasherBase, Dialogs, + + CRC8_AUTOSAR, CRC8_BLUETOOTH, CRC8_CDMA2000, CRC8_DARC, CRC8_DVBS2, CRC8_GSMA, + CRC8_GSMB, CRC8_HITAG, CRC8_I4321, CRC8_ICODE, CRC8_LTE, CRC8_MAXIMDOW, + CRC8_MIFAREMAD, CRC8_NRSC5, CRC8_OPENSAFETY, CRC8_ROHC, CRC8_SAEJ1850, + CRC8_SMBUS, CRC8_TECH3250, CRC8_WCDMA, Adler8, Adler16, Adler32, Adler64, cksum_mpeg2, - CRC8_AUTOSAR, CRC8_BLUETOOTH, + CRC16_ARC, CRC16_CDMA2000, CRC32_MPEG2, CRC32_JAMCRC, CRC64, CRC64_ecma, @@ -18,9 +23,13 @@ interface XOR8, XOR16, XOR32; type + + { THasher } + THasher = class private FAlgo: THasherBase; + FClass: THasherClass; public constructor Create(Algo: String); destructor Destroy; override; @@ -29,6 +38,7 @@ THasher = class procedure Update(Str: AnsiString); overload; procedure Update(Msg: PByte; Length: Integer); overload; procedure UpdateFile(Filename: TFilename); + function SelfCheck: Boolean; end; implementation @@ -65,6 +75,23 @@ procedure THasher.UpdateFile(Filename: TFilename); end; end; +function THasher.SelfCheck: Boolean; +const Test: array[0..9] of AnsiChar = '123456789'; +var Algo: THasherBase; + Res: String; +begin + Result := False; + try + Algo := FClass.Create; + Algo.Update(@Test[0], 9); + Res := Algo.Final; + + if Algo.Check = Res then Result := True; + finally + Algo.Free; + end; +end; + procedure THasher.Update(Msg: PByte; Length: Integer); begin FAlgo.Update(Msg, Length); @@ -80,6 +107,7 @@ constructor THasher.Create(Algo: String); if not Res then raise exception.create('Invalid algorithm'); + FClass := AClass; FAlgo := AClass.Create; end;