def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("") ui.message("--- Cyphering ---") text = "snoworrain" ui.message("Data to cypher: {}".format(text)) out = biliteral.cypher(text) ui.message("Biliteral cyphered data: {}".format(out)) ui.message("") ui.message("--- Decyphering ---") htext = "BABAAABAAABAABAABAAABAABBBAABBAABBBAABAAAABBBAAAAAAAABA" \ "ABABAAAAAAAAABBAABAAABBAABBAAAAAABBABBBABAABBAABABBAAAB" ui.message("Biliteral text used as input: {}".format(htext)) out = biliteral.decypher(htext) ui.message("The decyphered data is: {}".format(out)) ui.message("") ui.message("--- Won’t work ---") ui.message("+ The input text to cypher must be ASCII lowercase " "chars only:") ui.message("Data to cypher: {}\n".format("Hello World !")) try: out = biliteral.cypher("Hello World !") ui.message("Biliteral cyphered data: {}" "".format(out)) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.message("+ The input text to decypher must be valid Biliteral:") htext = "AABBBBBAABABBBBAAAABABABBBAABABBAAAABABABABBAABB" ui.message("Biliteral text used as input: {}".format(htext)) try: out = biliteral.decypher(htext) ui.message("Biliteral decyphered data: {}" "".format(out)) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)
def decypher(self, ui): """Interactive version of decypher().""" txt = "" ui.message("===== Decypher Mode =====") while 1: txt = ui.text_input("Please choose some Biliteral text", sub_type=ui.UPPER) try: ui.text_output("Text successfully decyphered", biliteral.decypher(txt), "The decyphered text is") except Exception as e: ui.message(str(e), 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