Skip to content
Merged
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
95 changes: 58 additions & 37 deletions Caesar_Cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)