Example #1
0
        public string encrypt(int p, int q, string x)
        {
            int n  = p * q;
            int fi = (q - 1) * (p - 1);
            int e  = 2;

            while (e < fi)
            {
                if (DBD(e, fi) == 1)
                {
                    break;
                }
                else
                {
                    e++;
                }
            }
            string encrypted = "";

            foreach (char c in x.ToCharArray())
            {
                encrypted += $"{Convert.ToString((Int32)BigInteger.ModPow(c,e,n))},";
            }
            encrypted = encrypted.Remove(encrypted.Length - 1);
            EncryptedModel model = new EncryptedModel();

            model.e = e;
            model.n = n;
            model.y = encrypted;
            DataBase.SaveEncrypted(model);
            return(encrypted);
        }
Example #2
0
 public static void SaveEncrypted(EncryptedModel model)
 {
     using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
     {
         cnn.Execute("insert into Data (y, n, e) values (@y, @n, @e)", model);
     }
 }
Example #3
0
 private void rBtnEncrypt_Checked(object sender, RoutedEventArgs e)
 {
     updateButton();
     tBxInputP.Text         = "";
     tBxInputQ.Text         = "";
     tBxInputText.Text      = "";
     selectedModel          = null;
     gridEncrypt.Visibility = Visibility.Visible;
     gridDecrypt.Visibility = Visibility.Collapsed;
 }
Example #4
0
        public string decrypt(EncryptedModel model)
        {
            int[]  encrypted = Array.ConvertAll(model.y.Split(','), int.Parse);
            string decrypted = "";

            foreach (int i in encrypted)
            {
                int temp3 = phi(model.n);
                int temp2 = IEA(model.e, temp3);
                int temp  = (Int32)BigInteger.ModPow(i, temp2, model.n);
                decrypted += Convert.ToChar(temp);
            }
            return(decrypted);
        }
Example #5
0
 private void setModel(EncryptedModel model)
 {
     selectedModel = model;
     updateList();
     updateButton();
 }