test
2008-04-07 17:39:18 UTC
Hi,
I'm getting a MD4 hash which is stored as either 4 unsigned
ints or a string
typedef unsigned LongWord; // 0..4294967295
typedef System::StaticArray<LongWord, 4> T4x4LongWordRecord;
T4x4LongWordRecord
or
AnsiString (Hex format)
I need to put this hash/hash string into a 16 byte array but am
clueless as to where to start.
I have a few other hashes that I get from 16 byte arrays using
the following functions
byte* buf11 = new byte[16];
ReadFile(fl, buf11, 16);
AnsiString Hash = byteHashToString(buf11, 16);
...
long __fastcall TForm1::byteToLong(byte* number, byte size)
{
long retorno = 0;
for(int i=0;i<size;i++)
{
if(number[i]>=0)
retorno += (number[i]*pow(256,i));
else
retorno += ((256+number[i])*pow(256,i));
}
return retorno;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TForm1::byteHashToString(byte* temp, byte size)
{
AnsiString retorno = "";
AnsiString tempStr = "";
byte* pedacito = new byte[1];
for(int i=0;i<size;i++)
{
pedacito[0] = temp[i];
tempStr = IntToHex((int)byteToLong(pedacito, 1), 2);
if (tempStr.Length()<2)
retorno += "0" + tempStr;
else
retorno += tempStr;
}
delete [] pedacito;
return retorno;
}
Can someone point me in the right direction please...
Thanks
I'm getting a MD4 hash which is stored as either 4 unsigned
ints or a string
typedef unsigned LongWord; // 0..4294967295
typedef System::StaticArray<LongWord, 4> T4x4LongWordRecord;
T4x4LongWordRecord
or
AnsiString (Hex format)
I need to put this hash/hash string into a 16 byte array but am
clueless as to where to start.
I have a few other hashes that I get from 16 byte arrays using
the following functions
byte* buf11 = new byte[16];
ReadFile(fl, buf11, 16);
AnsiString Hash = byteHashToString(buf11, 16);
...
long __fastcall TForm1::byteToLong(byte* number, byte size)
{
long retorno = 0;
for(int i=0;i<size;i++)
{
if(number[i]>=0)
retorno += (number[i]*pow(256,i));
else
retorno += ((256+number[i])*pow(256,i));
}
return retorno;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TForm1::byteHashToString(byte* temp, byte size)
{
AnsiString retorno = "";
AnsiString tempStr = "";
byte* pedacito = new byte[1];
for(int i=0;i<size;i++)
{
pedacito[0] = temp[i];
tempStr = IntToHex((int)byteToLong(pedacito, 1), 2);
if (tempStr.Length()<2)
retorno += "0" + tempStr;
else
retorno += tempStr;
}
delete [] pedacito;
return retorno;
}
Can someone point me in the right direction please...
Thanks