def cypher(self, ui): """Interactive version of cypher().""" txt = "" ui.message("===== Cypher Mode =====") while 1: done = False while 1: txt = ui.text_input("Text to cypher to Baudot", sub_type=ui.LOWER) if txt is None: break # Go back to main Cypher menu. try: # Get base(s). options = [(2, "$binary", ""), (8, "*octal", ""), (10, "*decimal", ""), (16, "and/or he*xadecimal", "")] bases = ui.get_choice("Do you want to use", options, oneline=True, multichoices=",") txt = baudot.cypher(txt, set(bases)) 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 " "Baudot, 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: txt = "\n " + "\n ".join(txt) ui.text_output("Text successfully converted", txt, "Baudot version(s) of 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("Text to cypher to Baudot", sub_type=ui.LOWER) if txt is None: break # Go back to main Cypher menu. try: # Get base(s). options = [(2, "$binary", ""), (8, "*octal", ""), (10, "*decimal", ""), (16, "and/or he*xadecimal", "")] bases = ui.get_choice("Do you want to use", options, oneline=True, multichoices=",") txt = baudot.cypher(txt, set(bases)) 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 " "Baudot, 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: txt = "\n " + "\n ".join(txt) ui.text_output("Text successfully converted", txt, "Baudot version(s) of 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 demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("") ui.message("--- Encoding ---") text = "bye bye 2011 :)" ui.message("Data to cypher: {}\n".format(text)) ui.message("Baudot cyphered data (binary, octal, decimal and " "hexadecimal):\n {}" "".format("\n ".join( baudot.cypher(text, bases=(2, 8, 10, 16))))) ui.message("") ui.message("--- Decoding ---") ui.message("+ In general, you can let Baudot find which base is used.") htext = "1f1401121218041b131617130d" ui.message("Baudot text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(baudot.decypher(htext))) ui.message("") ui.message("+ The input text to decypher may have space-separated " "bytes:") htext = "11111 10100 00001 10010 10010 11000 00100 11011 10011 " \ "10110 10111 10011 01101" ui.message("Baudot text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(baudot.decypher(htext))) ui.message("") ui.message("--- Won’t work ---") ui.message("+ The input text to cypher must contain only valid " "chars (ascii lowercase, digits, and a few others):") text = "Baudot was used by “paper tapes”…" ui.message("Text to cypher: {}".format(text)) try: ui.message("The cypherd data is: {}" "".format(baudot.cypher(text))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.message("+ The input text to decypher must contain only valid " "digits for the given base:") htext = "111111010111211101101100015000110110111101101101011a" \ "0010100100201" ui.message("Baudot text used as binary input: {}".format(htext)) try: ui.message("The decypherd data is: {}" "".format(baudot.decypher(htext, base=2))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.message("+ The input text to decypher must have an integer number " "of “bytes” (once spaces have been striped):") htext = "11111 01101 010110 01011 00111 01011 110011 00001" ui.message("Baudot text used as input: {}".format(htext)) try: ui.message("The decypherd data is: {}" "".format(baudot.decypher(htext, base=2))) 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("") ui.message("--- Encoding ---") text = "bye bye 2011 :)" ui.message("Data to cypher: {}\n".format(text)) ui.message("Baudot cyphered data (binary, octal, decimal and " "hexadecimal):\n {}" "".format("\n ".join(baudot.cypher(text, bases=(2, 8, 10, 16))))) ui.message("") ui.message("--- Decoding ---") ui.message("+ In general, you can let Baudot find which base is used.") htext = "1f1401121218041b131617130d" ui.message("Baudot text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(baudot.decypher(htext))) ui.message("") ui.message("+ The input text to decypher may have space-separated " "bytes:") htext = "11111 10100 00001 10010 10010 11000 00100 11011 10011 " \ "10110 10111 10011 01101" ui.message("Baudot text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(baudot.decypher(htext))) ui.message("") ui.message("--- Won’t work ---") ui.message("+ The input text to cypher must contain only valid " "chars (ascii lowercase, digits, and a few others):") text = "Baudot was used by “paper tapes”…" ui.message("Text to cypher: {}".format(text)) try: ui.message("The cypherd data is: {}" "".format(baudot.cypher(text))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.message("+ The input text to decypher must contain only valid " "digits for the given base:") htext = "111111010111211101101100015000110110111101101101011a" \ "0010100100201" ui.message("Baudot text used as binary input: {}".format(htext)) try: ui.message("The decypherd data is: {}" "".format(baudot.decypher(htext, base=2))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.message("+ The input text to decypher must have an integer number " "of “bytes” (once spaces have been striped):") htext = "11111 01101 010110 01011 00111 01011 110011 00001" ui.message("Baudot text used as input: {}".format(htext)) try: ui.message("The decypherd data is: {}" "".format(baudot.decypher(htext, base=2))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)