Guest User

Untitled

a guest
Feb 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. using Org.BouncyCastle.Math;
  2. using Org.BouncyCastle.Security;
  3. using System;
  4.  
  5. namespace CryptoTest
  6. {
  7. class Program
  8. {
  9.  
  10. static void Main(string[] args)
  11. {
  12. Console.WriteLine("Calculating a 1024-bits primenumber for key 1");
  13.  
  14. BigInteger prime = GenPrime2(1024);
  15. Console.WriteLine("Found a prime: " + prime.ToString());
  16.  
  17. Console.WriteLine("Running calculations to make sure this is a prime...");
  18. bool probablePrime = prime.IsProbablePrime(100);
  19.  
  20. Console.WriteLine("Calculation completed. Is prime: " + probablePrime.ToString());
  21.  
  22. if (probablePrime)
  23. {
  24. Console.WriteLine("Calculating a 1024-bits primenumber for key 2");
  25.  
  26. BigInteger prime2 = GenPrime2(1024);
  27. Console.WriteLine("Found a prime: " + prime.ToString());
  28.  
  29. Console.WriteLine("Running calculations to make sure this is a prime...");
  30. probablePrime = prime2.IsProbablePrime(100);
  31.  
  32. Console.WriteLine("Calculation completed. Is prime: " + probablePrime.ToString());
  33.  
  34. if (probablePrime)
  35. {
  36. Console.WriteLine("Both keys are prime numbers, concentrating them to make a 2048-bit key");
  37. BigInteger key = new BigInteger(prime.ToString() + prime2.ToString());
  38.  
  39. Console.WriteLine("Key forged: " + key.ToString());
  40. } else {
  41. Console.WriteLine("Could not find prime for key 2");
  42. }
  43. } else {
  44. Console.WriteLine("Could not find a prime for key 1");
  45. }
  46.  
  47.  
  48. // Just read to make sure console doesn't close
  49. Console.Read();
  50. }
  51.  
  52. static public BigInteger GenPrime2(int bits)
  53. {
  54. SecureRandom ran = new SecureRandom();
  55.  
  56. BigInteger c = new BigInteger(bits, ran);
  57.  
  58. for (; ; )
  59. {
  60. if (c.IsProbablePrime(1) == true) break;
  61.  
  62. c = c.Subtract(new BigInteger("1"));
  63. }
  64. return (c);
  65. }
  66. }
  67. }
Add Comment
Please, Sign In to add comment