Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Org.BouncyCastle.Math;
- using Org.BouncyCastle.Security;
- using System;
- namespace CryptoTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Calculating a 1024-bits primenumber for key 1");
- BigInteger prime = GenPrime2(1024);
- Console.WriteLine("Found a prime: " + prime.ToString());
- Console.WriteLine("Running calculations to make sure this is a prime...");
- bool probablePrime = prime.IsProbablePrime(100);
- Console.WriteLine("Calculation completed. Is prime: " + probablePrime.ToString());
- if (probablePrime)
- {
- Console.WriteLine("Calculating a 1024-bits primenumber for key 2");
- BigInteger prime2 = GenPrime2(1024);
- Console.WriteLine("Found a prime: " + prime.ToString());
- Console.WriteLine("Running calculations to make sure this is a prime...");
- probablePrime = prime2.IsProbablePrime(100);
- Console.WriteLine("Calculation completed. Is prime: " + probablePrime.ToString());
- if (probablePrime)
- {
- Console.WriteLine("Both keys are prime numbers, concentrating them to make a 2048-bit key");
- BigInteger key = new BigInteger(prime.ToString() + prime2.ToString());
- Console.WriteLine("Key forged: " + key.ToString());
- } else {
- Console.WriteLine("Could not find prime for key 2");
- }
- } else {
- Console.WriteLine("Could not find a prime for key 1");
- }
- // Just read to make sure console doesn't close
- Console.Read();
- }
- static public BigInteger GenPrime2(int bits)
- {
- SecureRandom ran = new SecureRandom();
- BigInteger c = new BigInteger(bits, ran);
- for (; ; )
- {
- if (c.IsProbablePrime(1) == true) break;
- c = c.Subtract(new BigInteger("1"));
- }
- return (c);
- }
- }
- }
Add Comment
Please, Sign In to add comment