示例#1
0
def test_fv_add_plain_plain(int1, int2):
    ctx = Context(EncryptionParams(64,
                                   CoeffModulus().create(64, [30, 30]), 64))
    encoder = IntegerEncoder(ctx)
    evaluator = Evaluator(ctx)
    op1 = encoder.encode(int1)
    op2 = encoder.encode(int2)
    assert (int1 + int2 == encoder.decode(evaluator._add_plain_plain(op1, op2))
            == encoder.decode(evaluator.add(op1, op2)) == encoder.decode(
                evaluator.add(op2, op1)))
示例#2
0
def test_fv_add_cipher_cipher(int1, int2):
    ctx = Context(EncryptionParams(64,
                                   CoeffModulus().create(64, [30, 30]), 64))
    keys = KeyGenerator(ctx).keygen()
    encoder = IntegerEncoder(ctx)
    encryptor = Encryptor(ctx, keys[1])  # keys[1] = public_key
    decryptor = Decryptor(ctx, keys[0])  # keys[0] = secret_key
    evaluator = Evaluator(ctx)

    op1 = encryptor.encrypt(encoder.encode(int1))
    op2 = encryptor.encrypt(encoder.encode(int2))
    assert (int1 + int2 == encoder.decode(
        decryptor.decrypt(evaluator._add_cipher_cipher(op1, op2))) ==
            encoder.decode(decryptor.decrypt(evaluator.add(op1, op2))) ==
            encoder.decode(decryptor.decrypt(evaluator.add(op2, op1))))