예제 #1
0
        public void Encrypt()
        {
            UiServices.SetBusyState();
            MatrixND mesMat = new MatrixND(1, 1);

            mesMat[0, 0] = int.Parse(Message);
            Cipher       = LWE.Encrypt(mesMat)[0, 0].ToString();

            Paragraph paragraph = new Paragraph();

            paragraph.Inlines.Add(new Bold(new Underline(new Run("** " + Languages.buttonEncrypt + " **\r\n"))));
            paragraph.Inlines.Add(new Bold(new Run(Languages.labelPlainText)));
            paragraph.Inlines.Add(" " + Message + "\r\n");
            paragraph.Inlines.Add(new Bold(new Run(Languages.labelCiphertext)));
            paragraph.Inlines.Add(" " + Cipher + "\r\n");

            if (History.Document.Blocks.FirstBlock != null)
            {
                History.Document.Blocks.InsertBefore(History.Document.Blocks.FirstBlock, paragraph);
            }
            else
            {
                History.Document.Blocks.Add(paragraph);
            }

            NotifyPropertyChanged("Cipher");
        }
예제 #2
0
 public bool CheckCipherFormat()
 {
     try
     {
         cipher       = new MatrixND(1, 1);
         cipher[0, 0] = Convert.ToDouble(Cipher);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #3
0
        public void GenerateNewLWE(int dim, int q)
        {
            UiServices.SetBusyState();

            LWE = new LWEModel(dim, 1, q, true);
            LWE.GenerateNewRandomVector();

            Paragraph paragraph = new Paragraph();

            paragraph.Inlines.Add(new Bold(new Underline(new Run("** " + Languages.buttonGenerateNewCryptosystem + " **\r\n"))));
            paragraph.Inlines.Add(new Bold(new Run(Languages.labelPrivateKeyS + ":")));
            paragraph.Inlines.Add(" " + LWE.S + "\r\n");
            paragraph.Inlines.Add(new Bold(new Run(Languages.labelPublicKeyA + ":")));
            paragraph.Inlines.Add(" " + LWE.A + "\r\n");
            paragraph.Inlines.Add(new Bold(new Run(Languages.labelAlpha)));
            paragraph.Inlines.Add(" " + Util.FormatDoubleLog(LWE.alpha) + "\r\n");
            paragraph.Inlines.Add(new Bold(new Run(Languages.labelPublicKeyB2 + ":")));
            paragraph.Inlines.Add(" " + LWE.B + "\r\n");
            paragraph.Inlines.Add(new Bold(new Run(Languages.labelModuloQ)));
            paragraph.Inlines.Add(" " + LWE.q + "\r\n");
            paragraph.Inlines.Add(new Bold(new Run(Languages.labelRandomVectorR)));
            paragraph.Inlines.Add(" " + MatrixND.Transpose(LWE.r) + "\r\n");
            paragraph.Inlines.Add(new Bold(new Run(Languages.labelSubsetU)));
            paragraph.Inlines.Add(" " + MatrixND.Transpose(LWE.u) + "\r\n");

            if (History.Document.Blocks.FirstBlock != null)
            {
                History.Document.Blocks.InsertBefore(History.Document.Blocks.FirstBlock, paragraph);
            }
            else
            {
                History.Document.Blocks.Add(paragraph);
            }

            NotifyPropertyChanged("RandomVectorR");
            NotifyPropertyChanged("SubsetU");
        }
예제 #4
0
 public LatticeManualInputView(int newN, int newM, int newMod, MatrixND currentMatrix, bool notAllowDetZero, List <BigInteger> allowedNumbers)
     : this(newN, newM, currentMatrix.ToLatticeND(), false, notAllowDetZero, newMod, allowedNumbers)
 {
 }
예제 #5
0
        public void LWETest()
        {
            //Test for single bit encryption
            //Example taken from my own master thesis (sadly in the absence of an alternative example)

            VectorND[] SVectors =
            {
                new VectorND(new BigInteger[] { 7, 7 })
            };
            LatticeND S = new LatticeND(SVectors, false);

            VectorND[] AVectors =
            {
                new VectorND(new BigInteger[] { 4, 3, 4, 0, 5 }),
                new VectorND(new BigInteger[] { 3, 3, 0, 7, 1 })
            };
            LatticeND A = new LatticeND(AVectors, false);

            VectorND[] eVectors =
            {
                new VectorND(new BigInteger[] { 7, 2, 4, 5, 2 })
            };
            LatticeND e = new LatticeND(eVectors, false);

            const int q   = 9;
            LWEModel  lwe = new LWEModel(S.ToMatrixND(), A.ToMatrixND(), e.ToMatrixND(), q, 1);

            VectorND[] rVectors =
            {
                new VectorND(new BigInteger[] { 1, 1, 0, 0, 0 })
            };
            LatticeND r = new LatticeND(rVectors, false);

            r.Transpose();
            lwe.SetRandomVector(r.ToMatrixND());

            //Cryptosystem correct?
            VectorND[] BVectors =
            {
                new VectorND(new BigInteger[] { 2, 8, 5, 0, 8 })
            };
            LatticeND B = new LatticeND(BVectors, false);

            Assert.AreEqual(B.ToMatrixND().ToString(), lwe.B.ToString());

            //Encryption and decryption correct?
            //Message = 0
            MatrixND messageMatrix = new MatrixND(1, 1);

            messageMatrix[0, 0] = 0;
            MatrixND cipher = lwe.Encrypt(messageMatrix);
            MatrixND expectedCipherMatrix = new MatrixND(1, 1);

            expectedCipherMatrix[0, 0] = 1;
            Assert.AreEqual(cipher.ToString(), expectedCipherMatrix.ToString());
            MatrixND decryptedMessage = lwe.Decrypt(cipher);

            Assert.AreEqual(messageMatrix.ToString(), decryptedMessage.ToString());
            //Message = 1
            messageMatrix[0, 0] = 1;
            cipher = lwe.Encrypt(messageMatrix);
            expectedCipherMatrix[0, 0] = 5;
            Assert.AreEqual(cipher.ToString(), expectedCipherMatrix.ToString());
            decryptedMessage = lwe.Decrypt(cipher);
            Assert.AreEqual(messageMatrix.ToString(), decryptedMessage.ToString());
        }