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

        while 1:
            txt = ui.text_input("Please choose some atomic digits text",
                                sub_type=ui.UPPER)

            try:
                txt = atomicdigits.decypher(txt)
                txt = "\n    " + "\n    ".join(utils.format_multiwords(txt))
                ui.text_output("Text successfully decyphered", txt,
                               "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
Esempio n. 2
0
    def decypher(self, ui):
        """Interactive version of decypher()."""
        txt = ""
        ui.message("===== Decypher Mode =====")

        while 1:
            txt = ui.text_input("Please choose some atomic digits text",
                                sub_type=ui.UPPER)

            try:
                txt = atomicdigits.decypher(txt)
                txt = "\n    " + "\n    ".join(utils.format_multiwords(txt))
                ui.text_output("Text successfully decyphered",
                               txt,
                               "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
Esempio n. 3
0
    def demo(self, ui):
        ui.message("===== Demo Mode =====")
        ui.message("Running a small demo/testing!")
        ui.message("")

        ui.message("--- Cyphering ---")
        ui.message("Data to cypher: {}".format("HOW ARE YOU NICEDAYISNTIT"))
        out = atomicdigits.cypher("HOW ARE YOU NICEDAYISNTIT")
        ui.message("Atomic digits cyphered data:\n    {}"
                   "".format("\n    ".join(utils.format_multiwords(out,
                                                                   sep="  "))))
        ui.message("")

        htext = "90 53 16  53 16  A  Q 92 53 52  16 53 M 15 L E  52 16 T"
        ui.message("--- Decyphering ---")
        ui.message("Atomic digits text used as input: {}".format(htext))
        out = atomicdigits.decypher(htext)
        ui.message("The decyphered data is:\n    {}"
                   "".format("\n    ".join(utils.format_multiwords(out))))
        ui.message("")

        ui.message("--- Notes ---")
        ui.message("+ You can choose the optionnal Exhaustive option, to get "
                   "all possible encodings of each words higher than the "
                   "given threshold of cyphering (or the highest possible):")
        ui.message("Data to cypher: {}".format("HOW ARE YOU NICEDAYISNTIT"))
        out = atomicdigits.cypher("HOW ARE YOU NICEDAYISNTIT", exhaustive=True,
                             min_cypher=0.8)
        out = self._get_exhaustive_txt(out, ui, min_cypher=0.8, act="all")
        ui.message(out)
        ui.message("")

        htext = "1874  A75  39892  75358DA39535081T"
        ui.message("+ You can try to decypher a text with atomic numbers "
                   "merged (i.e. no more spaces between them – nasty!):")
        ui.message("Data to decypher: {}".format(htext))
        out = atomicdigits.decypher(htext)
        ui.message("Atomic digits decyphered data:\n    {}"
                   "".format("\n    ".join(utils.format_multiwords(out))))
        ui.message("")

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to cypher must be ASCII uppercase "
                   "chars only:")
        ui.message("Data to cypher: {}\n".format("Hello WORLD !"))
        try:
            out = atomicdigits.cypher("Hello WORLD !")
            ui.message("Atomic digits cyphered data:\n    {}"
                       "".format("\n    ".join(utils.format_multiwords(out))))
        except Exception as e:
            ui.message(str(e), ui.ERROR)
        ui.message("")

        ui.message("+ The input text to decypher must be valid atomic digits:")
        htext = "90 53 016  53 16  A  Q 922 53 52  16 53 M 15 L E  52 16 T"
        ui.message("Atomic digits text used as input: {}".format(htext))
        try:
            out = atomicdigits.decypher(htext)
            ui.message("Atomic digits decyphered data:\n    {}"
                       "".format("\n    ".join(utils.format_multiwords(out))))
        except Exception as e:
            ui.message(str(e), ui.ERROR)
        ui.message("")

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

        ui.message("--- Cyphering ---")
        ui.message("Data to cypher: {}".format("HOW ARE YOU NICEDAYISNTIT"))
        out = atomicdigits.cypher("HOW ARE YOU NICEDAYISNTIT")
        ui.message("Atomic digits cyphered data:\n    {}"
                   "".format("\n    ".join(
                       utils.format_multiwords(out, sep="  "))))
        ui.message("")

        htext = "90 53 16  53 16  A  Q 92 53 52  16 53 M 15 L E  52 16 T"
        ui.message("--- Decyphering ---")
        ui.message("Atomic digits text used as input: {}".format(htext))
        out = atomicdigits.decypher(htext)
        ui.message("The decyphered data is:\n    {}"
                   "".format("\n    ".join(utils.format_multiwords(out))))
        ui.message("")

        ui.message("--- Notes ---")
        ui.message("+ You can choose the optionnal Exhaustive option, to get "
                   "all possible encodings of each words higher than the "
                   "given threshold of cyphering (or the highest possible):")
        ui.message("Data to cypher: {}".format("HOW ARE YOU NICEDAYISNTIT"))
        out = atomicdigits.cypher("HOW ARE YOU NICEDAYISNTIT",
                                  exhaustive=True,
                                  min_cypher=0.8)
        out = self._get_exhaustive_txt(out, ui, min_cypher=0.8, act="all")
        ui.message(out)
        ui.message("")

        htext = "1874  A75  39892  75358DA39535081T"
        ui.message("+ You can try to decypher a text with atomic numbers "
                   "merged (i.e. no more spaces between them – nasty!):")
        ui.message("Data to decypher: {}".format(htext))
        out = atomicdigits.decypher(htext)
        ui.message("Atomic digits decyphered data:\n    {}"
                   "".format("\n    ".join(utils.format_multiwords(out))))
        ui.message("")

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to cypher must be ASCII uppercase "
                   "chars only:")
        ui.message("Data to cypher: {}\n".format("Hello WORLD !"))
        try:
            out = atomicdigits.cypher("Hello WORLD !")
            ui.message("Atomic digits cyphered data:\n    {}"
                       "".format("\n    ".join(utils.format_multiwords(out))))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

        ui.message("+ The input text to decypher must be valid atomic digits:")
        htext = "90 53 016  53 16  A  Q 922 53 52  16 53 M 15 L E  52 16 T"
        ui.message("Atomic digits text used as input: {}".format(htext))
        try:
            out = atomicdigits.decypher(htext)
            ui.message("Atomic digits decyphered data:\n    {}"
                       "".format("\n    ".join(utils.format_multiwords(out))))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

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