예제 #1
0
def decode_multilayer(cipher_list: List[Tuple[str, str]],
                      max_layers: int,
                      printed_results=[]):
    # cipher_list is List[(ciphertext, origination)]
    # max_layers is the number of times the method can call itself recursively
    # printed_results optional argument that allows for printing each answer once
    """Used to solve nested layers of ciphers"""

    results = []
    # runs each ciphertext through a decoding method, and appends the method to ciphertext[1]
    for ciphertext in cipher_list:
        results.append((decode_base85(ciphertext[0]),
                        ciphertext[1] + " => Base85 Decode"))
        results.append((decode_base64(ciphertext[0]),
                        ciphertext[1] + " => Base64 Decode"))
        results.append((decode_base32(ciphertext[0]),
                        ciphertext[1] + " => Base32 Decode"))
        results.append((decode_base16(ciphertext[0]),
                        ciphertext[1] + " => Base16 Decode"))
        results.append(
            (decode_rot13(ciphertext[0]), ciphertext[1] + " => Rot13 Decode"))
        results.append((decode_mirror(ciphertext[0]),
                        ciphertext[1] + " => Mirror Decode"))
        results.append(
            (decode_morse(ciphertext[0]), ciphertext[1] + " => Morse Decode"))
        results.append((decode_number_as_phone(ciphertext[0]),
                        ciphertext[1] + " => Phone Decode"))
        results.append((decode_number_as_letter(ciphertext[0]),
                        ciphertext[1] + " => Number Decode"))

    # removes blank strings
    results = list(filter(None, results))

    # prints possible decoded text and the decoding methods used
    for possible_match in results:
        if detect_english.has_english(
                possible_match[0]
        ) and possible_match[0] not in printed_results:
            print(f'{possible_match[0]}: {possible_match[1]}')
            printed_results.append(possible_match[0])

    if max_layers > 0:
        decode_multilayer(results, max_layers - 1, printed_results)
예제 #2
0
def is_base64(cipher: str):
    """Used to detect base64"""
    return detect_english.has_english(decode_base64(cipher))
예제 #3
0
def is_rot13(cipher: str):
    """Used to detect rot13"""
    return detect_english.has_english(decode_rot13(cipher))
예제 #4
0
def is_binary(cipher: str):
    """Used to detect binary"""
    # TODO see decode_binary(), should function once written
    return detect_english.has_english(decode_binary(cipher))
예제 #5
0
def is_morse(cipher: str):
    """Can detect well behaved morse"""
    return detect_english.has_english(decode_morse(cipher))
예제 #6
0
def is_mirror(cipher: str):
    """used to detect mirrored cipher text"""
    return detect_english.has_english(decode_mirror(cipher))