Hi,
I'm trying to create a program which provides a key strength. Visual studio don't show errors, but the program hangs on QuadWordFromBigEndian functions. Whats wrong?
Program stop workin on this line:
01.x = ( (((UInt64)block[0]) << 56) | (((UInt64)block[1]) << 48) |
02. (((UInt64)block[2]) << 40) | (((UInt64)block[3]) << 32) |
03. (((UInt64)block[4]) << 24) | (((UInt64)block[5]) << 16) |
04. (((UInt64)block[6]) << 8) | ((UInt64)block[7])
05. );
An show this error:
"Index was outside the bounds of the array."
But I do not know how to fix. What should be the array index.
Thanks
private void button1_Click(object sender, EventArgs e)
{
byte[] sec_key = System.Text.Encoding.UTF8.GetBytes(textBox1.Text);
if (IsWeakKey(sec_key)) { label1.Text = "Yes"; }
else { label1.Text = "No"; }
}
private static bool IsLegalKeySize(byte[] sec_key) {
if (sec_key.Length == 8) return(true);
return(false);
}
private static UInt64 QuadWordFromBigEndian(byte[] block)
{
UInt64 x;
x = (
(((UInt64)block[0]) << 56) | (((UInt64)block[1]) << 48) |
(((UInt64)block[2]) << 40) | (((UInt64)block[3]) << 32) |
(((UInt64)block[4]) << 24) | (((UInt64)block[5]) << 16) |
(((UInt64)block[6]) << 8) | ((UInt64)block[7])
);
return (x);
}
public static bool IsWeakKey(byte[] sec_key)
{
UInt64 key = QuadWordFromBigEndian(sec_key);
if ((key == 0x0101010101010101) ||
(key == 0xfefefefefefefefe) ||
(key == 0x1f1f1f1f0e0e0e0e) ||
(key == 0xe0e0e0e0f1f1f1f1))
{
return (true);
}
else
{
return (false);
}
}