Esempio n. 1
0
        /// <summary>
        /// Encrypt the selected text file, which is encoded using the unicode charset
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnEncryptText_Click(object sender, EventArgs e)
        {
            n = RSAlgorithm.N(p, q);
            BtnSelectImage.Enabled = false;
            DisableUI();

            //Get running time for encription
            Stopwatch TimerForEncription = new Stopwatch();

            TimerForEncription.Start();
            String encrypted = Encrypt(stringFile, progressBarEnc);

            TimerForEncription.Stop();
            //End running time calculation

            File.WriteAllText(txtSaveCipherAtPath.Text, encrypted);
            MessageBox.Show("Encryption Done");
            BtnSelectImage.Enabled       = true;
            BtnLoadImage.Enabled         = true;
            BtnSaveImageCipherAt.Enabled = true;

            BtnDecryptImage.Enabled            = true;
            BtnSelectDecrytedImagePath.Enabled = true;
            BtnLoadImageCipher.Enabled         = true;
            button10.Enabled        = true;
            BtnEncryptImage.Enabled = true;
            GetRunningTime(TimerForEncription.ElapsedMilliseconds.ToString());
        }
Esempio n. 2
0
        public static object[] PopulateKeys(ulong e, ulong d, ulong p, ulong q, params TextBox[] textBoxes)
        {
            var primes = GeneratePrimes(10000);
            var result = GetTwoPrimes(primes);

            string Prime1 = primes[(int)result[0]].ToString();
            string Prime2 = primes[(int)result[1]].ToString();

            var N = RSAlgorithm
                    .N((ulong)primes[result[0]], (ulong)primes[result[1]]);

            p = Convert.ToUInt64(primes[result[0]]);
            q = Convert.ToUInt64(primes[result[1]]);

            textBoxes[0].Text = Prime1;
            textBoxes[1].Text = Prime2;
            textBoxes[2].Text = N.ToString();

            var phi = RSAlgorithm.Phi(p, q);

            e = RSAlgorithm.Find_E(phi);
            bool flag = false;

            for (ulong j = 1; !flag; j++)
            {
                if ((e * j) % phi == 1)
                {
                    d    = j;
                    flag = true;
                }
            }
            textBoxes[3].Text = e.ToString();
            textBoxes[4].Text = d.ToString();;
            var returnValues = new object[] { p, q, N, e, d };

            return(returnValues);
        }