Beispiel #1
0
        public void TestNegativeCases()
        {
            {
                var algorithm = new Paillier
                {
                    KeySize = 384
                };

                //Test negative number
                var z           = new BigInteger(8);
                var z_enc_bytes = algorithm.EncryptData(z);
                var z_dec       = algorithm.DecryptData(z_enc_bytes);
                Assert.Equal(z, z_dec);

                //Test positive number
                var z_2           = new BigInteger(10);
                var z_enc_bytes_2 = algorithm.EncryptData(z_2);
                var z_dec_2       = algorithm.DecryptData(z_enc_bytes_2);
                Assert.Equal(z_2, z_dec_2);

                //Test addition of positive and negative numbers
                var z_enc_addition = algorithm.Addition(z_enc_bytes, z_enc_bytes_2);
                var z_addition     = algorithm.DecryptData(z_enc_addition);
                Assert.Equal(z + z_2, z_addition);

                //Test subtraction of positive and negative numbers
                var z_enc_subtraction = algorithm.Subtraction(z_enc_bytes, z_enc_bytes_2);
                var z_subtraction     = algorithm.DecryptData(z_enc_subtraction);
                Assert.Equal(z - z_2, z_subtraction);

                algorithm.Dispose();
            }
        }