here is my code:
import time
ed = input('Encrypt (e) or decrypt (d)? ')
chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
charsLen = len(chars)
def numberToStr(num):
s = ""
while num:
s = chars[num % charsLen] + s
num //= charsLen
return(s)
def strToNumber(numStr):
num = 0
for i, c in enumerate(reversed(numStr)):
num += chars.index(c) * (charsLen ** i)
return(num)
def enc():
key = input('What is your key? (Alphanumeric and space) ')
ID = int(input('What is your ID? (0-9, 3+ digits) '))
inp = int(strToNumber(input('What do you want to encrypt? ')))
keyAsNum = int(strToNumber(key))
enc.asint = inp ** 2
enc.asint = enc.asint * ID
enc.asint = enc.asint - keyAsNum
enc.astext = numberToStr(int(enc.asint))
return(enc)
def dec():
key = input('What is your key? (Alphanumeric and space) ')
ID = int(input('What is your ID? (0-9, 3+ digits) '))
inp = int(strToNumber(input('What do you want to decrypt? ')))
keyAsNum = int(strToNumber(key))
message = inp + keyAsNum
message = message // ID
message = math.sqrt(message)
message = numberToStr(message)
return(message)
if ed=='e':
crypt = enc()
print('crypt.asint:\n' + str(crypt.asint) + '\ncrypt.astext:\n' + crypt.astext)
elif ed=='d':
crypt = dec()
print(crypt)
time.sleep(10)
and here is the error: File "stdin", line 5, in module
File "stdin", line 9, in dec
File "stdin", line 4, in numberToStr
TypeError: string indices must be integers
I cannot figure out why it is throwing this error and cannot find anything on google.