From 51942ec637c3ac87d2dbbbeee696db5b3c65bcd8 Mon Sep 17 00:00:00 2001 From: pythonboi Date: Sun, 12 Sep 2021 09:42:11 -0400 Subject: [PATCH] update the code with another method code solution --- Caesar_Cipher.py | 95 +++++++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 37 deletions(-) diff --git a/Caesar_Cipher.py b/Caesar_Cipher.py index 8f82e0f..154b252 100644 --- a/Caesar_Cipher.py +++ b/Caesar_Cipher.py @@ -5,46 +5,67 @@ text = input("Type your message:\n").lower() shift = int(input("Type the shift number:\n")) -newText = text.split() - -def encrypt(text, shift): - count_text = len(text) - move = '' - - # Loop through len of text - # for m in range(0, count_text): - # Add the index value of the number 5 to move variable - # move += alphabet[shift] - # Increment the shift and add it to the index value - # alphabet[shift] = alphabet[shift + 1] - # Increment the shift value by one during the Loop - # shift += 1 - # - # print(move) - # for loop for check the first letter in text variable in the alphabet list - for check in alphabet: - # check for the index of the first character in the newText variable - if check == newText[0][0]: - # get the index that match the first character of the newText - getIndex = alphabet.index(check) - - print(getIndex) - # Loop through the length of the text variable - for count in range(0, count_text): - # Increment the index value in the alphabet - alphabet[getIndex] = alphabet[getIndex + 1] - # Increment the index on each loop to move forward - getIndex += 1 - # Add each character of the index to the move string variable - move += alphabet[getIndex] - - print(move) - - -encrypt(text=text, shift=shift) +# newText = text.split() +# +# +# def encrypt(text, shift): +# count_text = len(text) +# move = '' +# +# # Loop through len of text +# # for m in range(0, count_text): +# # Add the index value of the number 5 to move variable +# # move += alphabet[shift] +# # Increment the shift and add it to the index value +# # alphabet[shift] = alphabet[shift + 1] +# # Increment the shift value by one during the Loop +# # shift += 1 +# # +# # print(move) +# # for loop for check the first letter in text variable in the alphabet list +# for check in alphabet: +# # check for the index of the first character in the newText variable +# if check == newText[0][0]: +# # get the index that match the first character of the newText +# getIndex = alphabet.index(check) +# +# print(getIndex) +# # Loop through the length of the text variable +# for count in range(0, count_text): +# # Increment the index value in the alphabet +# alphabet[getIndex] = alphabet[getIndex + 1] +# # Increment the index on each loop to move forward +# getIndex += 1 +# # Add each character of the index to the move string variable +# move += alphabet[getIndex] +# +# print(move) +# +# +# encrypt(text=text, shift=shift) # for l in range() # alphabet[text] = alphabet[text + 1] # shift += 1 # + +# BETTER COPY + +def encrypt(text, shift): + newEn = '' + for count in text: + en = alphabet.index(count) + shift + if en >= len(alphabet): + fw = alphabet.index("a") + shift + fw -= 1 + lw = alphabet.index(count) - shift + newEn += alphabet[fw] + # newEn += alphabet[nw] + else: + newEn += alphabet[en] + # print(en) + print(newEn) + + +encrypt(text=text, shift=shift) \ No newline at end of file