The head is filled with nothing but random thoughts of how to tweak this code of mine.
import art
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']
print(art.logo)
go=True
while go:
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
if shift >= 26:
shift = (shift%26)
def caesar (cipher_text, shift_amount, caesar_directive):
letter_dump = alphabet[0:shift_amount]
cut_alpha = alphabet[shift:]
cut_alpha.extend(letter_dump)
result = ""
for letter in (cipher_text):
if caesar_directive == "encode":
position = alphabet.index(letter)
result += cut_alpha[position]
elif caesar_directive == "decode":
position = cut_alpha.index(letter)
result += alphabet[position]
print(f"The {caesar_directive}d text is {result}")
caesar(cipher_text=text,shift_amount=shift,caesar_directive=direction)
reload = input("Do you want to use Casear Cipher again? type yes or no.\n").lower()
if reload == "no":
go=False
Now this is day eight of my one hundred day coding course. I think it has taken me close to two months to progress to this point. I foresee myself completing this course in a year or more.
I do see some improvement but I am still using lots of googling and using stack overflow to find ideas on how to solve each and every challenge this course is throwing my way.
I have abandoned trying to solve your challenge you gave me. I may or may not go back to it in the distant future. I can't say not too distant since I am struggling with time management. Too many pursuits.
Out of interest and context of my progress.
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', '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']
def caesar(start_text, shift_amount, cipher_direction):
end_text = ""
if cipher_direction == "decode":
shift_amount *= -1
for char in start_text:
#TODO-3: What happens if the user enters a number/symbol/space?
#Can you fix the code to keep the number/symbol/space when the text is encoded/decoded?
#e.g. start_text = "meet me at 3"
#end_text = "•••• •• •• 3"
position = alphabet.index(char)
new_position = position + shift_amount
end_text += alphabet[new_position]
print(f"Here's the {cipher_direction}d result: {end_text}")
This is the teachers code for the same work and while it is tempting to just do the exercises using her format I am sticking to just continuing with the code I started with, which is the code block above hers.
I am close to finishing day eight. I have just one more challenge of improving the UI for the cipher challenge. All up it consists of four tasks. This one being the fourth iteration on the previous three done.
Create encryption function.
Create decryption function.
Combine both functions.
This last one entails adding a logo, ensuring the code will allow for any amounts greater than the alphabet numbers (26), loop code until user wants out and ensure code can handle actual sentence used for encrypting and decrypting.
Will take a break from here though because my head is swimming like my starting statement.
I really do believe when it comes to my learning, not learning as a general sense I have to take my time and just let new knowledge become digested and adapted into my over all neural network.