Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tI&x27;我想为学校制作一个加密程序,但我';我很难用我的特殊字符替换字母数字_Python - Fatal编程技术网

Python tI&x27;我想为学校制作一个加密程序,但我';我很难用我的特殊字符替换字母数字

Python tI&x27;我想为学校制作一个加密程序,但我';我很难用我的特殊字符替换字母数字,python,Python,我尝试过使用不同导入的多种方法,但当它们在我的代码中实现时,它们似乎都有某种问题。 以下是当前版本: #Variables passcode= 24601 confirm= 0 msg= 0 x=0 #Functions def confirm_choice(): answer = "" while answer not in ["y", "n"]: answer = input("Is th

我尝试过使用不同导入的多种方法,但当它们在我的代码中实现时,它们似乎都有某种问题。 以下是当前版本:

#Variables
passcode= 24601
confirm= 0
msg= 0
x=0

#Functions
def confirm_choice():
    answer = ""
    while answer not in ["y", "n"]:
        answer = input("Is this the message you want encrypted? Y/N: ").lower()
    return answer == "y"

def encrypt():
  x= msg.replace("A", "‡")
  x= msg.replace("B", "֎")
  x= msg.replace("C", "Ѫ")
  x= msg.replace("D", "^")
  x= msg.replace("E", "҈")
  x= msg.replace("F", "₩")
  x= msg.replace("G", "Д")
  x= msg.replace("H", "҂")
  x= msg.replace("I", "*")
  x= msg.replace("J", "Ͱ")
  x= msg.replace("K", "֍")
  x= msg.replace("L", "҉")
  x= msg.replace("M", "!")
  x= msg.replace("N", "Ӕ")
  x= msg.replace("O", "჻")
  x= msg.replace("P", "ʘ")
  x= msg.replace("Q", "¶")
  x= msg.replace("R", "%")
  x= msg.replace("S", "Θ")
  x= msg.replace("T", "@")
  x= msg.replace("U", "Δ")
  x= msg.replace("V", "$")
  x= msg.replace("W", "‽")
  x= msg.replace("X", "¥")
  x= msg.replace("Y", "˧")
  x= msg.replace("Z", "~")
  x= msg.replace("1", "Փ")
  x= msg.replace("2", "§")
  x= msg.replace("3", "₿")
  x= msg.replace("4", "Ω")
  x= msg.replace("5", "©")
  x= msg.replace("6", "&")
  x= msg.replace("7", "£")
  x= msg.replace("8", "◊")
  x= msg.replace("9", "€")
  x= msg.replace("0", "#")
  print(x)

#Passcode guarantees only authorised users can use and access encryption key
code= int(input("Enter the passcode: " ))
if passcode == code:
  print("Access Granted.")
else:
  print("Incorrect Passcode. Access Denied")
  quit

#Takes input for encryption
msg= input("What message do you wish to send, comrade? Make sure it is in all capitals. \n")

confirm_choice()

encrypt()
注释

我正在replit.com中编写代码,但我不确定这是否会导致此类问题


确认选项和密码函数是针对标题上的“程序复杂性”的。

每次执行新的
msg.replace
,您都会覆盖
x
,因此只有最后一次替换才会生效。另外,
quit()
是一个内置函数。这应该行得通

#变量
密码=24601
确认=0
msg=0
x=0
#功能
def confirm_choice():
答案=”“
答案不在[“y”,“n”]:
回答=输入(“这是您想要加密的邮件吗?是/否:”).lower()
返回答案==“y”
def加密(消息:str):
x=msg.replace(“A”、“——”)
x=x。替换(“B”,“֎”)
x=x。替换(“C”、“Ѫ”)
x=x。替换(“D”,“^”)
x=x。替换为(“E”,“҈”)
x=x。替换为(“F”,“₩”)
x=x。替换(“G”、“Б”)
x=x。替换(“H”和“҂”)
x=x。替换(“I”,“*”)
x=x。替换(“J”、“Ͱ”)
x=x。替换为(“K”,“֍”)
x=x。替换(“L”,“҉”)
x=x。替换(“M”,“!”)
x=x。替换(“N”,“Ӕ”)
x=x。替换“O”჻")
x=x。替换(“P”、“ʘ”)
x=x。替换(“Q”和“Q”)
x=x。替换(“R”、“%”)
x=x。替换(“S”、“Θ”)
x=x。替换(“T”,“@”)
x=x。替换(“U”,“Δ”)
x=x。替换(“V”,“美元”)
x=x。替换为(“W”和“——”)
x=x。替换(“x”,“日元”)
x=x。替换为(“Y”,“˧”)
x=x。替换(“Z”,“~”)
x=x。替换(“1”,“Փ”)
x=x。替换(“2”和“§”)
x=x。替换(“3”₿")
x=x。替换(“4”Ω")
x=x。替换(“5”和“)”)
x=x。替换(“6”和“&”)
x=x。替换(“7”和“7”)
x=x。替换(“8”◊")
x=x。替换(“9”和“€”)
x=x。替换(“0”,“#”)
返回x
#密码保证只有授权用户才能使用和访问加密密钥
code=int(输入(“输入密码:”)
如果密码==代码:
打印(“已授予访问权限”)
其他:
打印(“密码不正确,访问被拒绝”)
退出
#接受加密输入
msg=输入(
“同志,你想发什么信息?确保所有的大写字母都有。\n”)
如果确认_选项():
打印(加密(msg))
其他:
打印(msg)

每次执行新的
msg.replace
,您都会覆盖
x
,因此只有最后一次替换才会生效。此外,
quit()
是一个内置函数。这应该可以工作

#变量
密码=24601
确认=0
msg=0
x=0
#功能
def confirm_choice():
答案=”“
答案不在[“y”,“n”]:
回答=输入(“这是您想要加密的邮件吗?是/否:”).lower()
返回答案==“y”
def加密(消息:str):
x=msg.replace(“A”、“——”)
x=x。替换(“B”,“֎”)
x=x。替换(“C”、“Ѫ”)
x=x。替换(“D”,“^”)
x=x。替换为(“E”,“҈”)
x=x。替换为(“F”,“₩”)
x=x。替换(“G”、“Б”)
x=x。替换(“H”和“҂”)
x=x。替换(“I”,“*”)
x=x。替换(“J”、“Ͱ”)
x=x。替换为(“K”,“֍”)
x=x。替换(“L”,“҉”)
x=x。替换(“M”,“!”)
x=x。替换(“N”,“Ӕ”)
x=x。替换“O”჻")
x=x。替换(“P”、“ʘ”)
x=x。替换(“Q”和“Q”)
x=x。替换(“R”、“%”)
x=x。替换(“S”、“Θ”)
x=x。替换(“T”,“@”)
x=x。替换(“U”,“Δ”)
x=x。替换(“V”,“美元”)
x=x。替换为(“W”和“——”)
x=x。替换(“x”,“日元”)
x=x。替换为(“Y”,“˧”)
x=x。替换(“Z”,“~”)
x=x。替换(“1”,“Փ”)
x=x。替换(“2”和“§”)
x=x。替换(“3”₿")
x=x。替换(“4”Ω")
x=x。替换(“5”和“)”)
x=x。替换(“6”和“&”)
x=x。替换(“7”和“7”)
x=x。替换(“8”◊")
x=x。替换(“9”和“€”)
x=x。替换(“0”,“#”)
返回x
#密码保证只有授权用户才能使用和访问加密密钥
code=int(输入(“输入密码:”)
如果密码==代码:
打印(“已授予访问权限”)
其他:
打印(“密码不正确,访问被拒绝”)
退出
#接受加密输入
msg=输入(
“同志,你想发什么信息?确保所有的大写字母都有。\n”)
如果确认_选项():
打印(加密(msg))
其他:
打印(msg)

你可以试试字典:

dct = {'A': '‡', 'B': '֎', 'C': 'Ѫ', 'D': '^', 'E': '҈', 'F': '₩', 'G': 'Д', 'H': '҂', 'I': '*', 'J': 'Ͱ', 'K': '֍', 'L': '҉', 'M': '!', 'N': 'Ӕ', 'O': '჻', 'P': 'ʘ', 'Q': '¶', 'R': '%', 'S': 'Θ', 'T': '@', 'U': 'Δ', 'V': '$', 'W': '‽', 'X': '¥', 'Y': '˧', 'Z': '~', '1': 'Փ', '2': '§', '3': '₿', '4': 'Ω', '5': '©', '6': '&', '7': '£', '8': '◊', '9': '€', '0': '#'}

word = input(">>> ")

for k in dct:
    word = word.replace(k, dct[k])
    
print(word)

你可以试试字典:

dct = {'A': '‡', 'B': '֎', 'C': 'Ѫ', 'D': '^', 'E': '҈', 'F': '₩', 'G': 'Д', 'H': '҂', 'I': '*', 'J': 'Ͱ', 'K': '֍', 'L': '҉', 'M': '!', 'N': 'Ӕ', 'O': '჻', 'P': 'ʘ', 'Q': '¶', 'R': '%', 'S': 'Θ', 'T': '@', 'U': 'Δ', 'V': '$', 'W': '‽', 'X': '¥', 'Y': '˧', 'Z': '~', '1': 'Փ', '2': '§', '3': '₿', '4': 'Ω', '5': '©', '6': '&', '7': '£', '8': '◊', '9': '€', '0': '#'}

word = input(">>> ")

for k in dct:
    word = word.replace(k, dct[k])
    
print(word)

str.translate
+
str.maketrans
比一行36个替换要高效得多

def encrypt():
    x = msg.translate(str.maketrans({'A': '‡', 'B': '֎', 'C': 'Ѫ', 'D': '^', 'E': '҈', 'F': '₩', 'G': 'Д', 'H': '҂', 'I': '*', 'J': 'Ͱ', 'K': '֍', 'L': '҉', 'M': '!', 'N': 'Ӕ', 'O': '჻', 'P': 'ʘ', 'Q': '¶', 'R': '%', 'S': 'Θ', 'T': '@', 'U': 'Δ', 'V': '$', 'W': '‽', 'X': '¥', 'Y': '˧', 'Z': '~', '1': 'Փ', '2': '§', '3': '₿', '4': 'Ω', '5': '©', '6': '&', 
'7': '£', '8': '◊', '9': '€', '0': '#'}))
    print(x)

str.translate
+
str.maketrans
比一行36个替换要高效得多

def encrypt():
    x = msg.translate(str.maketrans({'A': '‡', 'B': '֎', 'C': 'Ѫ', 'D': '^', 'E': '҈', 'F': '₩', 'G': 'Д', 'H': '҂', 'I': '*', 'J': 'Ͱ', 'K': '֍', 'L': '҉', 'M': '!', 'N': 'Ӕ', 'O': '჻', 'P': 'ʘ', 'Q': '¶', 'R': '%', 'S': 'Θ', 'T': '@', 'U': 'Δ', 'V': '$', 'W': '‽', 'X': '¥', 'Y': '˧', 'Z': '~', '1': 'Փ', '2': '§', '3': '₿', '4': 'Ω', '5': '©', '6': '&', 
'7': '£', '8': '◊', '9': '€', '0': '#'}))
    print(x)

那么,问题是什么呢?将msg作为参数传递给encrypt函数,然后在encrypt函数中添加参数x“当它们在我的代码中实现时,它们似乎都有某种问题“我们只能帮助您解决实际描述的问题。那么,问题是什么?将msg作为参数传递给encrypt函数,并在encrypt函数中添加参数x”“当它们在我的代码中实现时,似乎都有某种问题”我们只能帮助您解决您实际描述的问题。我同意这更实际。我同意这更实际。