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

        while 1:
            done = False
            while 1:
                txt = ui.text_input("Text to cypher to chinesecypher")
                if txt is None:
                    break  # Go back to main Cypher menu.

                options = [((True, False, False), "*Chinese", ""),
                           ((False, True, False), "*Samurai", ""),
                           ((False, False, True), "*Digits", ""),
                           ((True, True, True), "or *all of them", "")]
                chinese, samurai, digits = \
                         ui.get_choice("What version(s) do you want to get, ",
                                       options, oneline=True)

                try:
                    # Will also raise an exception if data is None.
                    txt = chinesecypher.cypher(txt,
                                               chinese=chinese,
                                               samurai=samurai,
                                               digits=digits)
                    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 "
                        "chinesecypher, 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:
                if len(txt) > 1:
                    txt = "\n    " + "\n    ".join(txt)
                else:
                    txt, = txt
                ui.text_output("Text successfully converted", txt,
                               "ChineseCypher 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
    def cypher(self, ui):
        """Interactive version of cypher()."""
        txt = ""
        ui.message("===== Cypher Mode =====")

        while 1:
            done = False
            while 1:
                txt = ui.text_input("Text to cypher to chinesecypher")
                if txt is None:
                    break  # Go back to main Cypher menu.

                options = [((True, False, False), "*Chinese", ""),
                           ((False, True, False), "*Samurai", ""),
                           ((False, False, True), "*Digits", ""),
                           ((True, True, True), "or *all of them", "")]
                chinese, samurai, digits = \
                         ui.get_choice("What version(s) do you want to get, ",
                                       options, oneline=True)

                try:
                    # Will also raise an exception if data is None.
                    txt = chinesecypher.cypher(txt, chinese=chinese,
                                               samurai=samurai, digits=digits)
                    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 "
                                         "chinesecypher, 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:
                if len(txt) > 1:
                    txt = "\n    " + "\n    ".join(txt)
                else:
                    txt, = txt
                ui.text_output("Text successfully converted", txt,
                               "ChineseCypher 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
    def demo(self, ui):
        ui.message("===== Demo Mode =====")
        ui.message("Running a small demo/testing!\n")

        ui.message("--- Cyphering ---")
        text = "china is a big country"
        ui.message("Data to cypher: {}\n".format(text))
        ui.message("ChineseCypher cyphered data, (Chinese, Samurai and "
                   "digits):\n    {}"
                   "".format("\n    "
                             "".join(chinesecypher.cypher(text,
                                                          chinese=True,
                                                          samurai=True,
                                                          digits=True))))
        ui.message("")

        ui.message("--- Decyphering Chinese version ---")
        htext = "————||||| ——||| ——  " \
                "——||| — —|| ———|| — —||| —— ———|||| ——————"
        ui.message("ChineseCypher text used as input: {}".format(htext))
        ui.message("The decyphered data is: {}"
                   "".format(chinesecypher.decypher(htext)))
        ui.message("")

        ui.message("--- Decyphering Samurai version ---")
        htext = "||||————— ||——— ||  " \
                "||——— | |—— |||—— | |——— || |||———— ||||||"
        ui.message("ChineseCypher text used as input: {}".format(htext))
        ui.message("The decyphered data is: {}"
                   "".format(chinesecypher.decypher(htext)))
        ui.message("")

        ui.message("--- Decyphering Digits version ---")
        htext = "45 23 20  23 10 12 32 10 13 20 34 60"
        ui.message("ChineseCypher text used as input: {}".format(htext))
        ui.message("The decyphered data is: {}"
                   "".format(chinesecypher.decypher(htext)))
        ui.message("")

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to cypher must be acsii lowercase "
                   "letters only:")
        ui.message("Data to cypher: {}\n".format("Hello Wolrd!"))
        try:
            ui.message("ChineseCypher cyphered data: {}"
                       "".format(chinesecypher.cypher("Hello World!",
                                                      chinese=True)))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

        ui.message("+ The input text to decypher must be phone digits only:")
        htext = "49 23 ||———  23 10 12 ———|| 10 13 88 34 60"
        ui.message("ChineseCypher text used as input: {}".format(htext))
        try:
            ui.message("The decyphered data is: {}"
                       "".format(chinesecypher.decypher(htext)))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

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

        ui.message("--- Cyphering ---")
        text = "china is a big country"
        ui.message("Data to cypher: {}\n".format(text))
        ui.message("ChineseCypher cyphered data, (Chinese, Samurai and "
                   "digits):\n    {}"
                   "".format("\n    "
                             "".join(
                                 chinesecypher.cypher(text,
                                                      chinese=True,
                                                      samurai=True,
                                                      digits=True))))
        ui.message("")

        ui.message("--- Decyphering Chinese version ---")
        htext = "————||||| ——||| ——  " \
                "——||| — —|| ———|| — —||| —— ———|||| ——————"
        ui.message("ChineseCypher text used as input: {}".format(htext))
        ui.message("The decyphered data is: {}"
                   "".format(chinesecypher.decypher(htext)))
        ui.message("")

        ui.message("--- Decyphering Samurai version ---")
        htext = "||||————— ||——— ||  " \
                "||——— | |—— |||—— | |——— || |||———— ||||||"
        ui.message("ChineseCypher text used as input: {}".format(htext))
        ui.message("The decyphered data is: {}"
                   "".format(chinesecypher.decypher(htext)))
        ui.message("")

        ui.message("--- Decyphering Digits version ---")
        htext = "45 23 20  23 10 12 32 10 13 20 34 60"
        ui.message("ChineseCypher text used as input: {}".format(htext))
        ui.message("The decyphered data is: {}"
                   "".format(chinesecypher.decypher(htext)))
        ui.message("")

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to cypher must be acsii lowercase "
                   "letters only:")
        ui.message("Data to cypher: {}\n".format("Hello Wolrd!"))
        try:
            ui.message("ChineseCypher cyphered data: {}"
                       "".format(
                           chinesecypher.cypher("Hello World!", chinese=True)))
        except Exception as e:
            ui.message(str(e), ui.ERROR)
        ui.message("")

        ui.message("+ The input text to decypher must be phone digits only:")
        htext = "49 23 ||———  23 10 12 ———|| 10 13 88 34 60"
        ui.message("ChineseCypher text used as input: {}".format(htext))
        try:
            ui.message("The decyphered data is: {}"
                       "".format(chinesecypher.decypher(htext)))
        except Exception as e:
            ui.message(str(e), ui.ERROR)
        ui.message("")

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