def menu(): it.clear() choices = [ "Symmetric", "Asymmetric", "Hash", "Get X509 Certificate", "BlockChain", "Prime Numbers Fountain's", "Exit", ] if it.correctSizeHook(): print("------------------------------------------------------------------") asc.asciiCat() print("- Created by: Gobinet Théo && Martin Azaël ") print("- Free to use") print("- MIT License\n") it.enumerateMenu(choices) try: selection = it.getInt(1, "choices") work_with_selection(selection) except KeyboardInterrupt: work_with_selection(-1) else: menu()
def asciiArt(): it.clear() return print(""" . . . . . . . 1217 . . . . . 337 . . . . . . . . . . . . . . . . . . 2027 . . . . 13 . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 . . . . . . 109 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I . I _______________III_______________ | . Prime . Numbers . | \SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS/ \ ======================= / \SSSSSSSSSSSSSSSSS/ ________\ /________ (=+=+=+=+=+=+=+=+=+=+=+=+=) ~~~~~~~~~~~~~~~~~~~~~~~~~ """)
def work_with_selection(pSelection): """Interact with others py functions depending on user choice.""" it.clear() asc.asciiCat() # Selection orientation if pSelection == 1: it.katsuSymm() elif pSelection == 2: it.katsuAsymm() elif pSelection == 3: it.katsuHash() elif pSelection == 4: it.certificate() elif pSelection == 5: it.katsuBlockChain() elif pSelection == 6: return it.primeNumbersFountain() elif pSelection in [7, -1]: asc.asciiGoodBye() sys.exit() else: it.clear() menu()
def asciiGoodBye(): it.clear() return print(""" __ /__ _ _ _| |_ _ ._ _ | _ ._ _| \_| (_) (_) (_| |_) \/ (/_ | | | \/ |_ (_) | (_| / / """)
def main(): it.clear() # Directory initialisation it.handleDirectory("processing") # Galois field's initialization GF2(16) menu()
def asciiJongling(): it.clear() return print(""" ' ' ' ' ' ' o/ ' \o /-' -\ /\ /\ Do you feel as though you are juggling a few to many responsibilities? """)
def asciiKeys(): it.clear() return print(""" 8 8 , o. , o. 8 8 d8o8azzzzzzzzd b Diffie Hellman Key d bzzzzzzzza8o8b `o' Exchange `o' 8 8 8 8 , ooo. 8a8 8a8 oP ?b d888a888zzzzzzzzzzzzzzzzzzzz8 8b `""^""' ?o___oP' """)
def asciiBlockC(): it.clear() return print(""" _______ __ __ ______ __ __ | \ | \ | \ / \ | \ | \ | $$$$$$$\| $$ ______ _______ | $$ __ | $$$$$$\| $$____ ______ \$$ _______ | $$__/ $$| $$ / \ / \| $$ / \| $$ \$$| $$ \ | \ | \| \ | $$ $$| $$| $$$$$$\| $$$$$$$| $$_/ $$| $$ | $$$$$$$\ \$$$$$$\| $$| $$$$$$$| | $$$$$$$\| $$| $$ | $$| $$ | $$ $$ | $$ __ | $$ | $$ / $$| $$| $$ | $$ | $$__/ $$| $$| $$__/ $$| $$_____ | $$$$$$\ | $$__/ \| $$ | $$| $$$$$$$| $$| $$ | $$ | $$ $$| $$ \$$ $$ \$$ \| $$ \$$\ \$$ $$| $$ | $$ \$$ $$| $$| $$ | $$ \$$$$$$$ \$$ \$$$$$$ \$$$$$$$ \$$ \$$ \$$$$$$ \$$ \$$ \$$$$$$$ \$$ \$$ \$$ """)
def asciiBark(): it.clear() return print(""" .-------------. . . * * /_/_/_/_/_/_/_/ \ certification * . ) . //_/_/_/_/_/_// _ \ __ authority (CA) . . /_/_/_/_/_/_/_/|/ \.' .`-o * . | ||-'(/ , --' | Benji || _ | BARK Trust Services | ||'' || (The dog is a lie) |_____________|| |_|L """)
def watch(): initVar() config.WATCH_GLOBAL_TIME = time.time() while config.WATCH_EXEC_STATUS: it.clear() # To avoid error of Division by 0 if config.WATCH_PERCENTAGE == 0: config.WATCH_PERCENTAGE = 0.01 display() time.sleep(0.5)
def asciiDeath(): it.clear() return print(""" %%% %%%%%%% |#| %%%% %%%%%%%%%%% |#|#### %%%%% % %%% |#|=##### %%%%% % @ @ %% | | ==#### %%%%%% % (_ () ) %% | | ===## %% %%% % \_ | %% | | =## % %%%% % u^uuu %% | | ==# %%%% %%%%%%%%% | | V ~ Death is irreversible ~ """)
def GF2(degree): """Initialize the Galois Field GF(p^degree) in Zn.""" config.DEGREE = degree config.NBR_ELEMENTS = 2**degree config.IRRED_POLYNOMIAL = int.from_bytes( bm.mult_to_bytes(config.IRRED_POLYNOMIAL), "big") config.GENERATOR = gen_GL_2(config.IRRED_POLYNOMIAL, degree) it.handleInvBox() if config.IN_CREATION: start = time.time() while config.IN_CREATION: it.clear() print(" --- Wait for the creation please --- ") print((" --- Time elapsed: {:.1f} seconds").format(time.time() - start)) time.sleep(1)
def asciiCat(): it.clear() return print(""" _ \`*-. _ __ _ _ ) _`-. | |/ / | | (_) . : `. . | ' / __ _| |_ ___ _ _ _ __ ___ _ : _ ' \ | < / _` | __/ __| | | | '_ ` _ \| | ; *` _. `*-._ | . \ (_| | |_\__ \ |_| | | | | | | | `-.-' `-. |_|\_\__, _|\__|___/\__, _|_| |_| |_|_| ; ` `. :. . \ Remember: . \ . : .-' . Encryption provides secrecy, ' `+.; ; ' : not authentication or integrety. : ' | ; ;-. ; ' : :`-: _.`* ; Martin Azaël && Gobinet Théo .*' / .*' ; .*`- +' `*' `*-* `*-* `*-*' """)
def safePrime_worker(nBits: int = 1024, randomFunction=None, easyGenerator: bool = False, Verbose: bool = False, flag=None, returnL: list = []): """ Function executed on each process for safe prime generation """ import ressources.interactions as it from multiprocessing import Manager if not flag: flag = Manager().Value("i", 0) if easyGenerator: if Verbose: print("Easy generator choosen.") p_filter = lambda p: p % 3 == 2 and ( p % 12 == 1 or p % 12 == 11 ) # p = 1 mod 12 make 11 as primitive root else: p_filter = lambda p: p % 3 == 2 while not bool(flag.value): # For faster searching # Calculate 2q +1 and (q-1)//2 # Return Sophie Germain's prime according to what is prime. if randomFunction is None: randomFunction = randomInt q = randomPrime(nBits, randomFunction, p_filter, 1) p1 = 2 * q + 1 p2 = (q - 1) // 2 if Verbose: it.clear() print(f"Prime {q} candidate's.") if millerRabin(p1): if Verbose: print("q is prime and 2q +1 too.") print(f"\nSophie Germain prime's: {q}\n") sophieGermain_prime, safe_prime = q, p1 # Safe prime found flag.value = 1 returnL.append((safe_prime, sophieGermain_prime)) elif millerRabin(p2): if Verbose: print("q is prime and (q-1)/2 too.") print(f"\nSophie Germain prime's: {p2}\n") sophieGermain_prime, safe_prime = p2, q # Safe prime found flag.value = 1 returnL.append((safe_prime, sophieGermain_prime)) else: if Verbose: print( "But 2 * him + 1 and (him - 1) / 2 doesn't seem to be primes...\n" )