Exemplo n.º 1
0
        /// <summary>
        /// Generates and stores prime and safe prime.
        /// </summary>
        /// <param name="dataPath">Path where application data is stored.</param>
        /// <param name="feedback">Feedback delegate or null.</param>
        public static void GenerateAndStoreSafePrime(string dataPath, PrimeGenerationFeedBack feedback)
        {
            BigInt prime = null;
              BigInt safePrime = null;

              Prime.FindPrimeAndSafePrimeThreaded(4096, out prime, out safePrime, feedback);

              string fileName = Path.Combine(dataPath, string.Format(Files.SafePrimeFileString, DateTime.Now.Ticks));
              FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write);
              SerializeContext context = new SerializeContext(file);

              context.Write(prime);
              context.Write(safePrime);

              context.Close();
              file.Close();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new generator.
 /// </summary>
 /// <param name="feedback">Feedback delegate or null.</param>
 public ThreadedPrimeGenerator(PrimeGenerationFeedBack feedBack)
 {
     this.feedBack = feedBack;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Finds both as prime and a larger safe prime.
 /// </summary>
 /// <param name="bitLength">Length in bits of the prime.</param>
 /// <param name="prime">Random prime number.</param>
 /// <param name="safePrime">Random safe prime number.</param>
 /// <param name="feedback">Feedback delegate or null.</param>
 public static void FindPrimeAndSafePrimeThreaded(int bitLength, out BigInt prime, out BigInt safePrime, PrimeGenerationFeedBack feedback)
 {
     ThreadedPrimeGenerator generator = new ThreadedPrimeGenerator(feedback);
       generator.FindPrimeAndSafePrime(bitLength, out prime, out safePrime);
 }