def decrypt(): print("Preparing to decrypt...") data = get_decrypt_input() while True: cypher = input( "1 : Ceaser (shift) Cypher\n2 : Block Cypher\n3 : Diffie-Hellman Cypher\nPlease select a cypher (1, 2, or 3): " ) try: cypher = int(cypher) except ValueError: print("Sorry, {} is not a valid choice. Pick 1, 2, or 3.".format( cypher)) continue if cypher == 1: decrypted = shift_cypher(data[0], -data[1]) break elif cypher == 2: chunk_list = list(map(int, data[0].split("\n"))) chunk_list = block_unshift(chunk_list, data[1]) decrypted = block_rebuild(chunk_list) break elif cypher == 3: shared_key = dh_shared_key(data[1], dh_public_key) decrypted = dh_unshift(data[0], shared_key) break elif cypher == 0: return print("The decrypted message is:\n'{}'".format(decrypted)) return
def decrypt(): print("Preparing to decrypt...") data = get_decrypt_input() while True: cypher = input( "1 : Ceaser (shift) Cypher\n2 : Block Cypher\n3 : Diffie-Hellman Cypher\nPlease select a cypher (1, 2, or 3): " ) try: cypher = int(cypher) except ValueError: white = "\x1b[0m" escape = "\x1b[" color = "31m" text = ("Sorry, '{}' is not a valid choice. Pick 1, 2, or 3.". format(cypher)) colored_text = escape + color + text + white print(colored_text) continue if cypher == 1: decrypted = shift_cypher(data[0], -data[1]) break elif cypher == 2: chunk_list = list(map(int, data[0].split("\n"))) chunk_list = block_unshift(chunk_list, data[1]) decrypted = block_rebuild(chunk_list) break elif cypher == 3: #msg_public_key = dh_base ** data[1] % dh_mod shared_key = dh_shared_key(dh_private_key, data[1]) decrypted = dh_unshift(data[0], shared_key) break # encryption #msg_public_key = dh_base ** data[1] % dh_mod #shared_key = dh_shared_key(dh_private_key, msg_public_key) #encrypted = dh_shift(data[0], shared_key) elif cypher == 0: return print("The decrypted message is:\n'{}'".format(decrypted)) return