def certificate(): import core.asymmetric.certificate as ca clear() asc.asciiBark() choices = [ "Get a public key certificate", "Show current digital certificate", "Back to menu", ] enumerateMenu(choices) selection = getInt(1, "choices") if selection == 1: clear() asc.asciiBark() k = getb64("public key") if not k: certificate() clear() asc.asciiBark() ca.x509(k, out=False) print("Certifcate generated !") doSomethingElse(certificate) elif selection == 2: clear() asc.asciiBark() if not isFileHere("X509.ca", c.DIRECTORY_PROCESSING): print("Certificate not present into the system.") print("Getting back ..") time.sleep(1) certificate() else: f = open(c.DIRECTORY_PROCESSING + "X509.ca") for line in f.readlines(): print(line) doSomethingElse(certificate) else: import katsumi clear() katsumi.menu() doSomethingElse(certificate)
def doSomethingFount(i: int): """ Handle choices for fountain. """ clear() asc.asciiArt() if i == 1: print("How many bits wanted for this generation?") wanted = getInt(2048, "bits size", True) print("\nHow many generations?") numbers = getInt(1, "generations") stockSafePrimes(wanted, numbers) doSomethingElse(primeNumbersFountain) elif i == 2: print("Enter number of bits for updating corresponding one's:") wanted = getInt(2048, "bits size", True) print("\nHow many generations?") numbers = getInt(1, "generations") stockSafePrimes(wanted, numbers) doSomethingElse(primeNumbersFountain) elif i == 3: clear() asc.asciiDeath() print( "Enter the number of bits corresponding to the list you would like to be removed." ) lnumber = getInt(2048, "bits size", True) name = f"{str(lnumber)}_bits.txt" if query_yn("Are you sure?"): rmFile(name, c.DIRECTORY_FOUNT) print(f"{name} removed successfully.\n") doSomethingElse(primeNumbersFountain) else: primeNumbersFountain() elif i == 4: import katsumi katsumi.menu() else: clear() primeNumbersFountain()
def cipher_choice(): clear() asc.asciiCat() print("Choice cypher method: ") print( " 1 - ECB \n 2 - CBC \n 3 - PCBC (Recommended) \n 4 - CTR (Stream) \n 5 - GCM (Authentification)" ) pCipher = getInt(3, "choices") # Cipher verification if pCipher > 5: print("Error: You didn't choose a cipher properly.") time.sleep(1) from katsumi import menu menu() if pCipher == 1: answer = query_yn( "ECB is not recommended for use in cryptographic protocols. Are you sure?" ) if answer: clear() return pCipher clear() return cipher_choice() clear() asc.asciiCat() return pCipher
def katsuBlockChain(): asc.asciiBlockC() choices = [ "Block-chain live simulation", "Quick block-chain test", "Back to menu" ] enumerateMenu(choices) selection = getInt(1, "choices") if selection == 1: bcSimulationParam() elif selection == 2: clear() print("Generating the test block-chain...") bc.createTestBC() else: import katsumi katsumi.menu() doSomethingElse(katsuBlockChain)
def katsuHash(): import core.hashbased.hashFunctions as hf import base64 clear() asc.asciiCat() choices = ["Generate a hash", "Check a hash", "Back to menu"] enumerateMenu(choices) selection = getInt(1, "choices") if selection == 1: size = getInt(256, "hash", True) if query_yn("Do you want to hash a file?", "no"): f = getFile() clear() if f: print( f"File hash: {base64.b64encode(hf.sponge(bm.fileToBytes(f), size)).decode()}" ) else: katsuHash() else: msg = readFromUser("Enter the text to hash:") print( f"Text hash: {base64.b64encode(hf.sponge(msg.encode(), size)).decode()}" ) elif selection == 2: def verifyHash(h, msg): h2 = hf.sponge(msg, len(h) * 8) if h == h2: print("Hashes are the same !") else: print("Hashes are not the same !") h = getb64("hash") if h: if query_yn("Do you want to compare this hash to a file's one?", "no"): f = getFile() if f: verifyHash(h, bm.fileToBytes(f)) else: katsuHash() else: verifyHash( h, readFromUser( "Enter the text to compare with the hash:").encode()) else: katsuHash() else: import katsumi clear() katsumi.menu() doSomethingElse(katsuHash)
def doSomethingAssym(i: int): """ Handle choices for symmetric things. """ clear() asc.asciiCat() if i == 1: print( "You are going to generate public/private key pairs with ElGamal algorithm." ) if keysVerif(): elGamalKeysGeneration() else: clear() asc.asciiCat() print("Your current public key is: ", end="") prGreen(getB64Keys(extractKeyFromFile("public_key"))) doSomethingElse(katsuAsymm) elif i == 2: try: publicK = getB64Keys(extractKeyFromFile("public_key")) privateK = getB64Keys(extractKeyFromFile("private_key")) print("Public Key: ", end="") prGreen(publicK) print() print("Private Key: ", end="") prGreen(privateK) except FileNotFoundError: print("One key doesn't exist. Please regenerate them.") doSomethingElse(katsuAsymm) elif i == 3: if not isFileHere("public_key.kpk", c.DIRECTORY_PROCESSING): print("No public key found into the system...") time.sleep(1) doSomethingAssym(1) else: keysVerif(verif=False) answer = readFromUser().encode() e = elG.encrypt( answer, extractKeyFromFile("public_key", c.DIRECTORY_PROCESSING), saving=True, ) print("Saved encrypted message into appropriated file: ", end="") prGreen(e) doSomethingElse(katsuAsymm) elif i == 4: print("Let's check if everything is there.") ##### while not isFileHere("public_key.kpk", c.DIRECTORY_PROCESSING): asc.asciiCat() input( "Please put your 'private_key.kpk' file into the 'processing' folder." ) print("Gotcha !\n") while not isFileHere("encrypted.kat", c.DIRECTORY_PROCESSING): asc.asciiCat() input( "Please put your 'encrypted.kat' file into the 'processing' folder." ) print("Gotcha !\n") ##### asc.asciiCat() if query_yn( "Do you want to use the encrypted.kat file's? (default: Yes)" ): e = extractKeyFromFile("encrypted", c.DIRECTORY_PROCESSING, ".kat") else: e = getIntKey(getb64("key"), 2) d = elG.decrypt(e, extractKeyFromFile("private_key", c.DIRECTORY_PROCESSING), asTxt=True) asc.asciiCat() prYellow(d) doSomethingElse(katsuAsymm) elif i == 5: dHgestion() elif i == 6: dlogAttack() elif i == 7: clear() asc.asciiDeath() print("You're going to erase all key's from the system.\n") if query_yn("Are you sure?"): for f in [ "public_key", "private_key", "dH_shared_key", "dH_agreement", "dH_sendable", ]: rmFile(f + ".kpk", c.DIRECTORY_PROCESSING) clear() asc.asciiDeath() print("Done.\n") return doSomethingElse(katsuAsymm) katsuAsymm() elif i == 8: clear() katsumi.menu() else: katsuAsymm()
def doSomethingSymm(i: int): """ Handle choices for symmetric things. """ clear() asc.asciiCat() if i in [1, 2]: if not c.KEY: key = askForKey() else: key = c.KEY if i == 1: # Encryption cipher = cipher_choice() aad = "" inFile = "" if cipher == 5: if query_yn( "GCM allows to store authentified additional data (not encrypted), do you want to store some AAD?" ): aad = readFromUser() else: clear() asc.asciiCat() useFile = query_yn("Do you want to encrypt a file?", "no") if useFile: inFile = getFile() if inFile: data = bm.fileToBytes(inFile) else: katsuSymm() else: data = readFromUser().encode() print("Encryption started....") begin_time = datetime.now() if useFile: print( f"Your file has been ciphered correctly ! Find-it into {c.DIRECTORY_PROCESSING} folder." ) else: print("Here is your ciphered message, copy it and send it !") prGreen(ciphers.run(data, inFile, True, cipher, aad, key)) end = datetime.now() - begin_time input(f"\nEncryption finished in {end} seconds !") clear() asc.asciiCat() doSomethingElse(katsuSymm) elif i == 2: # Decryption cipher = cipher_choice() inFile = False if query_yn("Do you want to decrypt a file?", "no"): inFile = getFile() if inFile: data = bm.fileToBytes(inFile) else: katsuSymm() else: data = getb64() if not data: katsuSymm() print("Decryption started....\n") begin_time = datetime.now() prYellow(ciphers.run(data, inFile, False, cipher, "", key)) end = datetime.now() - begin_time input(f"\nDecryption finished in {end} seconds !") clear() asc.asciiCat() doSomethingElse(katsuSymm) elif i == 3: clear() katsumi.menu() else: katsuSymm()