Пример #1
0
        public String MessageDecryptor(List <string> encryptedSequence, ElGamalBean el)
        {
            Encryptor     encryptor = new Encryptor(el);
            StringBuilder sb        = new StringBuilder();

            foreach (var item in encryptedSequence)
            {
                string[]   aAndB = item.Split('|');
                BigInteger a     = new BigInteger(aAndB[0]);
                BigInteger b     = new BigInteger(aAndB[1]);

                sb.Append(Convert.ToChar(encryptor.Decrypt(a, b)));
            }
            return(sb.ToString());
        }
Пример #2
0
        static void Main(string[] args)
        {
            ElGamalBean el = new ElGamalBean(new BigInteger(9473.ToString()),
                                             new BigInteger(3878.ToString()),
                                             new BigInteger(64.ToString()));



            /*Encryptor encryptor = new Encryptor(el, new BigInteger(9.ToString()));
             * Console.WriteLine(encryptor.GetA());
             * Console.WriteLine( encryptor.GetB());
             * encryptor.Decrypt(encryptor.GetA(), encryptor.GetB());*/
            MessageEncryptor me                = new MessageEncryptor();
            string           message           = "hello";
            List <string>    encryptedSequence = me.EncryptMessage(message, el);


            string decryptedHash = me.MessageDecryptor(encryptedSequence, el);

            Console.WriteLine(decryptedHash);

            MD5.MD5 hash = new MD5.MD5();
            hash.Value = message;
            Console.WriteLine(hash.Value);

            if (decryptedHash == hash.Value)
            {
                Console.WriteLine("all right");
            }
            else
            {
                Console.WriteLine("error");
            }

            Encryptor  e = new Encryptor(el);
            BigInteger a = e.GetA();
            BigInteger b = e.GetNDSAB(new BigInteger("104"));

            Encryptor  encryptor   = new Encryptor(el);
            BigInteger firstCheck  = el.g.ModPow(new BigInteger("104"), el.p);
            BigInteger secondChech = encryptor.GetSecondCheck();
        }
Пример #3
0
        public List <string> EncryptMessage(string message, ElGamalBean el)
        {
            Encryptor encryptor = new Encryptor(el);

            MD5.MD5 hash = new MD5.MD5();
            hash.Value = message;
            List <string> encryptedSequence = new List <string>();

            foreach (char item in hash.Value)
            {
                int messageSymbolAtInt = (int)item;

                StringBuilder aAndB = new StringBuilder();
                aAndB.Append(encryptor.GetA());
                aAndB.Append('|');
                aAndB.Append(encryptor.GetB(new BigInteger(messageSymbolAtInt.ToString())));
                encryptedSequence.Add(aAndB.ToString());
            }

            return(encryptedSequence);
        }
Пример #4
0
 public Encryptor(ElGamalBean bean)
 {
     this.bean = bean;
 }