key strength

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 16
Reputation: Lolalola is an unknown quantity at this point 
Solved Threads: 0
Lolalola Lolalola is offline Offline
Newbie Poster

key strength

 
0
  #1
16 Days Ago
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:
  1. 01.x = ( (((UInt64)block[0]) << 56) | (((UInt64)block[1]) << 48) |
  2. 02. (((UInt64)block[2]) << 40) | (((UInt64)block[3]) << 32) |
  3. 03. (((UInt64)block[4]) << 24) | (((UInt64)block[5]) << 16) |
  4. 04. (((UInt64)block[6]) << 8) | ((UInt64)block[7])
  5. 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


  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. byte[] sec_key = System.Text.Encoding.UTF8.GetBytes(textBox1.Text);
  4. if (IsWeakKey(sec_key)) { label1.Text = "Yes"; }
  5. else { label1.Text = "No"; }
  6. }
  7.  
  8. private static bool IsLegalKeySize(byte[] sec_key) {
  9. if (sec_key.Length == 8) return(true);
  10. return(false);
  11. }
  12.  
  13. private static UInt64 QuadWordFromBigEndian(byte[] block)
  14. {
  15. UInt64 x;
  16. x = (
  17. (((UInt64)block[0]) << 56) | (((UInt64)block[1]) << 48) |
  18. (((UInt64)block[2]) << 40) | (((UInt64)block[3]) << 32) |
  19. (((UInt64)block[4]) << 24) | (((UInt64)block[5]) << 16) |
  20. (((UInt64)block[6]) << 8) | ((UInt64)block[7])
  21. );
  22. return (x);
  23. }
  24.  
  25. public static bool IsWeakKey(byte[] sec_key)
  26. {
  27.  
  28. UInt64 key = QuadWordFromBigEndian(sec_key);
  29. if ((key == 0x0101010101010101) ||
  30. (key == 0xfefefefefefefefe) ||
  31. (key == 0x1f1f1f1f0e0e0e0e) ||
  32. (key == 0xe0e0e0e0f1f1f1f1))
  33. {
  34. return (true);
  35. }
  36. else
  37. {
  38. return (false);
  39. }
  40. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 91
Reputation: thines01 is an unknown quantity at this point 
Solved Threads: 8
thines01 thines01 is offline Offline
Junior Poster in Training
 
0
  #2
15 Days Ago
Have you ensured the length of the data you're feeding to QuadWordFromBigEndian is 8 (or more) bytes?
...Either by forcing the call to IsLegalKeySize() or by running it in Debug mode with an assert...

  1. private static UInt64 QuadWordFromBigEndian(byte[] block)
  2. {
  3. System.Diagnostics.Debug.Assert(block.Length.Equals(8));
  4.  
  5. UInt64 x;
  6. x = (
  7. (((UInt64)block[0]) << 56) | (((UInt64)block[1]) << 48) |
  8. (((UInt64)block[2]) << 40) | (((UInt64)block[3]) << 32) |
  9. (((UInt64)block[4]) << 24) | (((UInt64)block[5]) << 16) |
  10. (((UInt64)block[6]) << 8) | ((UInt64)block[7])
  11. );
  12.  
  13. return (x);
  14. }

Then test it with something like this:
  1. static void Main(string[] args)
  2. {
  3. byte[] block = {2,2,2,2,2,2,2,2};
  4. UInt64 x = QuadWordFromBigEndian(block);
  5. System.Diagnostics.Trace.WriteLine(x);
  6. }
Last edited by thines01; 15 Days Ago at 9:50 am. Reason: omission
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 16
Reputation: Lolalola is an unknown quantity at this point 
Solved Threads: 0
Lolalola Lolalola is offline Offline
Newbie Poster
 
0
  #3
15 Days Ago
Thanks, I did not know that the minutes should 8 bytes.

But if I put sec_key = "AAAAbbbb"; and "asdr34bf" i have answer
same. Why?
I sting convert to bytes[]. (byte[] sec_key = System.Text.Encoding.UTF8.GetBytes(textBox1.Text)
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC