Пример #1
0
def do_cypher(text, base=1):
    """
    Cypher message to triliteral (with optional base, shift)
    'd' --> ABA (base 0), 'd' --> CBC (base 7)
    """
    base -= 1
    MAP = {k: utils.num_to_base((v - base) % 26, ('A', 'B', 'C'), 3)
                                for v, k in enumerate(CHARS)}
    return "".join((MAP[c] for c in text))
Пример #2
0
def do_decypher(text, base=1):
    """
    Decypher message to triliteral (with optional base, shift)
    ABA --> 'd' (base 0), ABA --> 'j' (base 7)
    """
    base -= 1
    R_MAP = {utils.num_to_base((k - base) % 26, ('A', 'B', 'C'), 3): v
                               for k, v in enumerate(CHARS)}
    return "".join((R_MAP[c] for c in utils.grouper2(text, 3)))
Пример #3
0
def do_cypher(text, base=1):
    """
    Cypher message to triliteral (with optional base, shift)
    'd' --> ABA (base 0), 'd' --> CBC (base 7)
    """
    base -= 1
    MAP = {
        k: utils.num_to_base((v - base) % 26, ('A', 'B', 'C'), 3)
        for v, k in enumerate(CHARS)
    }
    return "".join((MAP[c] for c in text))
Пример #4
0
def do_decypher(text, base=1):
    """
    Decypher message to triliteral (with optional base, shift)
    ABA --> 'd' (base 0), ABA --> 'j' (base 7)
    """
    base -= 1
    R_MAP = {
        utils.num_to_base((k - base) % 26, ('A', 'B', 'C'), 3): v
        for k, v in enumerate(CHARS)
    }
    return "".join((R_MAP[c] for c in utils.grouper2(text, 3)))
Пример #5
0
(no spaces), decypher input must be an integer number of groups of five
(A,B) digits.

Note that [ij] and [uv] have the same biliteral codes.

Cyprium.Biliteral version {} ({}).
Licence GPL3
Software distributed on the site: http://thehackademy.fr

Current execution context:
    Operating System: {}
    Python version: {}
""".format(__version__, __date__, utils.__pf__, utils.__pytver__)


MAP = {k: utils.num_to_base(v, ('A', 'B'), 5)
                           for v, k in enumerate(string.ascii_lowercase)
                                    if k not in 'jv'}
MAP['j'] = MAP['i']
MAP['v'] = MAP['u']

R_MAP = utils.revert_dict(MAP, exceptions={MAP['i']: '[ij]', MAP['u']: '[uv]'})


def do_cypher(text):
    """
    Cypher message to triliteral (with optional base, shift)
    'd' --> AAABB
    """
    return "".join((MAP[c] for c in text))
Пример #6
0
}  # 00000  NOTE: should never be used in python.
#        WRU: 9    # 01001
#        BELL: 11  # 01011
#        CR: 8     # 01000

ALLOWED_CHARS = sorted(set(L_MAP.keys()) | set(S_MAP.keys()))

# Now, create the four bases mappings.
# Number of digits, in each base.
N_DIGITS = {2: 5, 8: 2, 10: 2, 16: 2}

# Mappings, for each base.
MAPS = {}
for b in N_DIGITS.keys():
    _b = utils.BASE_DIGITS_ALLOWED[:b]
    _l_m = {k: utils.num_to_base(v, _b, N_DIGITS[b]) for k, v in L_MAP.items()}
    _s_m = {k: utils.num_to_base(v, _b, N_DIGITS[b]) for k, v in S_MAP.items()}
    _m = _l_m.copy()
    _m.update(_s_m)
    MAPS[b] = {
        L_MODE: utils.num_to_base(L_MODE, _b, N_DIGITS[b]),
        S_MODE: utils.num_to_base(S_MODE, _b, N_DIGITS[b]),
        "MAP": _m,
        "RMAP": {
            L_MODE: utils.revert_dict(_l_m),
            S_MODE: utils.revert_dict(_s_m)
        }
    }
del _l_m
del _s_m
del _m
Пример #7
0
for 'a', CCA for 'b', and so on. The default base  (AAA for 'a') being 1.

Cyprium.Biliteral version {} ({}).
Licence GPL3
Software distributed on the site: http://thehackademy.fr

Current execution context:
    Operating System: {}
    Python version: {}
""".format(__version__, __date__, utils.__pf__, utils.__pytver__)

# No static MAP, as we generate one based on the “base” arg...
# However, we need a set of all possible triliteral codes, for decyphering
# checks.
CHARS = string.ascii_lowercase
CODES = {utils.num_to_base(v, ('A', 'B', 'C'), 3) for v in range(len(CHARS))}


def do_cypher(text, base=1):
    """
    Cypher message to triliteral (with optional base, shift)
    'd' --> ABA (base 0), 'd' --> CBC (base 7)
    """
    base -= 1
    MAP = {
        k: utils.num_to_base((v - base) % 26, ('A', 'B', 'C'), 3)
        for v, k in enumerate(CHARS)
    }
    return "".join((MAP[c] for c in text))

Пример #8
0
#        BELL: 11  # 01011
#        CR: 8     # 01000


ALLOWED_CHARS = sorted(set(L_MAP.keys()) | set(S_MAP.keys()))


# Now, create the four bases mappings.
# Number of digits, in each base.
N_DIGITS = {2: 5, 8: 2, 10: 2, 16: 2}

# Mappings, for each base.
MAPS = {}
for b in N_DIGITS.keys():
    _b = utils.BASE_DIGITS_ALLOWED[:b]
    _l_m = {k: utils.num_to_base(v, _b, N_DIGITS[b]) for k, v in L_MAP.items()}
    _s_m = {k: utils.num_to_base(v, _b, N_DIGITS[b]) for k, v in S_MAP.items()}
    _m = _l_m.copy()
    _m.update(_s_m)
    MAPS[b] = {L_MODE: utils.num_to_base(L_MODE, _b, N_DIGITS[b]),
               S_MODE: utils.num_to_base(S_MODE, _b, N_DIGITS[b]),
               "MAP": _m,
               "RMAP": {L_MODE: utils.revert_dict(_l_m),
                        S_MODE: utils.revert_dict(_s_m)}}
del _l_m
del _s_m
del _m


__version__ = "0.6.0"
__date__ = "2012/01/24"
Пример #9
0
(no spaces), decypher input must be an integer number of groups of five
(A,B) digits.

Note that [ij] and [uv] have the same biliteral codes.

Cyprium.Biliteral version {} ({}).
Licence GPL3
Software distributed on the site: http://thehackademy.fr

Current execution context:
    Operating System: {}
    Python version: {}
""".format(__version__, __date__, utils.__pf__, utils.__pytver__)

MAP = {
    k: utils.num_to_base(v, ('A', 'B'), 5)
    for v, k in enumerate(string.ascii_lowercase) if k not in 'jv'
}
MAP['j'] = MAP['i']
MAP['v'] = MAP['u']

R_MAP = utils.revert_dict(MAP, exceptions={MAP['i']: '[ij]', MAP['u']: '[uv]'})


def do_cypher(text):
    """
    Cypher message to triliteral (with optional base, shift)
    'd' --> AAABB
    """
    return "".join((MAP[c] for c in text))
Пример #10
0
Cyprium.Biliteral version {} ({}).
Licence GPL3
Software distributed on the site: http://thehackademy.fr

Current execution context:
    Operating System: {}
    Python version: {}
""".format(__version__, __date__, utils.__pf__, utils.__pytver__)


# No static MAP, as we generate one based on the “base” arg...
# However, we need a set of all possible triliteral codes, for decyphering
# checks.
CHARS = string.ascii_lowercase
CODES = {utils.num_to_base(v, ('A', 'B', 'C'), 3) for v in range(len(CHARS))}


def do_cypher(text, base=1):
    """
    Cypher message to triliteral (with optional base, shift)
    'd' --> ABA (base 0), 'd' --> CBC (base 7)
    """
    base -= 1
    MAP = {k: utils.num_to_base((v - base) % 26, ('A', 'B', 'C'), 3)
                                for v, k in enumerate(CHARS)}
    return "".join((MAP[c] for c in text))


def cypher(text, base=1):
    """Just a wrapper around do_cypher, with some checks."""