示例#1
0
    def decypher(self, ui):
        """Interactive version of decypher()."""
        txt = ""
        ui.message("===== Decypher Mode =====")

        while 1:
            txt = ui.text_input("Please choose some Baudot text")

            # 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("Text successfully decyphered",
                               baudot.decypher(txt, base),
                               "The decyphered text 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
示例#2
0
    def decypher(self, ui):
        """Interactive version of decypher()."""
        txt = ""
        ui.message("===== Decypher Mode =====")

        while 1:
            txt = ui.text_input("Please choose some Baudot text")

            # 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("Text successfully decyphered",
                               baudot.decypher(txt, base),
                               "The decyphered text 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
示例#3
0
    def demo(self, ui):
        ui.message("===== Demo Mode =====")
        ui.message("Running a small demo/testing!")
        ui.message("")

        ui.message("--- Encoding ---")
        text = "bye bye 2011 :)"
        ui.message("Data to cypher: {}\n".format(text))
        ui.message("Baudot cyphered data (binary, octal, decimal and "
                   "hexadecimal):\n    {}"
                   "".format("\n    ".join(
                       baudot.cypher(text, bases=(2, 8, 10, 16)))))
        ui.message("")

        ui.message("--- Decoding ---")
        ui.message("+ In general, you can let Baudot find which base is used.")
        htext = "1f1401121218041b131617130d"
        ui.message("Baudot text used as input: {}".format(htext))
        ui.message("The decypherd data is: {}"
                   "".format(baudot.decypher(htext)))
        ui.message("")

        ui.message("+ The input text to decypher may have space-separated "
                   "bytes:")
        htext = "11111 10100 00001 10010 10010 11000 00100 11011 10011 " \
                "10110 10111 10011 01101"
        ui.message("Baudot text used as input: {}".format(htext))
        ui.message("The decypherd data is: {}"
                   "".format(baudot.decypher(htext)))
        ui.message("")

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to cypher must contain only valid "
                   "chars (ascii lowercase, digits, and a few others):")
        text = "Baudot was used by “paper tapes”…"
        ui.message("Text to cypher: {}".format(text))
        try:
            ui.message("The cypherd data is: {}"
                       "".format(baudot.cypher(text)))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

        ui.message("+ The input text to decypher must contain only valid "
                   "digits for the given base:")
        htext = "111111010111211101101100015000110110111101101101011a" \
                "0010100100201"
        ui.message("Baudot text used as binary input: {}".format(htext))
        try:
            ui.message("The decypherd data is: {}"
                       "".format(baudot.decypher(htext, 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 = "11111 01101 010110 01011 00111 01011 110011 00001"
        ui.message("Baudot text used as input: {}".format(htext))
        try:
            ui.message("The decypherd data is: {}"
                       "".format(baudot.decypher(htext, base=2)))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

        ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)
示例#4
0
    def demo(self, ui):
        ui.message("===== Demo Mode =====")
        ui.message("Running a small demo/testing!")
        ui.message("")

        ui.message("--- Encoding ---")
        text = "bye bye 2011 :)"
        ui.message("Data to cypher: {}\n".format(text))
        ui.message("Baudot cyphered data (binary, octal, decimal and "
                   "hexadecimal):\n    {}"
                   "".format("\n    ".join(baudot.cypher(text,
                                                     bases=(2, 8, 10, 16)))))
        ui.message("")

        ui.message("--- Decoding ---")
        ui.message("+ In general, you can let Baudot find which base is used.")
        htext = "1f1401121218041b131617130d"
        ui.message("Baudot text used as input: {}".format(htext))
        ui.message("The decypherd data is: {}"
                   "".format(baudot.decypher(htext)))
        ui.message("")

        ui.message("+ The input text to decypher may have space-separated "
                   "bytes:")
        htext = "11111 10100 00001 10010 10010 11000 00100 11011 10011 " \
                "10110 10111 10011 01101"
        ui.message("Baudot text used as input: {}".format(htext))
        ui.message("The decypherd data is: {}"
                   "".format(baudot.decypher(htext)))
        ui.message("")

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to cypher must contain only valid "
                   "chars (ascii lowercase, digits, and a few others):")
        text = "Baudot was used by “paper tapes”…"
        ui.message("Text to cypher: {}".format(text))
        try:
            ui.message("The cypherd data is: {}"
                       "".format(baudot.cypher(text)))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

        ui.message("+ The input text to decypher must contain only valid "
                   "digits for the given base:")
        htext = "111111010111211101101100015000110110111101101101011a" \
                "0010100100201"
        ui.message("Baudot text used as binary input: {}".format(htext))
        try:
            ui.message("The decypherd data is: {}"
                       "".format(baudot.decypher(htext, 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 = "11111 01101 010110 01011 00111 01011 110011 00001"
        ui.message("Baudot text used as input: {}".format(htext))
        try:
            ui.message("The decypherd data is: {}"
                       "".format(baudot.decypher(htext, base=2)))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

        ui.get_choice("", [("", "Go back to $menu", "")], oneline=True)