Speed Coding A Caesar Cipher In Python (Time lapse)

Опубликовано: 05 Февраль 2025
на канале: R.K. Coding
71
2

This was originally a tutorial, but the audio quality was bad, so I turned it into a time lapse instead.

code:
def rotate_list_left(rotation_number, list):
rotated_list = list[:]

for i in range(rotation_number):
rotated_list.append(rotated_list[0])
del(rotated_list[0])

return rotated_list

def rotate_list_right(rotation_number, list):
rotated_list = list[:]

for i in range(rotation_number):
rotated_list.insert(0, rotated_list[len(rotated_list) - 1])
del(rotated_list[len(rotated_list) - 1])

return rotated_list

char_lower = list("abcdefghijklmnopqrstuvwxyz")
char_upper = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

while True:
instruction = input("ENCRYPT (E), DECRYPT (D), or STOP(S): ")

if (instruction == "S"):
print("DONE")
break


key = int(input("WHAT IS THE KEY: "))
message = input("MESSAGE: ")

output = ""

if (instruction == "E"):
for char in message:
if (char in char_lower):
index = char_lower.index(char)
rotated_list = rotate_list_left(key, char_lower)
output += rotated_list[index]

elif (char in char_upper):
index = char_upper.index(char)
rotated_list = rotate_list_left(key, char_upper)

output += rotated_list[index]

else:
output += char

elif (instruction == "D"):
for char in message:
if (char in char_lower):
index = char_lower.index(char)
rotated_list = rotate_list_right(key, char_lower)
output += rotated_list[index]

elif (char in char_upper):
index = char_upper.index(char)
rotated_list = rotate_list_right(key, char_upper)

output += rotated_list[index]

else:
output += char

else:
print("INVALID COMMAND: VALID COMMANDS ARE CAPITAL E FOR ENCRYPTION, CAPITAL D FOR DECRYPTION, OR CAPITAL S FOR STOPPING")


print(output)