<commit_before># Prototype of Multi-secret sharing scheme by Roy & Adhikari
# <NAME> 2016

def is_prime(n):
    if n == 2 or n == 3: return True
    if n < 2 or n%2 == 0: return False
    if n < 9: return True
    if n%3 == 0: return False
    r = int(n**0.5)
    f = 5
    while f <= r:
        print ('\t',f)
        if n%f == 0: return False
        if n%(f+2) == 0: return False
        f +=6
    return True

#def choose_prime(p_size):
    
    
import os # for OS random number generation
from math import log2, floor

k_secrets = 3
s_secrets = [7, 313, 671] # s_i
n_participants = 2
access_structures = [(1,),(2,),(1,2)]

p_size = 2 # bytes

print(access_structures)

# 1. Dealer Phase
## I. Initialization stage
p = int.from_bytes(os.urandom(p_size), byteorder="big")
print(p)
while p <= n_participants or not is_prime(p): # p must be prime, greater than any of secrets and greater than n
    p = int.from_bytes(os.urandom(p_size), byteorder="big")
    print(p)
    
print('[log2(p)]+1 = ', floor(log2(p))+1)

### A collision resistant hash function with variable output length / or set p
<commit_msg>construct variable size hash function from SHA256 and AES-CTR<commit_after># Prototype of Multi-secret sharing scheme by Roy & Adhikari
# <NAME> 2016

def is_prime(n):
    if n == 2 or n == 3: return True
    if n < 2 or n%2 == 0: return False
    if n < 9: return True
    if n%3 == 0: return False
    r = int(n**0.5)
    f = 5
    while f <= r:
        print ('\t',f)
        if n%f == 0: return False
        if n%(f+2) == 0: return False
        f +=6
    return True

#def choose_prime(p_size):
    
    
import os # for OS random number generation
from math import log2, floor
# import SHA256
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
#import AES-CTR
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes

k_secrets = 3
s_secrets = [7, 313, 671] # s_i
n_participants = 2
access_structures = [(1,),(2,),(1,2)]

p_size = 2 # bytes

print(access_structures)

# 1. Dealer Phase
## I. Initialization stage
p = int.from_bytes(os.urandom(p_size), byteorder="big")
print(p)
while p <= n_participants or not is_prime(p): # p must be prime, greater than any of secrets and greater than n
    p = int.from_bytes(os.urandom(p_size), byteorder="big")
    print(p)
    
print('[log2(p)]+1 = ', floor(log2(p))+1)

### A collision resistant hash function with variable output length:
# option 1: use SHA-3 Keccak (variable length digest)
# option 2: use BLAKE2 : variable length digest (available at "cryptography" library)
# option 3: use the first [log2(p)]+1 bits of AES-CTR(SHA256(m))

# SHA256 of message
message = b'deadbeef'
digest = hashes.Hash(hashes.SHA256(), backend=default_backend())
digest.update(message)
hashed_message = digest.finalize()

print('Hash of len', len(hashed_message))
print(hashed_message.hex())

# AES-CTR of the hash
aes_key = os.urandom(32)
aes_nonce = os.urandom(16)
cipher = Cipher(algorithms.AES(aes_key), modes.CTR(aes_nonce), backend=default_backend())
encryptor = cipher.encryptor()
ciphertext = encryptor.update(hashed_message) + encryptor.finalize()

print('Ciphertext of len', len(ciphertext))
print(ciphertext.hex())

{'fraction_non_alphanumeric': 0.1271551724137931, 'fraction_numerical': 0.03201970443349754, 'mean_word_length': 3.7849779086892488, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '1991189', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1137, 'n_words': 365}