Example #1
0
    def demo(self, ui):
        ui.message("===== Demo Mode =====")
        ui.message("Running a small demo/testing!")

        ui.message("--- Encrypting ---")
        ui.message("Data to encrypt: {}\n".format("hello wolrd"))
        ui.message("CodeABC encrypted data: {}"
                   "".format(codeabc.encrypt("hello world")))

        htext = "66 444 222 33 0 222 666 3 33 0 44 33 44"
        ui.message("--- Deciphering ---")
        ui.message("CodeABC text used as input: {}".format(htext))
        ui.message("The deciphered data is: {}"
                   "".format(codeabc.decipher(htext)))

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to encrypt must be space and acsii "
                   "lowercase letters only:")
        ui.message("Data to encrypt: {}\n".format("Hello Wolrd!"))
        try:
            ui.message("CodeABC encrypted data: {}"
                       "".format(codeabc.encrypt("Hello World!")))
        except Exception as e:
            ui.message(str(e), ui.ERROR)

        ui.message("+ The input text to decipher must be valid abc codes "
                   "only:")
        htext = "66 444 222 3333 0 222 666 3 33 00 44 33 44"
        ui.message("CodeABC text used as input: {}".format(htext))
        try:
            ui.message("The deciphered data is: {}"
                       "".format(codeabc.decipher(htext)))
        except Exception as e:
            ui.message(str(e), ui.ERROR)

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

        ui.message("--- Encrypting ---")
        ui.message("Data to encrypt: {}\n".format("hello wolrd"))
        ui.message("CodeABC encrypted data: {}"
                   "".format(codeabc.encrypt("hello world")))

        htext = "66 444 222 33 0 222 666 3 33 0 44 33 44"
        ui.message("--- Deciphering ---")
        ui.message("CodeABC text used as input: {}".format(htext))
        ui.message("The deciphered data is: {}"
                   "".format(codeabc.decipher(htext)))

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to encrypt must be space and acsii "
                   "lowercase letters only:")
        ui.message("Data to encrypt: {}\n".format("Hello Wolrd!"))
        try:
            ui.message("CodeABC encrypted data: {}"
                       "".format(codeabc.encrypt("Hello World!")))
        except Exception as e:
            ui.message(str(e), ui.ERROR)

        ui.message("+ The input text to decipher must be valid abc codes "
                   "only:")
        htext = "66 444 222 3333 0 222 666 3 33 00 44 33 44"
        ui.message("CodeABC text used as input: {}".format(htext))
        try:
            ui.message("The deciphered data is: {}"
                       "".format(codeabc.decipher(htext)))
        except Exception as e:
            ui.message(str(e), ui.ERROR)

        ui.get_choice("", [("", "Go back to *menu", "")], oneline=True)
Example #3
0
    def encrypt(self, ui):
        """Interactive version of encrypt()."""
        txt = ""
        ui.message("===== Encrypt Mode =====")

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

                try:
                    # Will also raise an exception if data is None.
                    txt = codeabc.encrypt(txt)
                    done = True  # Out of those loops, output result.
                    break
                except Exception as e:
                    print(e)
                    options = [("retry", "*try again", ""),
                               ("menu", "or go back to *menu", "")]
                    answ = ui.get_choice(
                        "Could not convert that data into "
                        "codeABC, 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,
                               "CodeABC version of text")

            options = [("redo", "*encrypt 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
Example #4
0
    def encrypt(self, ui):
        """Interactive version of encrypt()."""
        txt = ""
        ui.message("===== Encrypt Mode =====")

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

                try:
                    # Will also raise an exception if data is None.
                    txt = codeabc.encrypt(txt)
                    done = True  # Out of those loops, output result.
                    break
                except Exception as e:
                    print(e)
                    options = [("retry", "*try again", ""),
                               ("menu", "or go back to *menu", "")]
                    answ = ui.get_choice("Could not convert that data into "
                                         "codeABC, 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,
                               "CodeABC version of text")

            options = [("redo", "*encrypt 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