Esempio n. 1
0
        public void RSANumberEncryptionTest(int encrypted, int publicKey, int commonKey, int message)
        {
            // private key = -1, we won't need it for encryption!
            var rsaKey = new RivestShamirAdleman(-1, publicKey, commonKey);

            Assert.AreEqual(new BigInteger(encrypted), rsaKey.Encrypt(message));
        }
Esempio n. 2
0
        public void RSANumberDecryptionTest(int message, int privateKey, int commonKey, int encrypted)
        {
            // public key = -1, we won't need it for decryption!
            var rsaKey = new RivestShamirAdleman(privateKey, -1, commonKey);

            Assert.AreEqual(new BigInteger(message), rsaKey.Decrypt(encrypted));
        }
Esempio n. 3
0
 public void PrimeGenerationTest()
 {
     Assert.AreEqual(new List <BigInteger> {
         2, 3, 5, 7, 11, 13, 17, 19
     },
                     RivestShamirAdleman.GenerateListOfPrimes(20));
 }
Esempio n. 4
0
        public void RSATest()
        {
            var rsaKey = new RivestShamirAdleman();

            TestContext.WriteLine(
                $"privateKey: {rsaKey.PrivateKey}, publicKey: {rsaKey.PublicKey}, commonKey: {rsaKey.CommonKey}");

            var encrypted = rsaKey.Encrypt("topSecret123");

            TestContext.WriteLine(encrypted);
            Assert.AreEqual("topSecret123", rsaKey.Decrypt(encrypted));
        }
Esempio n. 5
0
 // TODO Fix RSA algorithm for longer numbers
 // [TestCase(7)]
 // [TestCase(8)]
 // [TestCase(9)]
 // [TestCase(10)]
 // [TestCase(20)]
 // [TestCase(100)]
 public void RSAKeyPairGenerationTest(int messageLength)
 {
     for (var i = 0; i < 5; i++)
     {
         var rsaKey = new RivestShamirAdleman();
         for (var j = 0; j < 10; j++)
         {
             var number    = BigInteger.Parse(GenerateRandomNumberString(messageLength));
             var encrypted = rsaKey.Encrypt(number);
             var decrypted = rsaKey.Decrypt(encrypted);
             TestContext.WriteLine(
                 $"privateKey: {rsaKey.PrivateKey}, publicKey: {rsaKey.PublicKey}, commonKey: {rsaKey.CommonKey}");
             TestContext.WriteLine($"input: {number}, encrypted: {encrypted}, decrypted: {decrypted}");
             Assert.AreEqual(number, decrypted);
         }
     }
 }
Esempio n. 6
0
 public void ModularMultiplicativeInverseTest(string expected, string a, string m)
 {
     Assert.AreEqual(BigInteger.Parse(expected),
                     RivestShamirAdleman.ModularMultiplicativeInverse(BigInteger.Parse(a), BigInteger.Parse(m)));
 }
Esempio n. 7
0
 public void LeastCommonMultipleTest(string expected, string a, string b)
 {
     Assert.AreEqual(BigInteger.Parse(expected),
                     RivestShamirAdleman.LeastCommonMultiple(BigInteger.Parse(a), BigInteger.Parse(b)));
 }
Esempio n. 8
0
 public void GreatestCommonDivisorTest(string expected, string a, string b)
 {
     Assert.AreEqual(BigInteger.Parse(expected),
                     RivestShamirAdleman.GreatestCommonDivisor(BigInteger.Parse(a), BigInteger.Parse(b)));
 }