Ejemplo n.º 1
0
        public string Decrypt(string p_strMsg)
        {
            string str  = p_strMsg;
            string Text = "";

            while (str.Length % 3 != 0)
            {
                str += " ";
            }

            //   int index = 0;
            for (int i = 0; i < str.Length; i++)
            {
                if (((i) % 3) == 0)
                {
                    //HillCipher m_objCipher = ciphers[index++];
                    HillCipher m_objCipher = new HillCipher();
                    char[]     ch          = new char[3];

                    ch = str.ToCharArray(i, 3);
                    string ThreeCharString = new string(ch);

                    //Text += m_objCipher.decryption(ThreeCharString);
                    //                    MessageBox.Show("Original = " + ThreeCharString + "\n" + "Cipher = " + m_objCipher.encryption() + "\n" + "Decrypted = " + m_objCipher.decryption());
                    Text += m_objCipher.de(ThreeCharString);
                }
            }
            return(Text);
        }
Ejemplo n.º 2
0
        public string Encrypt(string p_strMsg)
        {
            string str    = p_strMsg;
            string cipher = "";

            while (str.Length % 3 != 0)
            {
                str += "{";
            }

            //  ciphers.Clear();
            for (int i = 0; i < str.Length; i++)
            {
                if (((i) % 3) == 0)
                {
                    HillCipher m_objCipher = new HillCipher();
                    char[]     ch          = new char[3];
                    ch = str.ToCharArray(i, 3);
                    string ThreeCharString = new string(ch);
                    m_objCipher.SetString(ThreeCharString);
//                    cipher += m_objCipher.encryption();
                    //        ciphers.Add(m_objCipher);
                    cipher += m_objCipher.encryption();
                    //m_objCipher.de(en);
                    // MessageBox.Show("Original = " + ThreeCharString + "\n" + "Cipher = " +en + "\n" + "Decrypted = ");
                }
            }
            return(cipher);
        }