def decypher(self, ui): """Interactive version of decypher().""" txt = "" ui.message("===== Decypher Mode =====") while 1: txt = ui.text_input("Please choose some numbers text") # Get codec to use. options = [(octopus.DEFAULT, "$utf-8", ""), (octopus.ASCII, "*ascii", ""), (octopus.EBCDIC, "*ebcdic", ""), (octopus.ASCII7, "ascii*7 (binary encode over 7 bits " "only)", ""), (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'): ") # Get base. options = [(2, "*binary", ""), (8, "*octal", ""), (10, "*decimal", ""), (16, "he*xadecimal", ""), (None, "or $auto-detect it", "")] base = ui.get_choice("Do you want to use", options, oneline=True) try: ui.text_output("Data successfully decypherd", octopus.decypher(txt, codec, base), "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
def demo(self, ui): ui.message("===== Demo Mode =====") ui.message("Running a small demo/testing!") ui.message("--- Encoding ---") text = "Hello World!" ui.message("Data to cypher: {}\n".format(text)) ui.message("Octopus cyphered data (binary, octal, decimal and " "hexadecimal utf-8):\n {}" "".format("\n ".join( octopus.cypher(text, bases=(2, 8, 10, 16))))) ui.message("") ui.message("--- Decoding ---") ui.message("+ In general, you can let Octopus find which base is " "used.") htext = "127145154143157155145041040040040346254242040350277216041" ui.message("“Numbers” utf-8 text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="utf-8"))) ui.message("") htext = "110001011100001011000011110001001100100111000011" ui.message("“Numbers” ebcdic text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="cp500"))) ui.message("") ui.message("+ The input text to decypher may have space-separated " "bytes:") htext = "1001111 1100011 1110100 1101111 1110000 1110101 1110011" ui.message("“Numbers” ascii-7 text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="ascii7"))) ui.message("") ui.message("--- Won’t work ---") ui.message("+ The input text to decypher must contain only valid " "digits for the given base:") htext = "011001010111211101101100015000110110111101101101011a" \ "001010010001" ui.message("“Numbers” text used as binary input: {}".format(htext)) try: ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="ascii", 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 = "01100101 0110111 0110110 0110011 0110111 0101101 0110011 " \ "0000001" ui.message("“Numbers” text used as input: {}".format(htext)) try: ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="ascii", base=2))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.message("+ Auto-detection of the base might fail, especially with " "short messages. In the example below (decimal EBCDIC), as " "there are no '8' nor '9', the tool detect it as octal.") htext = "131136133131146064137163064150164163" ui.message("“Numbers” EBCDIC text used as input: {}".format(htext)) ui.message("The auto-detected decypherd data is: {}" "".format(octopus.decypher(htext, codec="cp500"))) ui.message("The decimal decypherd data is: {}" "".format(octopus.decypher(htext, codec="cp500", base=10))) 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("--- Encoding ---") text = "Hello World!" ui.message("Data to cypher: {}\n".format(text)) ui.message("Octopus cyphered data (binary, octal, decimal and " "hexadecimal utf-8):\n {}" "".format("\n ".join(octopus.cypher(text, bases=(2, 8, 10, 16))))) ui.message("") ui.message("--- Decoding ---") ui.message("+ In general, you can let Octopus find which base is " "used.") htext = "127145154143157155145041040040040346254242040350277216041" ui.message("“Numbers” utf-8 text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="utf-8"))) ui.message("") htext = "110001011100001011000011110001001100100111000011" ui.message("“Numbers” ebcdic text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="cp500"))) ui.message("") ui.message("+ The input text to decypher may have space-separated " "bytes:") htext = "1001111 1100011 1110100 1101111 1110000 1110101 1110011" ui.message("“Numbers” ascii-7 text used as input: {}".format(htext)) ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="ascii7"))) ui.message("") ui.message("--- Won’t work ---") ui.message("+ The input text to decypher must contain only valid " "digits for the given base:") htext = "011001010111211101101100015000110110111101101101011a" \ "001010010001" ui.message("“Numbers” text used as binary input: {}".format(htext)) try: ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="ascii", 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 = "01100101 0110111 0110110 0110011 0110111 0101101 0110011 " \ "0000001" ui.message("“Numbers” text used as input: {}".format(htext)) try: ui.message("The decypherd data is: {}" "".format(octopus.decypher(htext, codec="ascii", base=2))) except Exception as e: ui.message(str(e), level=ui.ERROR) ui.message("") ui.message("+ Auto-detection of the base might fail, especially with " "short messages. In the example below (decimal EBCDIC), as " "there are no '8' nor '9', the tool detect it as octal.") htext = "131136133131146064137163064150164163" ui.message("“Numbers” EBCDIC text used as input: {}".format(htext)) ui.message("The auto-detected decypherd data is: {}" "".format(octopus.decypher(htext, codec="cp500"))) ui.message("The decimal decypherd data is: {}" "".format(octopus.decypher(htext, codec="cp500", base=10))) ui.message("") ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)