private void GenerateHash()
{
// Make sure the input is not empty.
if (HashInput.Text.Length > 0)
{
// Convert \ to /
string hashInput = HashInput.Text.Replace(@"\", "/");
HashInput.Text = hashInput;
string hashString;
if (HashTypeList.SelectedIndex == 0)
{
hashString = ByteConverter.ByteArrayToString(HashFNV1.Hash(hashInput));
}
else
{
hashString = ByteConverter.ByteArrayToString(HashFNV1A.Hash(hashInput));
}
if (OutputAsHex.Checked)
{
HashResult.Text = hashString;
}
else
{
try
{
// Convert to UInt64
byte[] byteArray = HashFNV1A.Hash(hashInput);
if (BitConverter.IsLittleEndian)
Array.Reverse(byteArray);
ulong ulongValue = Convert.ToUInt64(hashString, 16);
HashResult.Text = ulongValue.ToString();
}
catch (OverflowException)
{
Console.WriteLine("Unable to convert '{0}' to an unsigned long integer.", hashString);
}
catch (FormatException)
{
Console.WriteLine("'{0}' is not in the correct format.", hashString);
}
}
}
}
private void GenerateHash()
{
// Make sure the input is not empty.
if (HashInput.Text.Length > 0)
{
// Convert \ to /
string hashInput = HashInput.Text.Replace(@"\", "/");
HashInput.Text = hashInput;
string hashString;
if (HashTypeList.SelectedIndex == 0)
{
hashString = ByteConverter.ByteArrayToString(HashFNV1.Hash(hashInput));
}
else
{
hashString = ByteConverter.ByteArrayToString(HashFNV1A.Hash(hashInput));
}
if (OutputAsHex.Checked)
{
HashResult.Text = hashString;
}
else
{
try
{
// Convert to UInt64
byte[] byteArray = HashFNV1A.Hash(hashInput);
if (BitConverter.IsLittleEndian)
Array.Reverse(byteArray);
ulong ulongValue = Convert.ToUInt64(hashString, 16);
HashResult.Text = ulongValue.ToString();
}
catch (OverflowException)
{
Console.WriteLine("Unable to convert '{0}' to an unsigned long integer.", hashString);
}
catch (FormatException)
{
Console.WriteLine("'{0}' is not in the correct format.", hashString);
}
}
}
}