def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("--- Encrypting ---") ui.message("Data to encrypt: {}\n".format("hello wolrd")) ui.message("Cellphone encrypted data: {}" "".format(cellphone.encrypt("hello world"))) htext = "123580 147*369#8 321457*0# 147*369#8 *74269#8 32470# " \ "147*538# *74269#8 *7412690 321457*0# *7415369# 15380" ui.message("--- Deciphering ---") ui.message("Cellphone text used as input: {}".format(htext)) ui.message("The deciphered data is: {}" "".format(cellphone.decipher(htext))) ui.message("--- Won’t work ---") ui.message("+ The input text to encrypt must be acsii lowercase " "letters only:") ui.message("Data to encrypt: {}\n".format("Hello Wolrd!")) try: ui.message("Cellphone encrypted data: {}" "".format(cellphone.encrypt("Hello World!"))) except Exception as e: ui.message(str(e), ui.ERROR) ui.message("+ The input text to decipher must be phone digits only:") htext = "123580 147*369#8 321457*0# 1N7*369#8 *74269#8 32470# " \ "147*538# *74269#8 *7412690 321457*0# *741k369# 15380!" ui.message("Cellphone text used as input: {}".format(htext)) try: ui.message("The deciphered data is: {}" "".format(cellphone.decipher(htext))) except Exception as e: ui.message(str(e), ui.ERROR) ui.get_choice("", [("", "Go back to *menu", "")], oneline=True)
def decipher(self, ui): """Interactive version of decipher().""" txt = "" ui.message("===== Decipher Mode =====") while 1: txt = ui.text_input("Please choose some cellphone text") try: ui.text_output("Text successfully deciphered", cellphone.decipher(txt), "The deciphered text is") except Exception as e: ui.message(str(e), ui.ERROR) options = [("redo", "*decipher another data", ""), ("quit", "or go back to *menu", "")] answ = ui.get_choice("Do you want to", options, oneline=True) if answ == "quit": return