alphabet = "abcdefghijklmnopqrstuvwxyz"
input_text = "and the mome raths outgrabe"
cipher_key = 3
character = input_text[0]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
new_letter = alphabet[new_position]
print(new_letter)
character = input_text[1]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
new_letter = alphabet[new_position]
print(new_letter)
character = input_text[2]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
new_letter = alphabet[new_position]
print(new_letter)
character = input_text[3]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
new_letter = alphabet[new_position]
print(new_letter)
alphabet = "abcdefghijklmnopqrstuvwxyz"
input_text = "twas brillig in the slithy tove"
cipher_key = 3
cipher_text = ""
character = input_text[0]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
print(cipher_text)
character = input_text[1]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
print(cipher_text)
character = input_text[2]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
print(cipher_text)
character = input_text[3]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
print(cipher_text)
alphabet = "abcdefghijklmnopqrstuvwxyz"
input_text = "twas"
cipher_key = 15
cipher_text = ""
character = input_text[0]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
print(cipher_text)
character = input_text[1]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
print(cipher_text)
character = input_text[2]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
print(cipher_text)
character = input_text[3]
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
print(cipher_text)
alphabet = "abcdefghijklmnopqrstuvwxyz"
input_text = "twas brillig in the slithy tove"
cipher_key = 15
cipher_text = ""
for character in input_text:
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
print(cipher_text)
alphabet = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
input_text = "$@Twas brillig in the slithy tove"
cipher_key = 1
cipher_text = ""
for character in input_text:
if character in alphabet:
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
else:
cipher_text = cipher_text + character
print(cipher_text)
alphabet = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
input_text = raw_input("Enter your input text: ")
cipher_key = raw_input("Enter a number between 0 and " + str(len(alphabet)) + ": ")
cipher_key = int(cipher_key)
cipher_text = ""
for character in input_text:
if character in alphabet:
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
else:
cipher_text = cipher_text + character
print(cipher_text)
alphabet = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
direction = raw_input("Encrypt or decrypt? (d/e): ")
input_text = raw_input("Enter your input text: ")
cipher_key = raw_input("Enter a number between 0 and " + str(len(alphabet)) + ": ")
cipher_key = int(cipher_key)
if direction == "d":
cipher_key = -cipher_key
cipher_text = ""
for character in input_text:
if character in alphabet:
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
else:
cipher_text = cipher_text + character
print(cipher_text)
alphabet = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
def caesar_cipher(input_text, cipher_key):
cipher_text = ""
for character in input_text:
if character in alphabet:
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
else:
cipher_text = cipher_text + character
return cipher_text
direction = raw_input("Encrypt, decrypt, or break? (d/e/b): ")
user_input_string = raw_input("Enter your input text: ")
cipher_text = ""
if direction == "b":
for count in range(len(alphabet)):
output_cipher_text = caesar_cipher(user_input_text, -count)
print(output_cipher_text)
else:
cipher_key = raw_input("Enter a number between 0 and " + str(len(alphabet)) + ": ")
cipher_key = int(cipher_key)
if direction == "d":
cipher_text = caesar_cipher(user_input_text, -cipher_key)
elif direction == "e":
cipher_text = caesar_cipher(user_input_text, cipher_key)
print(cipher_text)
alphabet = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
def caesar_cipher(input_text, cipher_key):
cipher_text = ""
for character in input_text:
if character in alphabet:
character_position = alphabet.find(character)
new_position = character_position + cipher_key
if new_position >= len(alphabet):
new_position = new_position - len(alphabet)
new_letter = alphabet[new_position]
cipher_text = cipher_text + new_letter
else:
cipher_text = cipher_text + character
return cipher_text
direction = ""
valid_option = False
while valid_option == False:
direction = raw_input("Encrypt, decrypt, or break? (d/e/b): ")
if direction in "bed":
valid_option = True
else:
print("Option not recognized. Please try again.")
user_input_text = raw_input("Enter your input text: ")
output_cipher_text = ""
if direction == "b":
for count in range(1, len(alphabet)):
output_cipher_text = caesar_cipher(user_input_text, -count)
print(output_cipher_text)
else:
cipher_key = raw_input("Enter a number between 0 and " + str(len(alphabet)) + ": ")
cipher_key = int(cipher_key)
if direction == "d":
output_cipher_text = caesar_cipher(user_input_text, -cipher_key)
elif direction == "e":
output_cipher_text = caesar_cipher(user_input_text, cipher_key)
print(output_cipher_text)