Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 09-24-2017, 12:38 PM
Luiz Eduardo Luiz Eduardo is offline
Member
 
Join Date: May 2014
Posts: 34
Default php to Delphi: validate Bitcoin wallet address

I'm trying convert a php code that is able to validate a Bitcoin hash and i have some questions:

How could be a equivalent for hash() function (php to Delphi)?
How could be a equivalent for substr_compare() function (php to Delphi)?
Following php code used as reference and my try of translation:

PHP Example

Delphi:

Code:
uses
  System.SysUtils, IdHashSHA, IdSSLOpenSSL;

const
  BASE58_ALPHABET = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';

function Base58Decode(const encoded: string): uint64;
var
  i, index: longint;
  base: uint64;
begin
  result := 0;
  base := 1;
  for i := Length(encoded) - 1 downto 0 do
  begin
    index := Pos(Copy(encoded, i + 1, 1), BASE58_ALPHABET) - 1;
    result := result + (index * base);
    base := 58 * base;
  end;
end;

function GetSHA256Str(const str: string): string;
begin
  IdSSLOpenSSL.LoadOpenSSLLibrary;
  with TIdHashSHA256.Create do
  try
    Result := HashStringAsHex(str);
  finally
    Free;
  end;
  IdSSLOpenSSL.UnLoadOpenSSLLibrary;
end;

function validation(address: string): Boolean;
var
 decoded, d1, d2: string;
begin

  decoded := IntToStr(Base58Decode(address));
  d1 := GetSHA256Str(copy(address, 0, 21));
  d2 := GetSHA256Str(d1);

  //...

  Result := True;

end;
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:18 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.