示例#1
0
        public void TestSafeIntEncryptionMinPlusTwo()
        {
            int initial        = FPEWrapper.MinAllowedSafeInt + 2;
            var encryptedValue = FPEWrapper.EncryptSafeInt(key, tweak, initial);
            var decryptedValue = FPEWrapper.DecryptSafeInt(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
示例#2
0
        public void TestSafeIntEncryptionMinusOne()
        {
            int initial        = -1;
            var encryptedValue = FPEWrapper.EncryptSafeInt(key, tweak, initial);
            var decryptedValue = FPEWrapper.DecryptSafeInt(key, tweak, encryptedValue);

            Assert.AreEqual(initial, decryptedValue);
        }
示例#3
0
        public void StressTestSafeIntEncryption()
        {
            Random r     = new Random();
            int    times = 10000;

            for (int i = 0; i < times; i++)
            {
                int plain          = r.Next(FPEWrapper.MinAllowedSafeInt, FPEWrapper.MaxAllowedSafeInt);
                var encryptedValue = FPEWrapper.EncryptSafeInt(key, tweak, plain);
                var decryptedValue = FPEWrapper.DecryptSafeInt(key, tweak, encryptedValue);
                Console.WriteLine($"Src:{plain}, Dest:{decryptedValue}");
                Assert.AreEqual(plain, decryptedValue);
            }
        }