def decypher(self, ui): """Interactive version of decypher().""" txt = "" ui.message("===== Decypher Mode =====") while 1: txt = ui.text_input("Please choose some morse/wabun text", sub_type=ui.UPPER) # Get optional decyphering method. options = [(morse_wabun.INTER, "*international morse decyphering", ""), (morse_wabun.WABUN, "*wabun one", ""), (None, "or $auto detect cypher method", "")] method = ui.get_choice("Do you want to force", options, oneline=True) try: ui.text_output("Data successfully decypherd", morse_wabun.decypher(txt, method), "The cyphered data is") except Exception as e: if utils.DEBUG: import traceback traceback.print_tb(sys.exc_info()[2]) ui.message(str(e), level=ui.ERROR) options = [("redo", "*decypher another data", ""), ("quit", "or go back to *menu", "")] answ = ui.get_choice("Do you want to", options, oneline=True) if answ == "quit": return
def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("") ui.message("--- Cyphering to Morse ---") text = "VANCOUVER! VANCOUVER! THIS IS IT!" ui.message("Data to cypher: {}".format(text)) out = morse_wabun.cypher(text, morse_wabun.INTER, morse_wabun.STANDARD) ui.message("International standard morse: {}".format(out)) out = morse_wabun.cypher(text, morse_wabun.INTER, morse_wabun.FAST) ui.message("International fast morse: {}".format(out)) ui.message("") ui.message("--- Cyphering to Wabun ---") text = "LE KATAKANA DU SAMOURAI ETAIT EN FER BLANC." ui.message("Data to cypher: {}".format(text)) out = morse_wabun.cypher(text, morse_wabun.WABUN, morse_wabun.STANDARD) ui.message("Wabun standard morse: {}".format(out)) out = morse_wabun.cypher(text, morse_wabun.WABUN, morse_wabun.FAST) ui.message("Wabun fast morse: {}".format(out)) ui.message("") ui.message("--- Decyphering ---") htext = ".. -.-. .. / ...- .- -. -.-. --- ..- ...- . .-. .-.-.- / " \ "-.-. --- -- -- . -. - / .- .-.. .-.. . --.. -....- ...- " \ "--- ..- ... --..-- / .--. .- .-. .. ... ..--.." ui.message("Note that most of the time, you can use default options " "here (i.e. automatic detection)!") ui.message("First input: {}".format(htext)) out = morse_wabun.decypher(htext) ui.message("The decyphered data is: {}".format(out)) htext = "T...=.......===.===.=.===.=...=.=.===.===..." \ "===.===.=.=.===.=.=.......=.===...S......." \ "S...===.===.=.=.=.=.===.===.=.===...=.===.=.===.===.=.=..." \ "===.===.=...N...G.......=.===.=.=.=...N.......T...=......." \ "===.=.===...L...L" ui.message("Second input: {}".format(htext)) out = morse_wabun.decypher(htext) ui.message("The decyphered data is: {}".format(out)) ui.message("") ui.message("--- Notes ---") ui.message("+ For Wabun cyphering, you can choose the optionnal " "Exhaustive option, to get all possible encodings of each " "words higher than the given threshold of cyphering (or " "the highest possible):") text = "THE SHOGUN IS DRINKING GREEN TEA." ui.message("Data to cypher: {}".format(text)) out = morse_wabun.cypher(text, morse_wabun.WABUN, morse_wabun.FAST, exhaustive=True, min_cypher=0.6) out = self._get_exhaustive_txt(out, ' / ', ui, min_cypher=0.6, act="all") ui.message("Cyphered solutions with cypher factor higher than 0.6:") ui.message(out) ui.message("") ui.message("--- Won’t work ---") ui.message("+ As usual, only valid letters/codes can be given " "(always uppercase).") text = "\"HELLŌ 2012 WØRLD…\"" ui.message("* International Morse supports numbers, and some special " "chars and accentuated occidental chars") ui.message("Data to cypher in international morse: {}" "".format(text)) try: out = morse_wabun.cypher(text, morse_wabun.INTER) ui.message("Morse cyphered data: {}".format(out)) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("* Wabun Morse supports only ASCII chars, spaces, dots, " "coma and parenthesis:") ui.message("Data to cypher in international morse: {}" "".format(text)) try: out = morse_wabun.cypher(text, morse_wabun.WABUN) ui.message("WABUN cyphered data: {}".format(out)) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)