I'm pretty beginner to Python so I get the error
Traceback (most recent call last):
File "C:/Users/spchee/Documents/cc.py", line 43, in c("helloz", 2) File "C:/Users/spchee/Documents/cc.py", line 35, in c add_to_string(n) File "C:/Users/spchee/Documents/cc.py", line 5, in add_to_string if message[i].titlecase():
IndexError: string index out of range
My current code at the moment is:
import math
message = ""
i=0
def add_to_string(modifier):
if message[i].titlecase():
encrypted = encrypted + string[modifier].upper()
else:
encrypted = encrypted +string[modifier]
def c(message,key):
string = "0abcdefghijklmnopqrstuvwxyz0"
encrypted = ""
legnth_message = len(message)
i = 0
for i in range (legnth_message-1):
n = 0
x = 0
while message[i] != string[x].lower():
x+=1;
while string[int(x)+int(n)] != "0":
n += math.copysign(1, key)
if abs(key)<abs(n):
n = (abs(n)-abs(key))*math.copysign(1,key)
if math.copysign(1,key) == 1:
add_to_string(n)
else:
add_to_string(27+n)
else:
add_to_string(x+key)
c("helloz", 2)
The code should function as a Caesar Cipher. Thanks in advance