CIPHER #002

Vigenère Cipher LinkedIn Puzzle

2024-10-25Vigenère CipherLinkedIn Cryptography Group

The Result

LXFOPVEFRNHR
ATTACKATDAWN
ENCRYPTED← DRAG TO REVEAL →DECRYPTED

The Challenge

A Vigenère cipher puzzle posted in a LinkedIn cryptography group. The key was hinted to be a common word related to "security".

The Analysis

Vigenère cipher uses a keyword to shift each letter by different amounts. The keyword "LEMON" repeats to match the message length. Each letter of the keyword determines the shift for the corresponding letter in the plaintext.

The Solution

Testing common security-related keywords, "LEMON" was found to be the correct key: A + L (11) = L T + E (4) = X T + M (12) = F ...and so on

The Code

def vigenere_decrypt(ciphertext, key):
    result = ""
    key_length = len(key)
    key_as_int = [ord(i) - ord('A') for i in key.upper()]

    for i, char in enumerate(ciphertext):
        if char.isalpha():
            shift = key_as_int[i % key_length]
            ascii_offset = ord('A') if char.isupper() else ord('a')
            decrypted_char = chr((ord(char) - ascii_offset - shift) % 26 + ascii_offset)
            result += decrypted_char
        else:
            result += char
    return result

ciphertext = "LXFOPVEFRNHR"
key = "LEMON"
print(vigenere_decrypt(ciphertext, key))