View Single Post
 
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