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

        while 1:
            txt = ui.text_input("Please choose some Prime text")

            # Get base.
            base = 1
            b = ui.text_input("Base prime to use", sub_type=ui.INT)
            if b:
                base = b

            try:
                ui.text_output("Text successfully decyphered",
                               prime.decypher(txt, base),
                               "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
Example #2
0
    def decypher(self, ui):
        """Interactive version of decypher()."""
        txt = ""
        ui.message("===== Decypher Mode =====")

        while 1:
            txt = ui.text_input("Please choose some Prime text")

            # Get base.
            base = 1
            b = ui.text_input("Base prime to use", sub_type=ui.INT)
            if b:
                base = b

            try:
                ui.text_output("Text successfully decyphered",
                               prime.decypher(txt, base),
                               "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
Example #3
0
    def demo(self, ui):
        ui.message("===== Demo Mode =====")
        ui.message("Running a small demo/testing!")
        ui.message("")

        ui.message("--- Cyphering ---")
        text = "prime numbers are widely used in cryptography"
        ui.message("Data to cypher: {}\n".format(text))
        ui.message("Prime cyphered data, base 1: {}"
                   "".format(prime.cypher(text, 1)))
        ui.message("Prime cyphered data, base 79: {}"
                   "".format(prime.cypher(text, 79)))
        ui.message("")

        ui.message("--- Decyphering ---")
        htext = "457 383 389 449  389 449  421 431  383 347 449 383  " \
                "457 347 349 409 367"
        ui.message("Prime text used as input (base 69): {}".format(htext))
        ui.message("The decyphered data is: {}"
                   "".format(prime.decypher(htext, 69)))
        ui.message("")

        ui.message("--- Won’t work ---")
        text = "The next prime year is 2017!"
        ui.message("+ The input text to cypher must be strict "
                   "ascii lowercase chars and spaces:")
        ui.message("Data to cypher: {}\n".format(text))
        try:
            ui.message("Prime cyphered data: {}"
                       "".format(prime.cypher(text)))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

        ui.message("+ The input text to decypher must be valid Prime "
                   "encoded text:")
        htext = "13447 24 14 15  15 234 2345 6  24 234 1345 3457 2345  " \
                "24 2345 1778 1456"
        ui.message("Prime text used as input (base 1): {}".format(htext))
        try:
            ui.message("The decyphered data is: {}"
                       "".format(prime.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!")
        ui.message("")

        ui.message("--- Cyphering ---")
        text = "prime numbers are widely used in cryptography"
        ui.message("Data to cypher: {}\n".format(text))
        ui.message("Prime cyphered data, base 1: {}"
                   "".format(prime.cypher(text, 1)))
        ui.message("Prime cyphered data, base 79: {}"
                   "".format(prime.cypher(text, 79)))
        ui.message("")

        ui.message("--- Decyphering ---")
        htext = "457 383 389 449  389 449  421 431  383 347 449 383  " \
                "457 347 349 409 367"
        ui.message("Prime text used as input (base 69): {}".format(htext))
        ui.message("The decyphered data is: {}"
                   "".format(prime.decypher(htext, 69)))
        ui.message("")

        ui.message("--- Won’t work ---")
        text = "The next prime year is 2017!"
        ui.message("+ The input text to cypher must be strict "
                   "ascii lowercase chars and spaces:")
        ui.message("Data to cypher: {}\n".format(text))
        try:
            ui.message("Prime cyphered data: {}"
                       "".format(prime.cypher(text)))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

        ui.message("+ The input text to decypher must be valid Prime "
                   "encoded text:")
        htext = "13447 24 14 15  15 234 2345 6  24 234 1345 3457 2345  " \
                "24 2345 1778 1456"
        ui.message("Prime text used as input (base 1): {}".format(htext))
        try:
            ui.message("The decyphered data is: {}"
                       "".format(prime.decypher(htext)))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

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