I am trying to create a function for a Caesar Cypher that converts any string to its respective unicode using the ord() function and then shifts the unicode by two steps.
For example, the unicode for the string 'a' is the integer 97.
print(ord('a'))
After that this shifted unicode is converted back to its respective character to produce a piece of code that is inscrutable.
. Traceback (most recent call last): File "main.py", line 11, in Ccypher(msg) File "main.py", line 9, in Ccypher a = a + str(chr(lst[i])) UnboundLocalError: local variable 'a' referenced before assignment**
I tried to convert a to a global variable by adding
global a in the body of the function but then I got no output, just blank.
The code I wrote is as follows:
lst = list()
a = ''
msg = "Meet me at the Ritz Carlton at 9 o'clock, don't be late!" #message to encrypt
def Ccypher(string, shift = 2):
for i in range(len(msg)):
lst.append(ord(msg[i]) + shift)
a = a + str(chr(lst[i]))
return a
Ccypher(msg)
On my machine, with
global aadded, the return value ofCcypher(msg)is not blank:'Oggv"og"cv"vjg"Tkv|"Ectnvqp"cv";"q)enqem."fqp)v"dg"ncvg#'. You've probably just forgot to print it