Exemple #1
0
 private void ApplyEuclidAlg()
 {
     using (StreamWriter sw = new StreamWriter(@"Q3.txt"))
     {
         sw.WriteLine("Q3.\n");
         foreach (var pair in PairList)
         {
             sw.WriteLine("GCD({0}, {1}) = {2}", pair[0], pair[1], MathsProcessor.EuclidAlg(pair[0], pair[1]));
         }
     }
 }
Exemple #2
0
        private static long GenerateE(long p, long q)
        {
            //calculate Ф(p,q)
            long phi = (p - 1) * (q - 1);

            // start at p-2
            long candidateE = p - 2;

            while (MathsProcessor.EuclidAlg(candidateE, phi) != 1 && MathsProcessor.PrimeCheck(candidateE) != 1)
            {
                --candidateE;
            }

            return(candidateE);
        }
Exemple #3
0
        private void q3CalcGcdBtn_Click(object sender, EventArgs e)
        {
            try
            {
                long numA = long.Parse(q3EntryATbox.Text);  // error handling
                long numB = long.Parse(q3EntryBTbox.Text);  // -//-

                long gcd = MathsProcessor.EuclidAlg(numA, numB);

                q3GcdOutLabel.Text = "The Greatest Common Divisor of " + numA + " and " + numB + " is " + gcd;
            }
            catch (FormatException fe)
            {
                MessageBox.Show("Wrong or missing input. Please enter a and b in a correct format.");
            }
            catch (OverflowException oe)
            {
                MessageBox.Show("Entered number(s) is too big.");
            }
        }