In symmetric key encryption, an encryption key is used to encrypt plaintext into ciphertext, and decrypt ciphertext to plaintext. The more keys we have, the longer it will take, on average, to find the correct key. For example, if we have a 4-bit value, we will have \(2^4\) keys (16). Overall, the number of encryption keys will be \(2^n\). If we try \(M\) keys per second, then the average time to crack by brute force will be \( \frac{2^n}{2.M}\) seconds. This outlines a calculation for an average time to decrypt a message with certain sizes of encryption keys. If we have a 36-bit key, we then have 3,668,719,476,736 (\(2^{36}\) keys), and if we can try 10 billion keys (\(10 \times 10^9\)) keys per second, it will take 3.44 seconds on average to find the correct key. We will compute the time to crack using a different number of processing elements.
Encryption Keys |
Code Outline
public void genkeytable(string n) { if (n == null) return; float val = System.Convert.ToInt32(n); double t = 1 / (double)val; List<encryptionkeys> l = new List<encryptionkeys>(); for (int i = 2; i < 73; i+=2) { encryptionkeys e = new encryptionkeys(); e.value = Convert.ToString(i); long key = (long)Math.Pow(2, i); e.result = key.ToString("##,0"); double timet = (key * t); string unit = ""; if (i > 62) { Org.BouncyCastle.Math.BigInteger n1 = new Org.BouncyCastle.Math.BigInteger(n); Org.BouncyCastle.Math.BigInteger b = new Org.BouncyCastle.Math.BigInteger("2"); Org.BouncyCastle.Math.BigInteger c = b.Pow(i); Org.BouncyCastle.Math.BigInteger time = c.Divide(n1); string s1 = c.ToString(); e.result = InsertComma(s1); timet = Convert.ToDouble(time.ToString()); } timet = timet / 2; // Calculate average time if (timet < 1e-6) { unit = " ns"; timet = timet / 1e-6; } else if (timet < 1e-3) { unit = " μs"; timet = timet / 1e-6; } else if (timet < 1) { unit = " ms"; timet = timet / 1e-3; } else if (timet < 60) { unit = " sec"; timet = timet; } else if (timet < 3600) { unit = " min"; timet = timet / 60; } else if (timet < 3600 * 24) { unit = " hr"; timet = timet / 60 / 60; } else if (timet < (3600 * 24 * 356)) { unit = " days"; timet = timet / 60 / 60 / 24; } else { unit = " years"; timet = timet / 60 / 60 / 24 / 365; } e.timetaken_4 = (timet / 4).ToString("##,0.00") + " " + unit; e.timetaken_256 = (timet / 256).ToString("##,0.00") + " " + unit; e.timetaken_16 = (timet / 16).ToString("##,0.00") + " " + unit; e.timetaken_1024 = (timet / 1024).ToString("##,0.00") + " " + unit; e.timetaken = (timet).ToString("##,0.00") + " " + unit; l.Add(e); } ViewData["data"] = l; }