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

        ui.message("--- Encoding ---")
        ui.message("Data to cypher: {}\n".format("Hello World!"))
        ui.message("Binary cypherd data: {}"
                   "".format(binary.cypher("Hello World!")))
        ui.message("")

        htext = "01110111011001010110110001100011011011110110110101100101" \
                "00100001"
        ui.message("--- Decoding ---")
        ui.message("“Binary” text used as input: {}".format(htext))
        ui.message("The decypherd data is: {}".format(binary.decypher(htext)))

        ui.message("+ The input text to decypher may have space-separated "
                   "octets:")
        htext = "01110111 01100101 01101100 01100011 01101111 01101101 " \
                "01100101 00100001"
        ui.message("--- Decoding ---")
        ui.message("“Binary” text used as input: {}".format(htext))
        ui.message("The decypherd data is: {}".format(binary.decypher(htext)))

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to decypher must be (0, 1) digits only:")
        htext = "011001010111211101101100015000110110111101101101011a" \
                "001010010001"
        ui.message("“Binary” text used as input: {}".format(htext))
        try:
            ui.message("The decypherd data is: {}"
                       "".format(binary.decypher(htext)))
        except Exception as e:
            ui.message(str(e), ui.ERROR)

        ui.message("+ The input text to decypher must have a length multiple "
                   "of 8 (once spaces have been striped):")
        htext = "01100101 0110111 0110110 0110011 0110111 0101101 0110011 " \
                "0000001"
        ui.message("“Binary” text used as input: {}".format(htext))
        try:
            ui.message("The decypherd data is: {}"
                       "".format(binary.decypher(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("--- Encoding ---")
        ui.message("Data to cypher: {}\n".format("Hello World!"))
        ui.message("Binary cypherd data: {}"
                   "".format(binary.cypher("Hello World!")))
        ui.message("")

        htext = "01110111011001010110110001100011011011110110110101100101" \
                "00100001"
        ui.message("--- Decoding ---")
        ui.message("“Binary” text used as input: {}".format(htext))
        ui.message("The decypherd data is: {}".format(binary.decypher(htext)))

        ui.message("+ The input text to decypher may have space-separated "
                   "octets:")
        htext = "01110111 01100101 01101100 01100011 01101111 01101101 " \
                "01100101 00100001"
        ui.message("--- Decoding ---")
        ui.message("“Binary” text used as input: {}".format(htext))
        ui.message("The decypherd data is: {}".format(binary.decypher(htext)))

        ui.message("--- Won’t work ---")
        ui.message("+ The input text to decypher must be (0, 1) digits only:")
        htext = "011001010111211101101100015000110110111101101101011a" \
                "001010010001"
        ui.message("“Binary” text used as input: {}".format(htext))
        try:
            ui.message("The decypherd data is: {}"
                       "".format(binary.decypher(htext)))
        except Exception as e:
            ui.message(str(e), ui.ERROR)

        ui.message("+ The input text to decypher must have a length multiple "
                   "of 8 (once spaces have been striped):")
        htext = "01100101 0110111 0110110 0110011 0110111 0101101 0110011 " \
                "0000001"
        ui.message("“Binary” text used as input: {}".format(htext))
        try:
            ui.message("The decypherd data is: {}"
                       "".format(binary.decypher(htext)))
        except Exception as e:
            ui.message(str(e), ui.ERROR)

        ui.get_choice("", [("", "Go back to *menu", "")], oneline=True)
Example #3
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 binary")
                if txt is None:
                    break  # Go back to main Cypher menu.

                try:
                    # Will also raise an exception if data is None.
                    codec = ui.get_data("Type the codec you want to use (e.g. "
                                        "'utf-8'), or leave empty to use "
                                        "default 'ascii' one: ")
                    if not codec:
                        codec = "ascii"
                    txt = binary.cypher(txt, codec)
                    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 "
                        "binary, 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("Data successfully converted", txt,
                               "Binary form of data")

            options = [("redo", "*cypher another data", ""),
                       ("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 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 binary")
                if txt is None:
                    break  # Go back to main Cypher menu.

                try:
                    # Will also raise an exception if data is None.
                    codec = ui.get_data("Type the codec you want to use (e.g. "
                                        "'utf-8'), or leave empty to use "
                                        "default 'ascii' one: ")
                    if not codec:
                        codec = "ascii"
                    txt = binary.cypher(txt, codec)
                    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 "
                                         "binary, 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("Data successfully converted", txt,
                               "Binary form of data")

            options = [("redo", "*cypher another data", ""),
                       ("quit", "or go back to *menu", "")]
            answ = ui.get_choice("Do you want to", options, oneline=True)
            if answ in {None, "quit"}:
                return