def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("--- Encoding ---") text = "Hello World!" bf = brainfuck.brainfuck ui.message("Data to cypher: {}\n".format(text)) ui.message("Brainfuck cyphered data (utf-8): {}" "".format(brainfuck.cypher(text, lang=bf.BRAINFUCK))) ui.message("Ook cyphered data (utf-8): {}" "".format(brainfuck.cypher(text, lang=bf.OOK))) ui.message("Spoon cyphered data (utf-8): {}" "".format(brainfuck.cypher(text, lang=bf.SPOON))) ui.message("SegFaultProg cyphered data (utf-8): {}" "".format(brainfuck.cypher(text, lang=bf.SIGSEV))) ui.message("") ui.message("--- Decoding ---") ui.message("+ Brainfuck will find out which language it is.") htext = "++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>++.>---.++++++" \ "+++++++++..+++++++++.<<++.>>-----------.---------.+++++++++" \ "+++++++++.<<.>>++.--------------------.----.+++++++++++++++" \ "++.<<.++++++++++++++++++.--.+.+." ui.message("Brainfuck code used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(brainfuck.decypher(htext, codec="utf-8"))) ui.message("") htext = "+8[>+4*2+8*3+12>+13>+14>+15>+16*8+19*9+20>+28<10-]*2+.*1.>4" \ "+.+4.*4+.*5-.*3+5.<2.>4-.*4.+4.>-3.<-.*3.*1.*3-.>2+5.*4+.." \ "*6+.<5.>9+2.<3.>+4.*5-.<2+.*5-.+.>5.<3.*8+.*10.*7.>2+6." ui.message("Brainfuck code used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(brainfuck.decypher(htext, codec="utf-8"))) ui.message("") ui.message("--- Won’t work ---") ui.message("+ The input code to decypher must be valid!") htext = "Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook." \ " Ook. Ook. Ook. Ook! Ook?" \ "*4.+4.>-3.<-.*3.*1.*3-.>2+5.*4+..*6+.<5.>9+2.<3.>+4.*5-.<2+." ui.message("“Numbers” text used as binary input: {}".format(htext)) try: ui.message("The decypherd data is: {}" "".format(brainfuck.decypher(htext))) 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 “code” text") # Get codec to use. options = [(brainfuck.DEFAULT, "$utf-8", ""), (None, "or specify another *codec", "")] codec = ui.get_choice("Do you want to use", options, oneline=True) if codec is None: codec = ui.get_data("Type the codec you want to use " "(e.g. 'latin-9'): ") try: ui.text_output("Data successfully decypherd", brainfuck.decypher(txt, codec), "The hidden 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