GithubHelp home page GithubHelp logo

pascalvault / lazarus_hashing Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 3.0 278 KB

Checksum & Hashing library for Lazarus

License: MIT License

Pascal 100.00%
crc crc-16 crc-32 crc-8 crc-algorithms crc-calculation crc16 crc32 crc64 crc8

lazarus_hashing's Introduction

Checksum & Hashing library for Lazarus

The goal is the create a library which is modular, fast and portable. There is no platform-specific code, no Assembly, no includes, no conditinal defines. Every algorith has it's own separate file and if you need just one algorithm in your program you can just copy 2 files- the file with the algorithm you need and "HasherBase.pas". Optionally you can copy "Hasher.pas" but that's just a helper class.

Available algorithms

More soon...

  • CRC-4 interlaken,
  • CRC-6 DARC, CRC-6 G704,
  • CRC-7 mmc, CRC-7 umts,
  • CRC-8 AUTOSAR, CRC-8 BLUETOOTH, CRC-8 CDMA2000, CRC-8 DARC, CRC-8 DVBS2, CRC-8 GSMA, CRC-8 GSMB, CRC-8 HITAG, CRC-8 I4321, CRC-8 ICODE, CRC-8 LTE, CRC-8 MAXIMDOW, CRC-8 MIFAREMAD, CRC-8 NRSC5, CRC-8 OPENSAFETY, CRC-8 ROHC, CRC-8 SAEJ1850, CRC-8 SMBUS, CRC-8 TECH3250, CRC-8 WCDMA,
  • CRC-10 atm, CRC-10 gsm, CRC-10 cdma2000,
  • CRC-11 flexray, CRC-11 umts,
  • CRC-12 gsm, CRC-12 dect, CRC-12 cdma2000,
  • CRC-13 bbc,
  • CRC-14 gsm,
  • CRC-15 can, CRC-15 MPT1327,
  • CRC-16 ARC, CRC-16 CDMA2000, CRC-16 CMS, CRC-16 DDS110, CRC-16 DECTR, CRC-16 DECTX, CRC-16 DNP, CRC-16 EN13757, CRC-16 GENIBUS, CRC-16 GSM, CRC-16 IBM3740, CRC-16 IBMSDLC, CRC-16 KERMIT, CRC-16 LJ1200, CRC-16 M17, CRC-16 MAXIMDOW, CRC-16 MCRF4XX, CRC-16 MODBUS, CRC-16 NRSC5, CRC-16 OPENSAFETYA, CRC-16 OPENSAFETYB, CRC-16 PROFIBUS, CRC-16 SPIFUJITSU, CRC-16 T10DIF, CR-C16 TELEDISK, CRC-16 UMTS, CRC-16 USB, CRC-16 XMODEM,
  • CRC-17 canfd,
  • CRC-21 canfd,
  • CRC-24 OS9, CRC-24 FLEXRAYA, CRC-24 FLEXRAYB, CRC-24 INTERLAKEN, CRC-24 LTEA, CRC-24 LTEB, CRC-24 OPENPGP,
  • CRC-30 cdma,
  • CRC-31 philips,
  • CRC-32 MPEG2, CRC32 JAMCRC,
  • CRC-40 gsm,
  • CRC-64, CRC-64 ecma, CRC-64 go, CRC-64 ecma 182, CRC-64 xz, CRC-64 ms,
  • CRC-82 darc,
  • Adler8, Adler16, Adler32, Adler64,
  • cksum mpeg2,
  • Fletcher8, Fletcher16, Fletcher32, Fletcher64,
  • SIZE64, Sum BSD, Sum SYSV,
  • SUM8, SUM16, SUM24, SUM32, SUM64,
  • XOR8, XOR16, XOR32
  • xxHash32
  • MurmurHash, MurmurHash2, MurmurHash2a, MurmurHash3
  • SHA-0, SHA-1, SHA-224, SHA-256

PHP port available

https://github.com/PascalVault/PHP_Hashing

Usage examples

hashing a String

uses Hasher;

var Hasher: THasher;
    Hash: String;
begin
  try
    Hasher := THasher.Create('CRC-32 JAMCRC');
    Hasher.Update('123456789');
    Hash := Hasher.Final;
    Hasher.Free;
    
    Memo1.Lines.Add( Hash );
  finally
  end; 

hashing a Stream

uses Hasher;

var Hasher: THasher;
    Hash: String;
    Msg: TMemoryStream;
begin
  try
    Msg := TMemoryStream.Create;
    Hasher := THasher.Create('CRC-32 JAMCRC');
    Hasher.Update(Msg);
    Hash := Hasher.Final;
    Hasher.Free;
    
    Memo1.Lines.Add( Hash );
  finally
    Msg.Free;
  end; 

hashing a file

 uses Hasher;

var Hasher: THasher;
    Hash: String;
begin
  try       
    Hasher := THasher.Create('CRC-32 JAMCRC');
    Hasher.UpdateFile('directory/file.exe');
    Hash := Hasher.Final;
    Hasher.Free;
    
    Memo1.Lines.Add( Hash );
  finally
  end; 

Using classes directly- without THasher

hashing a String

uses CRC64;

var Hasher: THasherCRC64;
    Hash: String;
    Msg: String;
begin
  Msg := '123456789';
  Hasher := THasherCRC64.Create;
  Hasher.Update(@Msg[1], Length(Msg));
  Hash := Hasher.Final;
  Hasher.Free;

  Memo1.Lines.Add( Hash );
end;

hashing an Array

uses CRC64;

var Hasher: THasherCRC64;
    Hash: String;
    Msg: array of Byte;
    Len: Integer;
begin
  SetLength(Msg, Len);
  Hasher := THasherCRC64.Create;
  Hasher.Update(@Msg[0], Len);
  Hash := Hasher.Final;
  Hasher.Free;

  Memo1.Lines.Add( Hash );
end;

lazarus_hashing's People

Contributors

pascalvault avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lazarus_hashing's Issues

little incorrect try/finally block

  try
    Algo := FClass.Create;
    Algo.Update(@Test[0], 9);
    Res := Algo.Final;

    if Algo.Check = Res then Result := True;
  finally
    Algo.Free;
  end;

move line Algo:= BEFORE try, common practice, more correct.

maybe use TStringList.CaseSensitive

function THasherList.FindClass(Name: String; out AClass: THasherClass): Boolean;
var Index: Integer;
begin
  Name := LowerCase(Name);

with CaseSensitive, you can avoid LowerCase

add helper method IsIndexValid

adding helper func will help in places like this:

function THasherList.GetName(Index: Integer): String;
begin
  if (Index > FList.Count-1) or (Index < 0) then Result := ''

maybe make the Lazarus package?

.lpk file. Making it will allow to use the package and src-folder will be auto included the the proj. no need to copy files into proj dir.

before doing LPK file, pls move all .pas files to 'src' folder and include pas files from there. LPK file can be inside 'src' too.

small optim here?

function THasherList.FindClass(Name: String; out AClass: THasherClass): Boolean;
var Index: Integer;
begin
  Name := LowerCase(Name);
  Index := FList.IndexOf(Name);

FList.IndexOf(LowerCase(Name)) and make Name the const-param.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.