Recent

Author Topic: Hashes  (Read 4264 times)

lazarus9

  • Full Member
  • ***
  • Posts: 118
Re: Hashes
« Reply #15 on: October 21, 2018, 07:24:14 pm »
OK, thanks.  I completely missed your reply above.  I'll try to do it and get back if any (most likely) problems.  Not real familiar with working with anything that is not a component.

Xor-el

  • Sr. Member
  • ****
  • Posts: 374
Re: Hashes
« Reply #16 on: October 21, 2018, 07:38:55 pm »
OK, thanks.  I completely missed your reply above.  I'll try to do it and get back if any (most likely) problems.  Not real familiar with working with anything that is not a component.

You are welcome.
While working with components is easy (especially for newbies), it limits your scope (most times) to just GUI programs and singleton designs which gets rowdy and untidy very quickly in the long run.

lazarus9

  • Full Member
  • ***
  • Posts: 118
Re: Hashes
« Reply #17 on: October 21, 2018, 09:37:41 pm »
  Agreed.  I have been using delphi and lazarus since the mid 90s, but don't have much experience in the adding of things as you showed above.
My real programming job was in IBM assembler and cobol.  Here is what I did step by step for anyone who might want to know:

1. Downloaded HashLib4Pascal from https://github.com/Xor-el/HashLib4Pascal
2. Unzipped it and copied the (sub) folder named HashLib4Pascal into C:\Lazarus\components\
3. Start the Lazarus compiler and click lazarus menu items Packages/Open packages file (.lpk)... and go to
    C:\Lazarus\components\HashLib4Pascal\HashLib\src\Packages\FPC\ and double clicked on HashLib4PascalPackage.lpk
4. Clicked the compile button in the window that comes up and when finished, closed out that window.
5. Then go to menu items Project/Project Inspector... and click on Add/New Requirements and select package name HashLib4PascalPackage,
    click OK, and close that window.
6. Start a Lazarus project and Add StdCtrls and HlpHashFactory to uses.
7. Here is the code to get the tiger hash of the word Fish:


unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, HlpHashFactory;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;

    procedure Button1Click(Sender: TObject);
    function  Tigit(data : string): string;

  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}


{ TForm1 }

function TForm1.Tigit(data : string): string;
begin
     Result := THashFactory.TCrypto.CreateTiger_5_192().ComputeString('Fish', TEncoding.UTF8).ToString();
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     ShowMessage( Tigit(''));
end;

end.

Xor-el

  • Sr. Member
  • ****
  • Posts: 374
Re: Hashes
« Reply #18 on: October 21, 2018, 09:58:48 pm »
Did some minor refactoring to your code to allow hashing of different strings
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, HlpHashFactory;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.  
  17.     procedure Button1Click(Sender: TObject);
  18.     function  Tigit(data : string): string;
  19.  
  20.   private
  21.  
  22.   public
  23.  
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33.  
  34. { TForm1 }
  35.  
  36. function TForm1.Tigit(data : string): string;
  37. begin
  38.      Result := THashFactory.TCrypto.CreateTiger_5_192().ComputeString(data, TEncoding.UTF8).ToString();
  39. end;
  40.  
  41. procedure TForm1.Button1Click(Sender: TObject);
  42. begin
  43.      ShowMessage( Tigit('Fish'));
  44. end;
  45.  
  46. end.
  47.  


lazarus9

  • Full Member
  • ***
  • Posts: 118
Re: Hashes
« Reply #19 on: October 21, 2018, 11:12:20 pm »
  Don't mean to be pushy or impose, but I hope you might include the additional hashes found in RHash some day.  It is written in C, but shouldn't take too much effort to convert if you know C also.  My use of C always gets me a grade of F.

Thaddy

  • Hero Member
  • *****
  • Posts: 9183
Re: Hashes
« Reply #20 on: October 22, 2018, 10:29:23 am »
Which ones? It is hardly worth the effort if they are exotica. Half of it is C macro's which is boring.
also related to equus asinus.

Xor-el

  • Sr. Member
  • ****
  • Posts: 374
Re: Hashes
« Reply #21 on: October 22, 2018, 12:06:14 pm »
  Don't mean to be pushy or impose, but I hope you might include the additional hashes found in RHash some day.  It is written in C, but shouldn't take too much effort to convert if you know C also.  My use of C always gets me a grade of F.

I agree with Thaddy, Some of the hashes there has no real use or application in the real world. of all the hashes found in RHash (not currently available in HashLib), I can only think of one (Gost Crypto) that might be kind of useful if ported.

lazarus9

  • Full Member
  • ***
  • Posts: 118
Re: Hashes
« Reply #22 on: October 22, 2018, 08:39:59 pm »
I would still like tth and aich, but don't know if they are exotica.  If so, then forget it.

By the way, the wiki says that there is one called Streebog which I don't see in the Cripto. list.  And there is a Keccak which I didn't see on the wiki.  Keccak = Streebog?

Edit:  I think I see now.  Streebog =  (GOST3411_2012_256, GOST3411_2012_512).
« Last Edit: October 22, 2018, 08:42:54 pm by lazarus9 »

Xor-el

  • Sr. Member
  • ****
  • Posts: 374
Re: Hashes
« Reply #23 on: October 22, 2018, 09:16:54 pm »
I would still like tth and aich, but don't know if they are exotica.  If so, then forget it.

By the way, the wiki says that there is one called Streebog which I don't see in the Cripto. list.  And there is a Keccak which I didn't see on the wiki.  Keccak = Streebog?

Edit:  I think I see now.  Streebog =  (GOST3411_2012_256, GOST3411_2012_512).

Yes, streebog is GOST3411_2012_256, GOST3411_2012_512.
Keccak is in the sha3 unit.
You can access it via the HashFactory class like this for Keccak_224

Code: Pascal  [Select]
  1. THashFactory.TCrypto.CreateKeccak_224


The unit tests contains these and more examples, just take some time and go through it.
« Last Edit: October 22, 2018, 10:42:26 pm by Xor-el »