def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("--- Cyphering ---") keys = ["HACK", "HACK", "1024", "HACK"] algo_names = ["vigenere", "autoclave", "gronsfeld", "beaufort"] algos = [vigenere.ALGO_VIGENERE, vigenere.ALGO_AUTOCLAVE, vigenere.ALGO_GRONSFELD, vigenere.ALGO_BEAUFORT] plain_text = "HELLO WORLD 1024" ui.message("plain-text <-> key <-> algorithm") for index, algo in enumerate(algos): ui.message(plain_text + " - " + keys[index] + " - " + algo_names[index]) ui.message("\t" + vigenere.cypher(plain_text, keys[index], algo)) #ui.message("--- Decyphering ---") ui.message("Won't work!") try: plain_text = "HELLO WORLD" key = "1234" ui.message("plain-text <-> key <-> algorithm") ui.message(plain_text + " <-> " + key + " <-> vigenere") vigenere.cypher(plain_text, key, vigenere.ALGO_VIGENERE) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)
def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("--- Cyphering ---") keys = ["HACK", "HACK", "1024", "HACK"] algo_names = ["vigenere", "autoclave", "gronsfeld", "beaufort"] algos = [ vigenere.ALGO_VIGENERE, vigenere.ALGO_AUTOCLAVE, vigenere.ALGO_GRONSFELD, vigenere.ALGO_BEAUFORT ] plain_text = "HELLO WORLD 1024" ui.message("plain-text <-> key <-> algorithm") for index, algo in enumerate(algos): ui.message(plain_text + " - " + keys[index] + " - " + algo_names[index]) ui.message("\t" + vigenere.cypher(plain_text, keys[index], algo)) #ui.message("--- Decyphering ---") ui.message("Won't work!") try: plain_text = "HELLO WORLD" key = "1234" ui.message("plain-text <-> key <-> algorithm") ui.message(plain_text + " <-> " + key + " <-> vigenere") vigenere.cypher(plain_text, key, vigenere.ALGO_VIGENERE) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)
def cypher(self, ui): """Interactive version of cypher().""" txt = "" ui.message("===== Cypher Mode =====") while 1: done = False while 1: txt = ui.text_input("Please input text to cypher", sub_type=ui.STRING) if txt is None: break # Go back to main Cypher menu. txt = txt.upper() # Get algo. options = [(vigenere.ALGO_VIGENERE, "$vigenere", ""), (vigenere.ALGO_BEAUFORT, "*beaufort", ""), (vigenere.ALGO_GRONSFELD, "*gronsfeld", ""), (vigenere.ALGO_AUTOCLAVE, "auto*clave", "")] algo = ui.get_choice("Algorithm to use ", options) # Get key key = ui.get_data("Enter the key : ", sub_type=ui.STRING) key = key.upper() spaces = ui.get_choice("Conserve spaces ?", options=[ (True, "$yes", ""), (False, "*no", "")], oneline=True) try: txt = vigenere.cypher(txt, key, algo, spaces) done = True # Out of those loops, output result. break except Exception as e: if utils.DEBUG: import traceback traceback.print_tb(sys.exc_info()[2]) ui.message(str(e), level=ui.ERROR) options = [("retry", "*try again", ""), ("menu", "or go back to *menu", "")] answ = ui.get_choice("Could not convert that data into " "Vigenere, please", options, oneline=True) if answ in {None, "menu"}: return # Go back to main Sema menu. # Else, retry with another data to hide. if done: ui.text_output("Text successfully converted", txt, "cyphered-text") options = [("redo", "*cypher another text", ""), ("quit", "or go back to $menu", "")] answ = ui.get_choice("Do you want to", options, oneline=True) if answ in {None, "quit"}: return
def cypher(self, ui): """Interactive version of cypher().""" txt = "" ui.message("===== Cypher Mode =====") while 1: done = False while 1: txt = ui.text_input("Please input text to cypher", sub_type=ui.STRING) if txt is None: break # Go back to main Cypher menu. txt = txt.upper() # Get algo. options = [(vigenere.ALGO_VIGENERE, "$vigenere", ""), (vigenere.ALGO_BEAUFORT, "*beaufort", ""), (vigenere.ALGO_GRONSFELD, "*gronsfeld", ""), (vigenere.ALGO_AUTOCLAVE, "auto*clave", "")] algo = ui.get_choice("Algorithm to use ", options) # Get key key = ui.get_data("Enter the key : ", sub_type=ui.STRING) key = key.upper() spaces = ui.get_choice("Conserve spaces ?", options=[(True, "$yes", ""), (False, "*no", "")], oneline=True) try: txt = vigenere.cypher(txt, key, algo, spaces) done = True # Out of those loops, output result. break except Exception as e: if utils.DEBUG: import traceback traceback.print_tb(sys.exc_info()[2]) ui.message(str(e), level=ui.ERROR) options = [("retry", "*try again", ""), ("menu", "or go back to *menu", "")] answ = ui.get_choice( "Could not convert that data into " "Vigenere, please", options, oneline=True) if answ in {None, "menu"}: return # Go back to main Sema menu. # Else, retry with another data to hide. if done: ui.text_output("Text successfully converted", txt, "cyphered-text") options = [("redo", "*cypher another text", ""), ("quit", "or go back to $menu", "")] answ = ui.get_choice("Do you want to", options, oneline=True) if answ in {None, "quit"}: return