in between commit

This commit is contained in:
Kevin Veen-Birkenbach 2022-12-08 19:51:13 +01:00
parent 743bbdd59a
commit aecfadbdfb
2 changed files with 74 additions and 43 deletions

View File

@ -9,8 +9,13 @@ The purpose of this software is to splitt a secret over multiple people. Just if
- Plattform independend - Plattform independend
- easy to use - easy to use
pip install numpy
## Further Information ## Further Information
- https://www.tutorialspoint.com/python/python_command_line_arguments.htm - https://www.tutorialspoint.com/python/python_command_line_arguments.htm
- https://docs.python.org/3/library/argparse.html#module-argparse - https://docs.python.org/3/library/argparse.html#module-argparse
- https://wiki.ubuntuusers.de/GoCryptFS/ - https://wiki.ubuntuusers.de/GoCryptFS/
- https://pynative.com/python-generate-random-string/ - https://pynative.com/python-generate-random-string/
- https://www.studimup.de/abitur/stochastik/anzahl-der-m%C3%B6glichketen-berechnen-kombinatorik/
- https://numpy.org/doc/stable/reference/generated/numpy.base_repr.html?highlight=base_repr#numpy.base_repr

View File

@ -1,12 +1,32 @@
import argparse import argparse
import random import random
import string import string
import math
import numpy
import re
def getPassword(): def getPassword():
characters = string.ascii_letters + string.digits characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters) for i in range(int(64*quota_factor))).upper() return ''.join(random.choice(characters) for i in range(int(64*quota_factor))).upper()
def getStartnumber():
index = 0
start_number = ''
while index < group_members_amount:
start_number += '1'
index += 1
return int(start_number)
def getEndnumber():
index = 0
start_number = ''
while index < group_members_amount:
start_number += str(amount_of_secret_holders)
index += 1
return int(start_number)
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-a', '--amount',type=int, dest='amount_of_secret_holders',required=True) parser.add_argument('-a', '--amount',type=int, dest='amount_of_secret_holders',required=True)
@ -15,45 +35,51 @@ if __name__ == '__main__':
amount_of_secret_holders = args.amount_of_secret_holders amount_of_secret_holders = args.amount_of_secret_holders
decryption_quota = args.decryption_quota decryption_quota = args.decryption_quota
quota_factor=decryption_quota/100 quota_factor=decryption_quota/100
password_group_members_amount=amount_of_secret_holders * quota_factor group_members_amount=math.ceil(amount_of_secret_holders * quota_factor)
amount_of_partner_secrets=(amount_of_secret_holders * password_group_members_amount) amount_of_partner_secrets=(amount_of_secret_holders * group_members_amount)
#required_passwords=amount_of_partner_secrets * ( amount_of_secret_holders -1) ; maximum_posible_combinations=amount_of_secret_holders*amount_of_secret_holders
required_passwords=amount_of_partner_secrets * amount_of_secret_holders width= range(1,(amount_of_secret_holders+1))
print(quota_factor); regex="([" + ','.join([str(x) for x in width]) + "]{" + str(group_members_amount) + "})"
print(amount_of_secret_holders); print(regex)
print(decryption_quota); valid_numbers = re.compile(regex)
print(required_passwords); unvalid_sequenz = re.compile("(.)\\1+")
index = getStartnumber()
while index < getEndnumber():
index_str= ''.join(sorted(str(index)))
if re.search(valid_numbers, index_str) and not re.search(unvalid_sequenz, index_str):
print(index_str)
index += 1
mathematical_formular_verification=[]
# Create Passwords # # Create Passwords
password_groups = {} # password_groups = {}
password_group_index = 0 # password_group_index = 0
secret_holder_index = 0 # secret_holder_index = 0
while password_group_index < required_passwords : # while password_group_index < amount_of_secret_holders :
password_groups[password_group_index] = {}; # password_groups[password_group_index] = {};
password_groups[password_group_index]['members'] = {} # password_groups[password_group_index]['members'] = {}
password_groups[password_group_index]['password'] = '' # password_groups[password_group_index]['password'] = ''
group_members_count = 0 # group_members_count = 0
while group_members_count < password_group_members_amount : # while group_members_count < amount_of_secret_holders :
if secret_holder_index == amount_of_secret_holders: # if secret_holder_index == amount_of_secret_holders:
secret_holder_index = 0 # secret_holder_index = 0
password_groups[password_group_index]['members'][secret_holder_index]={} # password_groups[password_group_index]['members'][secret_holder_index]={}
password_groups[password_group_index]['members'][secret_holder_index]['password_part'] = getPassword() # password_groups[password_group_index]['members'][secret_holder_index]['password_part'] = getPassword()
password_groups[password_group_index]['members'][secret_holder_index]['password_index'] = group_members_count # password_groups[password_group_index]['members'][secret_holder_index]['password_index'] = group_members_count
password_groups[password_group_index]['password'] += ''.join(password_groups[password_group_index]['members'][secret_holder_index]['password_part']) # password_groups[password_group_index]['password'] += ''.join(password_groups[password_group_index]['members'][secret_holder_index]['password_part'])
secret_holder_index += 1 # secret_holder_index += 1
group_members_count += 1 # group_members_count += 1
mathematical_formular_verification.append(sorted(password_groups[password_group_index]['members'])) # #mathematical_formular_verification.append(sorted(password_groups[password_group_index]['members']))
password_group_index += 1 # mathematical_formular_verification.append(sorted(password_groups[password_group_index]['members']))
print(password_groups) # password_group_index += 1
# print(password_groups)
# Create User Mapping #
user_splitted_passwords = {} # # Create User Mapping
for password_group_index in password_groups: # user_splitted_passwords = {}
for member_id in password_groups[password_group_index]['members']: # for password_group_index in password_groups:
if not member_id in user_splitted_passwords: # for member_id in password_groups[password_group_index]['members']:
user_splitted_passwords[member_id] = [] # if not member_id in user_splitted_passwords:
user_splitted_passwords[member_id].append({"password_information" : password_groups[password_group_index]['members'][member_id], "members": list(password_groups[password_group_index]['members'].keys())}); # user_splitted_passwords[member_id] = []
#print(user_splitted_passwords) # user_splitted_passwords[member_id].append({"password_information" : password_groups[password_group_index]['members'][member_id], "members": list(password_groups[password_group_index]['members'].keys())});
print(sorted(mathematical_formular_verification)); # #print(user_splitted_passwords)
# print(sorted(mathematical_formular_verification));