Skip to content

Instantly share code, notes, and snippets.

@Susros
Last active February 23, 2024 03:54
Show Gist options
  • Save Susros/c7ff80cf78eab2d1cad451ad64bed7b9 to your computer and use it in GitHub Desktop.
Save Susros/c7ff80cf78eab2d1cad451ad64bed7b9 to your computer and use it in GitHub Desktop.
caesar_cipher_decrypt_xy25la
# Deciphering the Caesar cipher encoded message with a loop to try different shifts
def caesar_cipher_decrypt(ciphertext, shift):
decrypted_text = ""
for char in ciphertext:
if char.isalpha(): # Check if the character is an alphabet
shift_amount = shift % 26
if char.islower():
decrypted_text += chr((ord(char) - shift_amount - 97) % 26 + 97)
else:
decrypted_text += chr((ord(char) - shift_amount - 65) % 26 + 65)
else:
decrypted_text += char # Non-alphabet characters remain the same
return decrypted_text
# The encoded message
encoded_message = "Keen to master the art of impregnable security ghvljqv? Venture into a domain where DZV and Dcxuh lay the irxqgdwlrqv of our vwurqjkrog. We're seeking a Vhfxulwb Dufklwhfw to intertwine frpsoldqfh and lqqrydwlrq within our enterprise's core, guided by the principles of the Sulvpd Sdor Dowr sodwirup. Are you up for the fkdoohqjh?"
# Trying different shifts to find the correct decryption
for shift in range(1, 26): # Trying all possible shifts from 1 to 25
decrypted_message = caesar_cipher_decrypt(encoded_message, shift)
print(f"Shift {shift}: {decrypted_message}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment