Код: Выделить всё
Traceback (most recent call last):
File "C:\Users\mynam\OneDrive\Masaüstü\desktop2\Vısual Studio Code\python\encrypt-decrypt\cipher.py", line 29, in
shifted_value = shifted_value + user_input4
^^^^^^^^^^^^^
NameError: name 'shifted_value' is not defined
Код: Выделить всё
custom_alphabet = "NİDALQWERTYUIOPĞÜSFGHJKŞZXCVBMÖÇnidalüğpoıuytrewqşkjhgfsçömbvcxz37890712456+=-/%()*$&"
def three_shift_encrypt(text, alphabet):
for character in text: #characters contain all of the chars in text
global shifted_value
shifted_value = alphabet.find(character) + 3
print(custom_alphabet[shifted_value], end='')
def three_shift_decrypt(text2, alphabet2):
for character2 in text2:
global shifted_value2
shifted_value2 = alphabet2.find(character2) - 3
print(custom_alphabet[shifted_value2], end='')
print('To exit the program press Ctrl + C')
while True:
user_input1 = input('encrypt or decrypt or change shitf value?(e/d/change) -->')
if user_input1 == 'e':
user_input2 = input('enter plaintext -->')
three_shift_encrypt(user_input2, custom_alphabet)
print('\n')
elif user_input1 == 'd':
user_input3 = input('enter plaintext -->')
three_shift_decrypt(user_input3, custom_alphabet)
print('\n')
elif user_input1 == 'change':
user_input4 = input('enter the new shift value (int) -->')
shifted_value = shifted_value + user_input4
shifted_value2 = shifted_value2 + user_input4
else:
print('please enter e or d')
break
На самом деле сдвинутые значения не были глобальными. Я пытался сделать его глобальным, но это не сработало.
Почему я получаю эту ошибку?
Подробнее здесь: https://stackoverflow.com/questions/786 ... ot-defined