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

        while 1:
            done = False
            while 1:
                exhaustive = False
                goal = 0.2
                method = argots.JAVANAIS
                syllable = "uz"

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

                # Get obfuscating method.
                options = [(argots.JAVANAIS,
                            "$javanais cyphering", ""),
                           (argots.FEU, "langue de *feu", ""),
                           (argots.GENERIC, "*generic one", ""),
                           (argots.LARGONJI,
                            "or *largonji des loucherbèmes", "")]
                method = ui.get_choice("Do you want to use", options,
                                       oneline=True)

                if method == argots.LARGONJI:
                    # Get sets of suffix syllables.
                    v_sylb = argots.LARGONJI_SYLLABLES_V
                    s = ui.get_data("Suffix vowel-compliant syllables, comma "
                                    "separated (or nothing to use default "
                                    "'{}' ones): "
                                    "".format("', '".join(v_sylb)),
                                    allow_void=True)
                    if s:
                        v_sylb = [s.strip() for s in s.split(",")]

                    c_sylb = argots.LARGONJI_SYLLABLES_C
                    s = ui.get_data("Suffix consonant-compliant syllables, "
                                    "comma separated (or nothing to use "
                                    "default '{}' ones): "
                                    "".format("', '".join(c_sylb)),
                                    allow_void=True)
                    if s:
                        c_sylb = [s.strip() for s in s.split(",")]

                else:
                    if method == argots.JAVANAIS:
                        syllable = "av"
                    elif method == argots.FEU:
                        syllable = "fe"

                    # Get obfuscating syllable.
                    s = ui.get_data("Obfuscating syllable (or nothing to use "
                                    "default '{}' one): ".format(syllable),
                                    allow_void=True,
                                    validate=self._validate,
                                    validate_kwargs={'method': method})
                    if s:
                        syllable = s

                    # What algo to use.
                    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 goal (nothing to use default "
                                        "{} one): ".format(goal),
                                        sub_type=ui.FLOAT, allow_void=True)
                        if t is not None:
                            goal = t

                try:
                    if method == argots.LARGONJI:
                        txt = argots.cypher_largonji(txt, v_sylb, c_sylb)
                        txt = self._get_largonji_txt(txt, ui)
                    else:
                        txt = argots.cypher(txt, method, syllable,
                                            exhaustive=exhaustive,
                                            cypher_goal=goal)
                        if exhaustive:
                            txt = self._get_exhaustive_txt(txt, ui,
                                                           cypher_goal=goal)
                    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 "
                                         "argot, 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:
                meth = "Generic"
                if method == argots.JAVANAIS:
                    meth = "Argot Javanais"
                elif method == argots.FEU:
                    meth = "Langue de Feu"
                elif method == argots.LARGONJI:
                    meth = "Largonji des Loucherbèms"
                ui.text_output("Text successfully converted", txt,
                               "{} version of text".format(meth))

            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
Exemple #2
0
    def cypher(self, ui):
        """Interactive version of cypher()."""
        txt = ""
        ui.message("===== Cypher Mode =====")

        while 1:
            done = False
            while 1:
                exhaustive = False
                goal = 0.2
                method = argots.JAVANAIS
                syllable = "uz"

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

                # Get obfuscating method.
                options = [(argots.JAVANAIS, "$javanais cyphering", ""),
                           (argots.FEU, "langue de *feu", ""),
                           (argots.GENERIC, "*generic one", ""),
                           (argots.LARGONJI, "or *largonji des loucherbèmes",
                            "")]
                method = ui.get_choice("Do you want to use",
                                       options,
                                       oneline=True)

                if method == argots.LARGONJI:
                    # Get sets of suffix syllables.
                    v_sylb = argots.LARGONJI_SYLLABLES_V
                    s = ui.get_data("Suffix vowel-compliant syllables, comma "
                                    "separated (or nothing to use default "
                                    "'{}' ones): "
                                    "".format("', '".join(v_sylb)),
                                    allow_void=True)
                    if s:
                        v_sylb = [s.strip() for s in s.split(",")]

                    c_sylb = argots.LARGONJI_SYLLABLES_C
                    s = ui.get_data("Suffix consonant-compliant syllables, "
                                    "comma separated (or nothing to use "
                                    "default '{}' ones): "
                                    "".format("', '".join(c_sylb)),
                                    allow_void=True)
                    if s:
                        c_sylb = [s.strip() for s in s.split(",")]

                else:
                    if method == argots.JAVANAIS:
                        syllable = "av"
                    elif method == argots.FEU:
                        syllable = "fe"

                    # Get obfuscating syllable.
                    s = ui.get_data("Obfuscating syllable (or nothing to use "
                                    "default '{}' one): ".format(syllable),
                                    allow_void=True,
                                    validate=self._validate,
                                    validate_kwargs={'method': method})
                    if s:
                        syllable = s

                    # What algo to use.
                    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 goal (nothing to use default "
                                        "{} one): ".format(goal),
                                        sub_type=ui.FLOAT,
                                        allow_void=True)
                        if t is not None:
                            goal = t

                try:
                    if method == argots.LARGONJI:
                        txt = argots.cypher_largonji(txt, v_sylb, c_sylb)
                        txt = self._get_largonji_txt(txt, ui)
                    else:
                        txt = argots.cypher(txt,
                                            method,
                                            syllable,
                                            exhaustive=exhaustive,
                                            cypher_goal=goal)
                        if exhaustive:
                            txt = self._get_exhaustive_txt(txt,
                                                           ui,
                                                           cypher_goal=goal)
                    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 "
                        "argot, 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:
                meth = "Generic"
                if method == argots.JAVANAIS:
                    meth = "Argot Javanais"
                elif method == argots.FEU:
                    meth = "Langue de Feu"
                elif method == argots.LARGONJI:
                    meth = "Largonji des Loucherbèms"
                ui.text_output("Text successfully converted", txt,
                               "{} version of text".format(meth))

            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
Exemple #3
0
    def demo(self, ui):
        ui.message("===== Demo Mode =====")
        ui.message("Running a small demo/testing!")
        ui.message("")

        ui.message("--- Cyphering ---")
        ui.message("+ Argot Javanais & co.")
        text = "Les « Blousons Noirs » vous parlent…"
        ui.message("Data to cypher: {}".format(text))
        out = argots.cypher(text, argots.JAVANAIS, 'av')
        ui.message("Argot Javanais with 'av': {}".format(out))
        ui.message("")

        ui.message("+ Largonji des Loucherbèmes.")
        text = "Les bouchers de la Villette osent un tango langoureux !"
        ui.message("Data to cypher: {}".format(text))
        out = argots.cypher_largonji(text, argots.LARGONJI_SYLLABLES_V,
                                     argots.LARGONJI_SYLLABLES_C)
        out = self._get_largonji_txt(out, ui, act="rand")
        ui.message("Largonji des Loucherbèmes: {}".format(out))
        ui.message("")

        ui.message("--- Decyphering ---")
        ui.message("+ Argot Javanais & co.")
        htext = "LEfes EfApEfachEfes sEfont sEfur lEfe sEfentEfier dEfes " \
                "HEfallEfes."
        ui.message("Note that most of the time, you can use default options "
                   "here (i.e. Generic, and give no obfuscating syllable), "
                   "as that kind of “cyphering” is really easy to break!")
        ui.message("Langue de Feu text used as input: {}".format(htext))
        out = argots.decypher(htext, argots.FEU)
        ui.message("The decyphered data is:\n    With '{}': {}"
                   "".format(out[0][0], out[0][1]))
        ui.message("")

        ui.message("+ Largonji des Loucherbèmes.")
        htext = "La mie du loucherbouche lricottefesse lavecouche le " \
                "loulangerbesse !"
        ui.message("Largonji de Loucherbems text used as input: {}"
                   "".format(htext))
        out = argots.decypher_largonji(htext)
        ui.message("The decyphered data is:\n    {}"
                   "".format("\n    ".join(utils.format_multiwords(out))))
        ui.message("")

        ui.message("--- Notes ---")
        ui.message("+ With Argot Javanais & co, you can choose the optional "
                   "Exhaustive option, to get all possible encodings of each "
                   "words higher than the given goal of cyphering (or the "
                   "highest possible):")
        text = "Do you know Ménilmuche and Belleville ?"
        ui.message("Data to cypher: {}".format(text))
        out = argots.cypher(text, argots.GENERIC, 'uz', exhaustive=True,
                            cypher_goal=0.2)
        out = self._get_exhaustive_txt(out, ui, cypher_goal=0.2, act="goal")
        ui.message("Generic cyphered solutions with cypher factor higher "
                   "than 0.2:")
        ui.message(out)
        ui.message("")

        ui.message("+ Here is what you’ll get if you try to decypher some "
                   "largonji without giving any suffix syllables (note how "
                   "some words aren’t decyphered well at all):")
        htext = "La mie du loucherbouche lricottefesse lavecouche le " \
                "loulangerbesse !"
        ui.message("Largonji de Loucherbems text used as input: {}"
                   "".format(htext))
        out = argots.decypher_largonji(htext, (), ())
        ui.message("The decyphered data is:\n    {}"
                   "".format("\n    ".join(utils.format_multiwords(out))))
        ui.message("")

        ui.message("--- Won’t work ---")
        ui.message("+ With Argot Javanais & co, the obfuscating syllable "
                   "must comply to the chosen method!")
        text = "Hello WORLD !"
        ui.message("Data to cypher, using Javanais and 'eh': {}\n"
                   "".format(text))
        try:
            out = argots.cypher(text, argots.JAVANAIS, 'eh')
            ui.message("Javanais cyphered data: {}".format(out))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

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

        ui.message("--- Cyphering ---")
        ui.message("+ Argot Javanais & co.")
        text = "Les « Blousons Noirs » vous parlent…"
        ui.message("Data to cypher: {}".format(text))
        out = argots.cypher(text, argots.JAVANAIS, 'av')
        ui.message("Argot Javanais with 'av': {}".format(out))
        ui.message("")

        ui.message("+ Largonji des Loucherbèmes.")
        text = "Les bouchers de la Villette osent un tango langoureux !"
        ui.message("Data to cypher: {}".format(text))
        out = argots.cypher_largonji(text, argots.LARGONJI_SYLLABLES_V,
                                     argots.LARGONJI_SYLLABLES_C)
        out = self._get_largonji_txt(out, ui, act="rand")
        ui.message("Largonji des Loucherbèmes: {}".format(out))
        ui.message("")

        ui.message("--- Decyphering ---")
        ui.message("+ Argot Javanais & co.")
        htext = "LEfes EfApEfachEfes sEfont sEfur lEfe sEfentEfier dEfes " \
                "HEfallEfes."
        ui.message("Note that most of the time, you can use default options "
                   "here (i.e. Generic, and give no obfuscating syllable), "
                   "as that kind of “cyphering” is really easy to break!")
        ui.message("Langue de Feu text used as input: {}".format(htext))
        out = argots.decypher(htext, argots.FEU)
        ui.message("The decyphered data is:\n    With '{}': {}"
                   "".format(out[0][0], out[0][1]))
        ui.message("")

        ui.message("+ Largonji des Loucherbèmes.")
        htext = "La mie du loucherbouche lricottefesse lavecouche le " \
                "loulangerbesse !"
        ui.message("Largonji de Loucherbems text used as input: {}"
                   "".format(htext))
        out = argots.decypher_largonji(htext)
        ui.message("The decyphered data is:\n    {}"
                   "".format("\n    ".join(utils.format_multiwords(out))))
        ui.message("")

        ui.message("--- Notes ---")
        ui.message("+ With Argot Javanais & co, you can choose the optional "
                   "Exhaustive option, to get all possible encodings of each "
                   "words higher than the given goal of cyphering (or the "
                   "highest possible):")
        text = "Do you know Ménilmuche and Belleville ?"
        ui.message("Data to cypher: {}".format(text))
        out = argots.cypher(text,
                            argots.GENERIC,
                            'uz',
                            exhaustive=True,
                            cypher_goal=0.2)
        out = self._get_exhaustive_txt(out, ui, cypher_goal=0.2, act="goal")
        ui.message("Generic cyphered solutions with cypher factor higher "
                   "than 0.2:")
        ui.message(out)
        ui.message("")

        ui.message("+ Here is what you’ll get if you try to decypher some "
                   "largonji without giving any suffix syllables (note how "
                   "some words aren’t decyphered well at all):")
        htext = "La mie du loucherbouche lricottefesse lavecouche le " \
                "loulangerbesse !"
        ui.message("Largonji de Loucherbems text used as input: {}"
                   "".format(htext))
        out = argots.decypher_largonji(htext, (), ())
        ui.message("The decyphered data is:\n    {}"
                   "".format("\n    ".join(utils.format_multiwords(out))))
        ui.message("")

        ui.message("--- Won’t work ---")
        ui.message("+ With Argot Javanais & co, the obfuscating syllable "
                   "must comply to the chosen method!")
        text = "Hello WORLD !"
        ui.message("Data to cypher, using Javanais and 'eh': {}\n"
                   "".format(text))
        try:
            out = argots.cypher(text, argots.JAVANAIS, 'eh')
            ui.message("Javanais cyphered data: {}".format(out))
        except Exception as e:
            ui.message(str(e), level=ui.ERROR)
        ui.message("")

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