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

        while 1:
            done = False
            while 1:
                exhaustive = False
                threshold = 0.8
                txt = ui.text_input("Text to cypher to atomic digits",
                                    sub_type=ui.UPPER)
                if txt is None:
                    break  # Go back to main Cypher menu.

                options = [("exhst", "*exhaustive cyphering", ""),
                           ("simple", "or $simple one", "")]
                answ = ui.get_choice("Do you want to use", options,
                                     oneline=True)
                if answ == "exhst":
                    exhaustive = True
                    t = ui.get_data("Cypher threshold (nothing to use default "
                                    "{} one): ".format(threshold),
                                    sub_type=ui.FLOAT, allow_void=True)
                    if t is not None:
                        threshold = t

                try:
                    # Will also raise an exception if data is None.
                    txt = atomicdigits.cypher(txt, exhaustive=exhaustive,
                                              min_cypher=threshold)
                    if exhaustive:
                        txt = self._get_exhaustive_txt(txt, ui,
                                                       min_cypher=threshold)
                    done = True  # Out of those loops, output result.
                    break
                except Exception as e:
                    if utils.DEBUG:
                        import traceback
                        traceback.print_tb(sys.exc_info()[2])
                    ui.message(str(e), level=ui.ERROR)
                    options = [("retry", "*try again", ""),
                               ("menu", "or go back to *menu", "")]
                    answ = ui.get_choice("Could not convert that data into "
                                         "atomic digits, please", options,
                                         oneline=True)
                    if answ in {None, "menu"}:
                        return  # Go back to main Sema menu.
                    # Else, retry with another data to hide.

            if done:
                ui.text_output("Text successfully converted", txt,
                               "Atomic digits version of text")

            options = [("redo", "*cypher another text", ""),
                       ("quit", "or go back to *menu", "")]
            answ = ui.get_choice("Do you want to", options, oneline=True)
            if answ in {None, "quit"}:
                return
Esempio n. 2
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. 3
0
    def cypher(self, ui):
        """Interactive version of cypher()."""
        txt = ""
        ui.message("===== Cypher Mode =====")

        while 1:
            done = False
            while 1:
                exhaustive = False
                threshold = 0.8
                txt = ui.text_input("Text to cypher to atomic digits",
                                    sub_type=ui.UPPER)
                if txt is None:
                    break  # Go back to main Cypher menu.

                options = [("exhst", "*exhaustive cyphering", ""),
                           ("simple", "or $simple one", "")]
                answ = ui.get_choice("Do you want to use",
                                     options,
                                     oneline=True)
                if answ == "exhst":
                    exhaustive = True
                    t = ui.get_data("Cypher threshold (nothing to use default "
                                    "{} one): ".format(threshold),
                                    sub_type=ui.FLOAT,
                                    allow_void=True)
                    if t is not None:
                        threshold = t

                try:
                    # Will also raise an exception if data is None.
                    txt = atomicdigits.cypher(txt,
                                              exhaustive=exhaustive,
                                              min_cypher=threshold)
                    if exhaustive:
                        txt = self._get_exhaustive_txt(txt,
                                                       ui,
                                                       min_cypher=threshold)
                    done = True  # Out of those loops, output result.
                    break
                except Exception as e:
                    if utils.DEBUG:
                        import traceback
                        traceback.print_tb(sys.exc_info()[2])
                    ui.message(str(e), level=ui.ERROR)
                    options = [("retry", "*try again", ""),
                               ("menu", "or go back to *menu", "")]
                    answ = ui.get_choice(
                        "Could not convert that data into "
                        "atomic digits, please",
                        options,
                        oneline=True)
                    if answ in {None, "menu"}:
                        return  # Go back to main Sema menu.
                    # Else, retry with another data to hide.

            if done:
                ui.text_output("Text successfully converted", txt,
                               "Atomic digits version of text")

            options = [("redo", "*cypher another text", ""),
                       ("quit", "or go back to *menu", "")]
            answ = ui.get_choice("Do you want to", options, oneline=True)
            if answ in {None, "quit"}:
                return
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)