Open sandeephr opened 5 years ago
Hello! The Damgard-Jurik library is designed to encrypt Python integers rather than strings, but you can certainly tranform a string into a list of integers and then encrypt that list. An example of this would be:
from damgard_jurik import keygen
public_key, private_key_ring = keygen(
n_bits=64,
s=1,
threshold=3,
n_shares=3
)
text = "String to Encrypt"
msg_list = list(map(int, text))
cipher_list = public_key.encrypt_list(msg_list)
Cheers!
In order to make this as easy as possible, perhaps we should extend the library to allow the encryption of strings. @swansonk14 can you think of any reason not to overload the generic encryption function with different behaviors for different arg types? If not, I'm happy to branch off and PR.
I think it should definitely be possible to extend the encryption/decryption functions to handle different data types. I'll try to implement this functionality sometime this week.
@nickboucher I got an error when I tried running your code .........but replacing "int" with "ord" solved that error. but I got an output which prints [mpz(83), mpz(116), mpz(114), mpz(105), mpz(110), mpz(103), mpz(32), mpz(116), mpz(111), mpz(32), mpz(69), mpz(110), mpz(99), mpz(114), mpz(121), mpz(112), mpz(116)]
I think that's the ASCII value of each word I guess but what does mpz mean.
@sandeephr mpz
is an arbitrary-precision integer. Once you have the string encoded in a numerical format you should be able to use the library as expected!
We'll release a wrapper around this within the package soon.
ok sir thank you
I have two questions
@sandeephr You can certainly look inside the key objects and see the underlying data. Check the __dict__
attribute on the relevant objects for the available properties. You can encrypt any file that you would like, but using homomorphic encryption on anything other than integers is probably not worth the performance hit over regular encryption methods, unless you can come up with a good reason that you need homomorphic properties on the other data. To encrypt an arbitrary file type, you could just interpret the binary encoding of the file as a list of integers and encode that list.
@swansonk14 I created a branch with a wrapper for string encryption. Originally I thought that it would be nice to just overload the encrypt
function to support different data types, but ultimately I thought that was probably a bad idea because the plaintext data type would become less apparent with a generic decrypt method. Curious on your thoughts as well.
In the meantime, I'll make a PR and request your review! :)
I need to perform homomorphic encryption on my files such as text pdf and few more can I do it in homomorphic encryption similar to AES and DES