private static void PrintAnswer(EncAnswerItem answer)
        {
            Console.WriteLine(string.Empty);
            Console.WriteLine("********* Factors *********");
            //Console.WriteLine($"Factor1:{answer.Factor1}");
            //Console.WriteLine($"Factor2:{answer.Factor2}");
            Console.WriteLine(string.Empty);

            var context           = SEALUtils.GetContext();
            var ciphertextPrime   = SEALUtils.BuildCiphertextFromBase64String(answer.Prime, context);
            var ciphertextFactor1 = SEALUtils.BuildCiphertextFromBase64String(answer.Factor1, context);
            var ciphertextFactor2 = SEALUtils.BuildCiphertextFromBase64String(answer.Factor2, context);
            var publicKey         = SEALUtils.BuildPublicKeyFromBase64String(answer.PublicKey, context);
            var secretKey         = SEALUtils.BuildSecretKeyFromBase64String(answer.SecretKey, context);

            Ciphertext temp       = new Ciphertext();
            Evaluator  _evaluator = new Evaluator(context);
            Encryptor  encryptor  = new Encryptor(context, publicKey);

            _evaluator.Multiply(ciphertextFactor1, ciphertextFactor2, temp);
            var tempstring = SEALUtils.CiphertextToBase64String(temp);

            if (tempstring.Equals(answer.Prime))
            {
                Console.WriteLine("the answer is right!");
            }
            else
            {
                var plain = new Plaintext();
                Console.WriteLine("the answer is wrong");
                Decryptor _decryptor = new Decryptor(context, secretKey);
                _decryptor.Decrypt(ciphertextPrime, plain);
                PrintAnswer(plain.ToString());
                encryptor.Encrypt(plain, temp);
                if (!SEALUtils.CiphertextToBase64String(temp).Equals(SEALUtils.CiphertextToBase64String(ciphertextPrime)))
                {
                    Console.WriteLine(SEALUtils.CiphertextToBase64String(ciphertextFactor2).Substring(0, 100));
                    Console.WriteLine(SEALUtils.CiphertextToBase64String(ciphertextFactor1).Substring(0, 100));
                }
                Console.WriteLine(_decryptor.InvariantNoiseBudget(temp));
                _decryptor.Decrypt(temp, plain);
                PrintAnswer(plain.ToString());
                //_decryptor.Decrypt(ciphertextFactor1, plain);
                //PrintAnswer(plain.ToString());
                //_decryptor.Decrypt(ciphertextFactor2, plain);
                //PrintAnswer(plain.ToString());
            }
        }
Ejemplo n.º 2
0
        public MetricsController()
        {
            // Initialize context
            // Getting context from Commons project
            _sealContext = SEALUtils.GetContext();


            // Initialize key generator and encryptor
            // Initialize key Generator that will be use to get the Public and Secret keys
            _keyGenerator = new KeyGenerator(_sealContext);
            // Initializing encryptor
            _encryptor = new Encryptor(_sealContext, _keyGenerator.PublicKey);

            // Initialize evaluator
            _evaluator = new Evaluator(_sealContext);
        }
Ejemplo n.º 3
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("SEAL LAB");
            Console.WriteLine("Setting up encryption...\n");

            // Add Initialization code here
            _context = SEALUtils.GetContext();

            // Add keys code here
            var keys = await FitnessTrackerClient.GetKeys();

            // Create encryptor

            var publicKey = SEALUtils.BuildPublicKeyFromBase64String(keys.PublicKey, _context);

            _encryptor = new Encryptor(_context, publicKey);


            // Create decryptor
            var secretKey = SEALUtils.BuildSecretKeyFromBase64String(keys.SecretKey, _context);

            _decryptor = new Decryptor(_context, secretKey);


            while (true)
            {
                PrintMenu();
                var option = Convert.ToInt32(Console.ReadLine());

                switch (option)
                {
                case 1:
                    await SendNewRun();

                    break;

                case 2:
                    await GetMetrics();

                    break;
                }
            }
        }
Ejemplo n.º 4
0
 public PrimeController()
 {
     _sealContext  = SEALUtils.GetContext();
     _keyGenerator = new KeyGenerator(_sealContext);
     _encryptor    = new Encryptor(_sealContext, _keyGenerator.PublicKey);
 }