Skip to content

Dealing with float numbers #75

@SpBossGui

Description

@SpBossGui

I wonder whether it has the ability to deal with float numbers. Actually I run alternative_base.py in examples folder and changed the values of a and b to float numbers and it turned to be a failure to deal with it. Did I make any mistakes or could it really not? Thank you for answering my questions!

def math_example():
    print("Encoding two large positive numbers. BASE={}".format(ExampleEncodedNumber.BASE))

    a = 0.5
    b = 0.2

    encoded_a = ExampleEncodedNumber.encode(public_key, a)
    encoded_b = ExampleEncodedNumber.encode(public_key, b)

    print("Checking that decoding gives the same number...")
    assert a == encoded_a.decode()
    assert b == encoded_b.decode()

    print("Encrypting the encoded numbers")
    encrypted_a = public_key.encrypt(encoded_a)
    encrypted_b = public_key.encrypt(encoded_b)

    print("Adding the encrypted numbers")
    encrypted_c = encrypted_a + encrypted_b

    print("Decrypting the one encrypted sum")
    decrypted_but_encoded = \
        private_key.decrypt_encoded(encrypted_c, ExampleEncodedNumber)

    print("Checking the decrypted number is what we started with")

    print("Decrypted: {}".format(decrypted_but_encoded.decode()))

Generating paillier keypair
Encoding a large positive number. With a BASE 64 encoding scheme
Checking that decoding gives the same number...
Encrypting the encoded number
Decrypting...
Checking the decrypted number is what we started with
Encoding two large positive numbers. BASE=64
Checking that decoding gives the same number...
Encrypting the encoded numbers
Adding the encrypted numbers
Decrypting the one encrypted sum
Checking the decrypted number is what we started with
Decrypted: 0.325

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions