Recent

Author Topic: Hashes  (Read 4284 times)

lazarus9

  • Full Member
  • ***
  • Posts: 118
Hashes
« on: October 20, 2018, 04:33:00 pm »
Does anyone know of any additional Hash generators code (.pas files ok) for Lazarus/pascal?  I need whirlpool, gost, tth, aich, and can use others also.

I have these:

DCP_tiger1
DCP_sha512_1
DCP_sha256_1
DCP_sha384_1
DCP_sha1_1
DCP_ripemd160_1
DCP_ripemd128_1
DCP_md5_1
DCP_haval1

Thanks

Xor-el

  • Sr. Member
  • ****
  • Posts: 378
Re: Hashes
« Reply #1 on: October 20, 2018, 05:09:14 pm »
Does anyone know of any additional Hash generators code (.pas files ok) for Lazarus/pascal?  I need whirlpool, gost, tth, aich, and can use others also.

I have these:

DCP_tiger1
DCP_sha512_1
DCP_sha256_1
DCP_sha384_1
DCP_sha1_1
DCP_ripemd160_1
DCP_ripemd128_1
DCP_md5_1
DCP_haval1

Thanks

Hi, you can take a look at HashLib4Pascal http://wiki.freepascal.org/HashLib4Pascal, It supports all the hashes you mentioned (except (tth, aich), I don't know what those mean?) and more.

Thaddy

  • Hero Member
  • *****
  • Posts: 9194
Re: Hashes
« Reply #2 on: October 20, 2018, 09:03:44 pm »
Hi, you can take a look at HashLib4Pascal http://wiki.freepascal.org/HashLib4Pascal, It supports all the hashes you mentioned (except (tth, aich), I don't know what those mean?) and more.
Yes I would recommend the same: your code is excellent and standards compliant, Xor-el! Although there are other options.
@Xor-el: aich is the hash for emule and tth is tiger tree hashing.. (which you know, tiger1 is from that family). Just curious: can you add an mp3 that pronounces your real name? O:-) :o :)
« Last Edit: October 20, 2018, 09:14:03 pm by Thaddy »
also related to equus asinus.

Xor-el

  • Sr. Member
  • ****
  • Posts: 378
Re: Hashes
« Reply #3 on: October 20, 2018, 09:15:27 pm »
Quote
Yes I would recommend the same: your code is excellent and standards compliant, Xor-el! Although there are other options.
@Xor-el: aich is the hash for emule and tth is tiger tree hashing.. (which you know, probably). Just curious: can you add an mp3 that pronounces your real name? O:-) :o :)
@Thaddy, Thanks for the kind words and the explanation of tth, ( I kind of figured it out after I made the post ), it is very much appreciated.
as regards the mp3, I will give a thought to that.  ::) ;)
« Last Edit: October 20, 2018, 09:50:35 pm by Xor-el »

Thaddy

  • Hero Member
  • *****
  • Posts: 9194
Re: Hashes
« Reply #4 on: October 20, 2018, 10:05:01 pm »
We could just call you Al (Paul Simon)
also related to equus asinus.

Xor-el

  • Sr. Member
  • ****
  • Posts: 378
Re: Hashes
« Reply #5 on: October 20, 2018, 10:07:40 pm »
Quote
Just curious: can you add an mp3 that pronounces your real name? O:-) :o :)

@Thaddy, Done, Check DM.  :) ::)

Xor-el

  • Sr. Member
  • ****
  • Posts: 378
Re: Hashes
« Reply #6 on: October 20, 2018, 10:09:26 pm »
We could just call you Al (Paul Simon)
That kind of has a nice ring to it. :D
By the way, this song brings back memories.  ;)
https://www.youtube.com/watch?v=uq-gYOrU8bA
« Last Edit: October 20, 2018, 10:13:55 pm by Xor-el »

lazarus9

  • Full Member
  • ***
  • Posts: 118
Re: Hashes
« Reply #7 on: October 20, 2018, 11:29:59 pm »
Hi, you can take a look at HashLib4Pascal http://wiki.freepascal.org/HashLib4Pascal, It supports all the hashes you mentioned (except (tth, aich), I don't know what those mean?) and more.

  Really nice, thanks.  Needed GOST, Panama, Whirlpool and some of the others.  I am trying to increase some of the hash options in a freeware program I have out.  I tried commandlining RHash to get the results, but it delays the program too much.  The reason I want tth and aich is because they has full a-z characters.  Makes for a nice ED25519 like hash option.


marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7510
Re: Hashes
« Reply #8 on: October 21, 2018, 12:13:39 pm »
We could just call you Al (Paul Simon)

So that makes you Betty ?

P.s. my mother had the album on repeat for YEARS. It is quite nice, but that was too much :_)

lazarus9

  • Full Member
  • ***
  • Posts: 118
Re: Hashes
« Reply #9 on: October 21, 2018, 04:13:00 pm »
I was trying to install HashLib4Pascal into lazarus, but the Use/Install menu item is grayed out.  Does this mean that these components are not put into a tab?

I tried something like below to use the tiger component, but couldn't get it to work.

<code>
function get_tiger(S: String): String;
var Hash: TDCP_tiger;
    Digest: array[0..23] of byte;  // HashSize = 192
    Source: string;
    i: integer;
    str1: string;
begin
     Source:= S;  // here your string for get sha256

     if Source <> '' then begin
        Hash := Form1.DCP_tiger1;  // create the hash
        Hash.Init;                       // initialize it
        Hash.UpdateStr(Source);
        Hash.Final(Digest);              // produce the digest
        str1 := '';

        for i := 0 to 23 do
            str1 := str1 + IntToHex(Digest, 2);
     end;

     Result := str1;
end;
</code>

Xor-el

  • Sr. Member
  • ****
  • Posts: 378
Re: Hashes
« Reply #10 on: October 21, 2018, 05:03:12 pm »
I was trying to install HashLib4Pascal into lazarus, but the Use/Install menu item is grayed out.  Does this mean that these components are not put into a tab?

I tried something like below to use the tiger component, but couldn't get it to work.

<code>
function get_tiger(S: String): String;
var Hash: TDCP_tiger;
    Digest: array[0..23] of byte;  // HashSize = 192
    Source: string;
    i: integer;
    str1: string;
begin
     Source:= S;  // here your string for get sha256

     if Source <> '' then begin
        Hash := Form1.DCP_tiger1;  // create the hash
        Hash.Init;                       // initialize it
        Hash.UpdateStr(Source);
        Hash.Final(Digest);              // produce the digest
        str1 := '';

        for i := 0 to 23 do
            str1 := str1 + IntToHex(Digest, 2);
     end;

     Result := str1;
end;
</code>

First of all,
HashLib4Pascal is a Runtime Package not a Design Time one meaning you can even use it in Console programs.

The Steps are

1. Install the HashLib Package from OPM (online package manager) or from Github (https://github.com/Xor-el/HashLib4Pascal)

2. Add the "HashLib4PascalPackage" to your Program Projects "Required Packages".

3.
Simple One Liner Code to Compute Hash of a String using Tiger_5_192.
Do note that HashLib4Pascal supports incremental Hashing too.
For more examples, take a look at the unit tests, they contain lots of code samples.

Code: Pascal  [Select]
  1.  
  2. uses
  3. SysUtils,
  4. HlpHashFactory;
  5.  
  6. .....
  7.  
  8.  
  9. Result := THashFactory.TCrypto.CreateTiger_5_192().ComputeString('Fish', TEncoding.UTF8).ToString();
  10.  

Thaddy

  • Hero Member
  • *****
  • Posts: 9194
Re: Hashes
« Reply #11 on: October 21, 2018, 05:14:52 pm »
Indeed. These are not components, but classes.
Don't ask for components, they would be over-coding and not very useful in true, real life, settings.
Xor-el would probably never even consider it. (this code is not for - I hear a song - "Absolute Beginners" comes to mind.... 8-))

In this case installing the package simply means the classes are compiled and available for fast linking without re-compiling.
« Last Edit: October 21, 2018, 05:18:37 pm by Thaddy »
also related to equus asinus.

Thaddy

  • Hero Member
  • *****
  • Posts: 9194
Re: Hashes
« Reply #12 on: October 21, 2018, 05:20:02 pm »
also related to equus asinus.

lazarus9

  • Full Member
  • ***
  • Posts: 118
Re: Hashes
« Reply #13 on: October 21, 2018, 06:36:19 pm »
Indeed. These are not components, but classes.
Don't ask for components, they would be over-coding and not very useful in true, real life, settings.
Xor-el would probably never even consider it. (this code is not for - I hear a song - "Absolute Beginners" comes to mind.... 8-))

In this case installing the package simply means the classes are compiled and available for fast linking without re-compiling.

When I try to execute my routine, I get this error:

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, HlpTiger;

type
  TForm1 = class(TForm)
    HlpTiger1: TTiger;   

Error. Only classes which are compiled in $M+ mode can be published


Not sure what that means or how it is done.  Does $M+ need to be put in somewhere as a compiler directive before compiling HashLib4PascalPackage.lpk?

Xor-el

  • Sr. Member
  • ****
  • Posts: 378
Re: Hashes
« Reply #14 on: October 21, 2018, 07:08:39 pm »
Quote

When I try to execute my routine, I get this error:

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, HlpTiger;

type
  TForm1 = class(TForm)
    HlpTiger1: TTiger;   

Error. Only classes which are compiled in $M+ mode can be published


Not sure what that means or how it is done.  Does $M+ need to be put in somewhere as a compiler directive before compiling HashLib4PascalPackage.lpk?

You are doing it all wrong.
There's no need to use the HlpTiger unit except you know exactly what you are doing.

For ease of use and to avoid mistakes, use the factory method as I specified in my previous example.

Also the error you get is as a result of placing HlpTiger1: TTiger;  in the published section of your form.
Define that variable in the public section of your form.
« Last Edit: October 25, 2018, 09:12:17 pm by Xor-el »