Skip to content

Instantly share code, notes, and snippets.

@agu3rra
Created February 18, 2020 15:05
Show Gist options
  • Save agu3rra/24f40ae2943aaf1ea08eb862bf2abfa6 to your computer and use it in GitHub Desktop.
Save agu3rra/24f40ae2943aaf1ea08eb862bf2abfa6 to your computer and use it in GitHub Desktop.
A simple snippet for a Caesar cipher in Python
message = 'Divide the army in two, advance and outflank them on the right. I will advance on the left flank from the woods getting them by surprise.'
message = message.replace(' ','')
message = message.replace(',','')
message = message.replace('.','')
shift_secret = 6
ciphered_message = ''
print(message)
for character in message:
if character.isupper():
ciphered_message += chr((ord(character) + shift_secret - 65) % 26 + 65)
else:
ciphered_message += chr((ord(character) + shift_secret - 97) % 26 + 97)
print(ciphered_message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment