<commit_before># Project modules
import symmetric
from config import *

# Python modules
import numpy as np


def keygen():
    """Generate private and public keys."""

    # Generate regular secret key
    sk = symmetric.keygen()

    # Generate a set of encryptions of zero
    pk = [symmetric.encrypt(sk, 0, PK_M_BIT_LENGTH) for i in range(PK_SIZE)]

    return (sk, pk)


def encrypt(pk, b):
    """Encrypt a bit b into an integer based on a public key."""

    # Choose a random subset of the pk's encrypted zeros
    idxs = np.random.choice(np.arange(PK_SIZE), PK_SUBSET_SIZE, replace=False)
    
    # Sum subset of encrypted zeros along with the bit to be encrypted
    cypher = b #cypher = (random.randint(0, 2**(N-1) -1) << 1) + b
    for i in idxs:
        cypher += pk[i]
        
    return cypher


if __name__ == '__main__':

    sk, pk = keygen()
    assert symmetric.decrypt(sk, encrypt(pk, 0)) == 0
    assert symmetric.decrypt(sk, encrypt(pk, 1)) == 1

    from testing import consistency

    def keygenEncryptDecrypt(b):
        """asymmetric keygen-encrypt-decrypt (bit = {0})"""
        sk, pk = keygen()
        c = encrypt(pk, b)<commit_msg>Simplify encryption summation<commit_after># Project modules
import symmetric
from config import *

# Python modules
import numpy as np


def keygen():
    """Generate private and public keys."""

    # Generate regular secret key
    sk = symmetric.keygen()

    # Generate a set of encryptions of zero
    pk = [symmetric.encrypt(sk, 0, PK_M_BIT_LENGTH) for i in range(PK_SIZE)]

    return (sk, pk)


def encrypt(pk, b):
    """Encrypt a bit b into an integer based on a public key."""

    # Choose a random subset of the pk's encrypted zeros
    idxs = np.random.choice(np.arange(PK_SIZE), PK_SUBSET_SIZE, replace=False)
    
    # Sum subset of encrypted zeros along with the bit to be encrypted
    cypher = b + sum([pk[i] for i in idxs])
        
    return cypher


if __name__ == '__main__':

    sk, pk = keygen()
    assert symmetric.decrypt(sk, encrypt(pk, 0)) == 0
    assert symmetric.decrypt(sk, encrypt(pk, 1)) == 1

    from testing import consistency

    def keygenEncryptDecrypt(b):
        """asymmetric keygen-encrypt-decrypt (bit = {0})"""
        sk, pk = keygen()
        c = encrypt(pk, b)
{'fraction_non_alphanumeric': 0.11086765994741454, 'fraction_numerical': 0.007449605609114811, 'mean_word_length': 2.9635416666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '4958268', 'n_tokens_mistral': 787, 'n_tokens_neox': 718, 'n_words': 260}