diff --git a/cipher.py b/cipher.py index 0e772db..581ac4c 100644 --- a/cipher.py +++ b/cipher.py @@ -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) diff --git a/cipherXL.py b/cipherXL.py new file mode 100644 index 0000000..7e50ca0 --- /dev/null +++ b/cipherXL.py @@ -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}\"')