Example #1
0
def aristocrat(plaintext: str) -> str:
    """Encodes text with the Aristocrat cipher."""
    ciphertext: str = ""
    alph_map: list = utils.alph_map()
    plaintext = plaintext.strip().upper()
    for i in plaintext:
        ascii_val: int = ord(i)
        if utils.is_letter(ascii_val):
            ciphertext += chr(alph_map[ascii_val - 65] + 65)
        else:
            ciphertext += chr(ascii_val)
    return ciphertext
Example #2
0
def vigenere(ciphertext: str, key: str) -> str:
    plaintext: str = ""
    ciphertext = ciphertext.upper()
    key = key.upper()
    cipher_char: list = [ord(l) for l in ciphertext]
    key_char: list = utils.vig_key_array(key, cipher_char)
    for i in range(0, len(cipher_char)):
        if utils.is_letter(cipher_char[i]):
            plaintext += chr((cipher_char[i] - key_char[i] + 26) % 26 + 65)
        else:
            plaintext += chr(cipher_char[i])
    return plaintext
Example #3
0
def vigenere(plaintext: str, key: str) -> str:
    """Encodes text with the Vigenere cipher."""
    ciphertext: str = ""
    plaintext = plaintext.strip().upper()
    key = key.upper()
    plain_char: list = [ord(letter) for letter in plaintext]
    key_char: list = utils.vig_key_array(key, plain_char)
    for i in range(0, len(plain_char)):
        if utils.is_letter(plain_char[i]):
            ciphertext += chr((plain_char[i] + key_char[i] - 130) % 26 + 65)
        else:
            ciphertext += chr(plain_char[i])
    return ciphertext
Example #4
0
def patristocrat(plaintext: str) -> str:
    """Encodes text with the Patristocrat cipher."""
    ciphertext: str = ""
    new_cipher: str = ""
    alph_map: list = utils.alph_map()
    plaintext = plaintext.strip().upper()
    for i in range(0, len(plaintext)):
        ascii_val: int = ord(plaintext[i])
        if utils.is_letter(ascii_val):
            new_cipher += chr(ascii_val)
    letters: int = 0
    for i in range(0, len(new_cipher)):
        ascii_val: int = ord(new_cipher[i])
        ciphertext += chr(alph_map[ascii_val - 65] + 65)
        letters += 1
        if letters == 5 and i != len(new_cipher) - 1:
            ciphertext += " "
            letters = 0
    return ciphertext
Example #5
0
def xenocrypt(plaintext: str) -> str:
    """Encodes text with the Xenocrypt/Spanish Aristocrat cipher."""
    ciphertext: str = ""
    used = []
    for i in range(0, 27):
        used.append(False)
    alph_map: list = []
    for i in range(0, 26):
        newval: int = random.randint(0, 26)
        while newval == i or used[newval]:
            newval: int = random.randint(0, 26)
        used[newval] = True
        alph_map.append(newval)
    plaintext = plaintext.strip().upper()
    letters: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZĂ‘"
    for i in plaintext:
        ascii_val: int = ord(i)
        if utils.is_letter(ascii_val):
            ciphertext += letters[alph_map[ascii_val - 65]]
        elif ascii_val == 165:
            ciphertext += letters[26]
        else:
            ciphertext += chr(ascii_val)
    return ciphertext