diff --git a/scripts/decrypt.py b/scripts/classes/Cleanup.py similarity index 100% rename from scripts/decrypt.py rename to scripts/classes/Cleanup.py diff --git a/scripts/classes/Cli.py b/scripts/classes/Cli.py index bbdb272..df5ec68 100644 --- a/scripts/classes/Cli.py +++ b/scripts/classes/Cli.py @@ -3,11 +3,11 @@ import subprocess -class Cli: +class Cli(): def __init__(self): - self.command = ''; - self.output = []; + self.command = '' + self.output = [] pass def executeCommand(self,command): diff --git a/scripts/classes/Decrypt.py b/scripts/classes/Decrypt.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/classes/Generate.py b/scripts/classes/Generate.py new file mode 100644 index 0000000..97d55d1 --- /dev/null +++ b/scripts/classes/Generate.py @@ -0,0 +1,76 @@ +import random +import string +import math +import numpy +import re +import classes.Cli as Cli + +class Generate: + + def __init__(self, amount_of_secret_holders, decryption_quota): + self.amount_of_secret_holders = amount_of_secret_holders + self.decryption_quota = decryption_quota + self.decrypted_master_password_file_path="data/decrypted/password_files/master-password.txt" + self.quota_factor=self.decryption_quota/100 + self.group_members_amount=math.ceil(self.amount_of_secret_holders * self.quota_factor) + self.cli = Cli.Cli() + def getStartnumber(self): + index = 0 + start_number = '' + while index < self.group_members_amount: + start_number += '1' + index += 1 + return int(start_number) + + def getEndnumber(self): + index = 0 + start_number = '' + while index < self.group_members_amount: + start_number += str(self.amount_of_secret_holders) + index += 1 + return int(start_number) + + def savePassword(self,password,password_file_path): + print("Saving password to: " + password_file_path) + master_password_file = open(password_file_path, "a") + master_password_file.seek(0) + master_password_file.truncate() + master_password_file.write(password) + master_password_file.close() + + + def getPassword(self): + characters = string.ascii_letters + string.digits + return ''.join(random.choice(characters) for i in range(int(64*self.quota_factor))).upper() + + def execute(self): + + width= range(1,(self.amount_of_secret_holders+1)) + regex="([" + ','.join([str(x) for x in width]) + "]{" + str(self.group_members_amount) + "})" + valid_numbers = re.compile(regex) + unvalid_sequenz = re.compile("(.)\\1+") + index = self.getStartnumber() + password_groups = {} + while index < self.getEndnumber(): + password_group_index_str = ''.join(sorted(str(index))) + if re.search(valid_numbers, password_group_index_str) and not re.search(unvalid_sequenz, password_group_index_str): + password_group_index_int = int(password_group_index_str) + if not password_group_index_int in password_groups: + password_index = 1 + password_groups[password_group_index_int] = {} + password_groups[password_group_index_int]['members'] = {} + password_groups[password_group_index_int]['password'] = '' + password = '' + for secret_holder_index in password_group_index_str: + password_groups[password_group_index_int]['members'][secret_holder_index]={} + password_part = self.getPassword() + password_groups[password_group_index_int]['members'][secret_holder_index]['password_part'] = password_part + password_groups[password_group_index_int]['members'][secret_holder_index]['password_index'] = password_index + password += password_part + password_index += 1 + password_groups[password_group_index_int]['password'] += password + decrypted_splitted_password_file = "data/decrypted/splitted_password_files/" + password_group_index_str + ".txt" + encrypted_splitted_password_file = "data/encrypted/splitted_password_files/" + password_group_index_str + ".txt.gpg" + self.cli.executeCommand('cp -v "' + self.decrypted_master_password_file_path + '" "' + decrypted_splitted_password_file + '" && gpg --batch --passphrase "' + password + '" -c "' + decrypted_splitted_password_file + '"') + print(self.cli.getCommandString()) + index += 1 \ No newline at end of file diff --git a/scripts/classes/__init__.py b/scripts/classes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/cleanup.py b/scripts/cleanup.py deleted file mode 100644 index e605a2c..0000000 --- a/scripts/cleanup.py +++ /dev/null @@ -1 +0,0 @@ -rm -r "" \ No newline at end of file diff --git a/scripts/generate.py b/scripts/generate.py deleted file mode 100644 index 405caf4..0000000 --- a/scripts/generate.py +++ /dev/null @@ -1,85 +0,0 @@ -import argparse -import random -import string -import math -import numpy -import re -from classes.Cli import Cli - -def getPassword(): - characters = string.ascii_letters + string.digits - 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) - -def savePassword(password,password_file_path): - print("Saving password to: " + password_file_path) - master_password_file = open(password_file_path, "a") - master_password_file.seek(0) - master_password_file.truncate() - master_password_file.write(password) - master_password_file.close() - -if __name__ == '__main__': - cli = Cli() - decrypted_master_password_file_path="data/decrypted/password_files/master-password.txt" - - parser = argparse.ArgumentParser() - parser.add_argument('-a', '--amount',type=int, dest='amount_of_secret_holders',required=True,choices=range(1,9)) - parser.add_argument('-q', '--quota', type=int, dest='decryption_quota', choices=range(1,101),required=True) - #parser.add_argument('-p', '--master-password', type=str, dest='master_password', required=False) - args = parser.parse_args() - amount_of_secret_holders = args.amount_of_secret_holders - #master_password = args.master_password - decryption_quota = args.decryption_quota - - #savePassword(master_password,decrypted_master_password_file_path) - - quota_factor=decryption_quota/100 - group_members_amount=math.ceil(amount_of_secret_holders * quota_factor) - width= range(1,(amount_of_secret_holders+1)) - regex="([" + ','.join([str(x) for x in width]) + "]{" + str(group_members_amount) + "})" - valid_numbers = re.compile(regex) - unvalid_sequenz = re.compile("(.)\\1+") - index = getStartnumber() - password_groups = {} - while index < getEndnumber(): - password_group_index_str = ''.join(sorted(str(index))) - if re.search(valid_numbers, password_group_index_str) and not re.search(unvalid_sequenz, password_group_index_str): - password_group_index_int = int(password_group_index_str) - if not password_group_index_int in password_groups: - password_index = 1 - password_groups[password_group_index_int] = {} - password_groups[password_group_index_int]['members'] = {} - password_groups[password_group_index_int]['password'] = '' - password = '' - for secret_holder_index in password_group_index_str: - password_groups[password_group_index_int]['members'][secret_holder_index]={} - password_part = getPassword() - password_groups[password_group_index_int]['members'][secret_holder_index]['password_part'] = password_part - password_groups[password_group_index_int]['members'][secret_holder_index]['password_index'] = password_index - password += password_part - password_index += 1 - password_groups[password_group_index_int]['password'] += password - decrypted_splitted_password_file = "data/decrypted/splitted_password_files/" + password_group_index_str + ".txt" - encrypted_splitted_password_file = "data/encrypted/splitted_password_files/" + password_group_index_str + ".txt.gpg" - cli.executeCommand('cp -v "' + decrypted_master_password_file_path + '" "' + decrypted_splitted_password_file + '" && gpg --batch --passphrase "' + password + '" -c "' + decrypted_splitted_password_file + '"') - print(cli.getCommandString()) - index += 1 - print(password_groups) - - diff --git a/scripts/main.py b/scripts/main.py new file mode 100644 index 0000000..f4673fb --- /dev/null +++ b/scripts/main.py @@ -0,0 +1,18 @@ +import argparse +from classes.Generate import Generate + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('-a', '--amount',type=int, dest='amount_of_secret_holders',required=True,choices=range(1,9)) + parser.add_argument('-q', '--quota', type=int, dest='decryption_quota', choices=range(1,101),required=True) + #parser.add_argument('-p', '--master-password', type=str, dest='master_password', required=False) + args = parser.parse_args() + #master_password = args.master_password + generate = Generate(args.amount_of_secret_holders, args.decryption_quota) + generate.execute() + #savePassword(master_password,decrypted_master_password_file_path) + + + #print(password_groups) + +