h4cker/crypto/challenges/04_Classic_Vigenere_Cipher.md

37 lines
1001 B
Markdown
Raw Normal View History

2023-08-15 13:55:01 +00:00
# Challenge 4: Classic Vigenère Cipher
2023-08-15 13:52:53 +00:00
**Level:** Beginner
**Description:**
Crack a message encrypted using the Vigenère cipher with a known keyword.
**Challenge Text:**
```
Encrypted Message: "XBGXLTVJZTFKTRDCXWPNCRTGDHDDJQKFTZR"
Keyword: "KEYWORD"
```
**Instructions:**
1. Utilize the given keyword to decrypt the Vigenère cipher.
2. Provide the original plaintext.
2023-08-15 13:55:01 +00:00
**Answer:**
The decrypted message is "WELCOMETOTHEWORLDOFCRYPTOGRAPHY"
2023-08-15 13:52:53 +00:00
2023-08-15 13:55:01 +00:00
**Code:**
```python
def decrypt_vigenere(ciphertext, keyword):
keyword_repeated = (keyword * (len(ciphertext) // len(keyword))) + keyword[:len(ciphertext) % len(keyword)]
decrypted_text = ''
for i in range(len(ciphertext)):
decrypted_char = chr(((ord(ciphertext[i]) - ord(keyword_repeated[i])) % 26) + ord('A'))
decrypted_text += decrypted_char
return decrypted_text
2023-08-15 13:52:53 +00:00
2023-08-15 13:55:01 +00:00
ciphertext = "XBGXLTVJZTFKTRDCXWPNCRTGDHDDJQKFTZR"
keyword = "KEYWORD"
decrypted_text = decrypt_vigenere(ciphertext, keyword)
print(decrypted_text)
2023-08-15 13:52:53 +00:00
```