<jupyter_start><jupyter_text>Testing Individual components of the FV HE scheme<jupyter_code>from syft.frameworks.torch.he.fv.modulus import CoeffModulus
from syft.frameworks.torch.he.fv.encryption_params import EncryptionParams
from syft.frameworks.torch.he.fv.context import Context
from syft.frameworks.torch.he.fv.integer_encoder import IntegerEncoder
from syft.frameworks.torch.he.fv.key_generator import KeyGenerator
from syft.frameworks.torch.he.fv.encryptor import Encryptor
from syft.frameworks.torch.he.fv.decryptor import Decryptor
from syft.frameworks.torch.he.fv.integer_encoder import IntegerEncoder
from syft.frameworks.torch.he.fv.modulus import SeqLevelType<jupyter_output>Falling back to insecure randomness since the required custom op could not be found for the installed version of TensorFlow. Fix this by compiling custom ops. Missing file was '/usr/local/lib/python3.7/site-packages/tf_encrypted/operations/secure_random/secure_random_module_tf_1.15.3.so'
WARNING:tensorflow:From /usr/local/lib/python3.7/site-packages/tf_encrypted/session.py:24: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.<jupyter_text>Keygeneration<jupyter_code>params = EncryptionParams(128, CoeffModulus().create(128, [40, 40]), 1<<7 )
ctx = Context(params)
keygenerator = KeyGenerator(ctx)
sk, pk = keygenerator.keygen()
print(ctx.param.coeff_modulus)

print(len(sk.data))
print('secret key values : ', sk.data)
print(pk.data)
print(pk)
# print('public key values : ', pk.data)<jupyter_output>[[[964174082904, 850373235682, 978379498969, 415843427838, 197659747211, 788758661840, 254126077558, 962698441104, 384316079722, 956718713007, 380903014655, 462528075481, 588725214856, 383566100423, 214941947947, 470777328767, 688802314026, 666238506134, 868269072127, 951257939441, 159888481231, 984731270824, 782293359403, 755546621709, 937370835738, 711424938917, 994413865398, 428401841314, 567961218045, 21738632468, 418716678209, 1099207415623, 11890527895, 199781653947, 962675577524, 971971247693, 1032338459159, 661316426091, 1063787429485, 121079440287, 649300602225, 357295494954, 499784827730, 951207994688, 324165183515, 619877396929, 933098610333, 134911866283, 160367225211, 570634510418, 733905767831, 5652802079, 290234450541, 956336696716, 544996288219, 1055708704002, 1009936743924, 358838787038, 356763748139, 416754947028, 844735155055, 361554955960, 623857055717, 990969550155, 727338050931, 118499549383, 156939576667, 508980251, 226607083954, 622716032650, 472173901339, 10109[...]<jupyter_text>Integer EncoderEncodes Integer values to Plaintext object<jupyter_code>int_encoder = IntegerEncoder(ctx)
plaintext = int_encoder.encode(110)
print(plaintext.data)
# print('plaintext data',plaintext.data)<jupyter_output>[0, 1, 1, 1, 0, 1, 1]<jupyter_text>Decodes back to Integer<jupyter_code>print(int_encoder.decode(plaintext))<jupyter_output>110<jupyter_text>EncrypterEncrypt Plaintext to ciphertext using public_key<jupyter_code>encrypter = Encryptor(ctx, pk)
ciphertext = encrypter.encrypt(plaintext)
print(ciphertext)
print('ciphertext data :', ciphertext.data)
print('len ciphertext data :', len(ciphertext.data))<jupyter_output><syft.frameworks.torch.he.fv.ciphertext.CipherText object at 0x107519250>
ciphertext data : [[[535562519665, 886768163865, 297892494300, 968346898392, 622107070335, 1077884880377, 951678553528, 1059816751518, 335805453222, 233515490532, 480108829678, 765913691467, 787734059567, 552399491757, 313105618767, 719546646087, 375880647827, 628561498084, 621872052923, 156298033504, 328742233978, 900517124627, 756418205127, 1067773700553, 726276195043, 658283421806, 208006187788, 530479422068, 508116688987, 376721035286, 168619123858, 919256582331, 2032498433, 14303017904, 872910166499, 7453438095, 165306555439, 688722768551, 447584282080, 523643842516, 933619798800, 936398277066, 750657280362, 145198170317, 480406164416, 728388214567, 975167998833, 482966255145, 972644821221, 761571587141, 239667697511, 838497808431, 60185415536, 237830496767, 249428061969, 171479677532, 344599941862, 343171956107, 894698793771, 579283532754, 520700104601, 945324622519, 684215805984, 40889135803, 871233450135,[...]<jupyter_text>Encrypt Plaintext to ciphertext using secret_key  DecryptorDecrypt Ciphertext to Plaintext using secret_key<jupyter_code>decrypter = Decryptor(ctx, sk)
result = decrypter.decrypt(ciphertext)
print("len : ",len(result.data))
print(result.data)
print(result)
print(int_encoder.decode(result))
import numpy as np
from numpy.polynomial import polynomial as poly
sk = [[1,1,1],[1,2,3]]
cm = [3,5]
def get_sufficient_sk_power(max_power):
    """Generate an list of secret key polynomial raised to 1...max_power"""
    sk_power = [0] * (max_power)
    for i in range(1, max_power):
        sk_power[i] = [0] * len(cm)  # for every polynomial.

    sk_power[0] = sk

    for i in range(2, max_power+1):
        for j in range(len(cm)):
            sk_power[i-1][j] = poly.polypow(sk[j], i).astype(int).tolist()
    return sk_power
print(get_sufficient_sk_power(1))<jupyter_output>[[[1, 1, 1], [1, 2, 3]]]
{'fraction_non_alphanumeric': 0.10182818950265382, 'fraction_numerical': 0.33418517790446234, 'mean_word_length': 7.895104895104895, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '345987', 'license': 'Apache-2.0', 'n_tokens_mistral': 3077, 'n_tokens_neox': 1975, 'n_words': 368, 'path': 'examples/experimental/FV HE Experimentation.ipynb', 'repo_name': 'jefersonf/PySyft', 'size': '5087'}