Python 需要帮助制作这个加密机吗

Python 需要帮助制作这个加密机吗,python,encryption,Python,Encryption,嗨,我有一个encryter,我想在学校普通中等教育证书级别上制作,我需要帮助,因为我不知道它有什么问题,现在我希望最后一个数字会弹出一个加密脚本的istead,但我有一个字符串索引错误,我如何修复这个错误 # This asks a user for an input of text integers etc text = input('Enter A Word : ') # Empty Value used to store the encrypted value encrypt = ''

嗨,我有一个encryter,我想在学校普通中等教育证书级别上制作,我需要帮助,因为我不知道它有什么问题,现在我希望最后一个数字会弹出一个加密脚本的istead,但我有一个字符串索引错误,我如何修复这个错误

# This asks a user for an input of text integers etc
text = input('Enter A Word : ')
# Empty Value used to store the encrypted value
encrypt = ''
# Empty temp value replaced at every iteration of the wencryption process
temp = ''
# Empty temp value replaced at every iteration of the wencryption process
temp2 = ''

# key used to shift the letters
key = int(input('Enter your key (their will be more encryption) : '))

for i in range(0,len(text)):
    # Rearranges text in a caps switch
    if str.islower(text[i]):
        temp += str.upper(text[i])
    elif str.isupper(text[i]):
        temp += str.lower(text[i])
    else:
        temp += text[i]

for j in range(0, len(temp)):
    temp = str(ord(temp[j]))
    temp2 += temp + str(key)
    encrypt += temp2

print(encrypt)

我真的不明白在temp=strordtemp[I]时会发生什么

此代码生成一个数字:

text = input('Enter A Word : ') ##This asks a user for an input of text integers etc
encrypt = '' ##Empty Value used to store the encrypted value
temp = '' ##Empty temp value replaced at every iteration of the wencryption process
temp2 = '' ##Empty temp value replaced at every iteration of the wencryption process

key=int(input('Enter your key (their will be more encryption) : '))##key used to shift the letters


for i in range(0,len(text)):
    ##Rearranges text in a caps switch
    if str.islower(text[i])==True:
        temp=temp+str.upper(text[i])
    elif str.isupper(text[i])==True:
        temp=temp+str.lower(text[i])
    else:
        temp=temp+text[i]
for j in temp:
    temp=str(ord(j))
    temp2=temp2+temp+str(key)
    encrypt=encrypt+temp2
print(encrypt)

感谢大家的支持;我想出了如何解决这个加密算法。答案将张贴在PS下方,您显然可以使用此选项。 此Python脚本使用for和range函数将字符串拆分为每个单独的字符,以便可以重新排列

首先,我做了一个简单的cAPS开关,暂时不需要,这样我就可以确保我的加密机的安全。然后,我使用ord函数将每个字符转换为其ascii等价物,然后使用简单的密码技术,并请求一个简单的整数密钥,如3[Caesar]或13[ROT13]。然后添加ascii值和键,以便ascii值相应地更改

然后,我们使用chr函数将ascii数字转换为字符,该函数用于将ascii值转换为chr。完成后,我们使用连接将每个字母连接到最终变量,以便稍后在屏幕上显示

enter code here

text = input('Enter A Word : ') ##This asks a user for an input of text integers etc
encrypt = '' ##Empty Value used to store the encrypted value
temp = '' ##Empty temp value replaced at every iteration of the encryption process
temp2 =0 ##Empty temp value replaced at every iteration of the encryption process
temp_val=0
temp_char=''

key=int(input('Enter your key (their will be more encryption) : '))##key used to shift the letters

for i in range(0,len(text)):
    ##Rearranges text in a caps switch
    if str.islower(text[i])==True:
        temp=temp+str.upper(text[i])
    elif str.isupper(text[i])==True:
        temp=temp+str.lower(text[i])
    else:
        temp=temp+text[i]
for j in range(0,len(temp)):
    temp_val=0
    temp2=0
    temp_val=ord(temp[j])
    temp2=temp2+temp_val+key
    temp_char=temp_char+chr(temp2)
    encrypt=temp_char
print(encrypt)
print(temp)
print(temp2)

为什么要创建自己的加密?这是某个赋值的一部分吗?你能添加错误回溯,这样我们就可以看到错误发生的地方吗?temp=strordtemp[i]我可能应该是一个j。感谢大家的支持,这是一个赋值错误回溯是temp=strordtemp[j]indexer错误:字符串索引超出范围。我很抱歉需要回退您的问题-让我解释一下为什么这是必要的。堆栈溢出的目的是生成可能对其他人有用的问题和答案页面。所以,当你在2月28日提问时,你很幸运地在五分钟内得到了米凯尔·布伦纳的回答。这将创建一对有用的问答。然而,您随后对您的问题进行了实质性修改,以至于Mikael的答案可能不再有任何意义,这对他们来说是不公平的。ord将临时[i]处的字符转换为序号,然后再转换回str,以便他们可以连接字符串。