Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cipher.py
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# add your code here

alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
phrase = input("Please enter the phrase you wish to encode: ")
phrase = phrase.lower()
cipherPhrase = ""

for char in phrase:
if char in alphabet:
position = alphabet.index(char)
newPosition = (position + 5) % 26
cipherPhrase += (alphabet[newPosition])
else:
cipherPhrase += char

print(cipherPhrase)
36 changes: 36 additions & 0 deletions cipherXL.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import string

alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

cipherShift = input("please enter the number of characters you wish to shift for this cipher: ")

while not cipherShift.isdigit():
print("Invalid input. Please enter a valid number.")
cipherShift = input("please enter the number of characters you wish to shift for this cipher: ")

cipherShift = int(cipherShift)

phrase = input("Please enter the phrase you wish to encode: ")
cipherPhrase = ""

for char in phrase:
if char == ' ':
cipherPhrase += " "
elif char.isdigit() or char in string.punctuation:
cipherPhrase += char
else:
position = alphabet.index(char.lower())
newPosition = (position + cipherShift) % 26

if char.isupper():
cipherPhrase += (alphabet[newPosition].upper())
else:
cipherPhrase += (alphabet[newPosition])
# print(position)
# print(alphabet[position])
# print(newPosition)
# print(alphabet[newPosition])

#print(cipherPhrase)
print(f'The phrase you input was: \"{phrase}\"')
print(f'The phrase has been scambled to be: \"{cipherPhrase}\"')