我是初学者,很抱歉这很明显或者很奇怪。我也很抱歉,如果这已经得到了回答,我只是找不到真正有效的东西。
我正试着制作一个程序来加密和解密文本文件。
我的想法是将字符加密成数字形式,并将它们相乘为加密,当然也可以作为解密。
加密部分工作得很好,但是当运行解密代码时,我会得到一个
不支持/的操作数类型:'str‘和'int’。
我试过浮点和整数,但它们不起作用。
加密代码:
import binascii
#ENCRYPTION ALGORITHM
algorithm = 2
#ASCII ----> NUMBERS
raw = raw_input("Enter text to encrypt:")
one = binascii.hexlify(raw)
two = binascii.hexlify(one)
#UNENCRYPTED HEX
unencrypted = int(two)
#ENCRYPT HEX
encrypted = unencrypted * algorithm
#PRINTS ENCRYPTED TEXT
print "%.9f" % encrypted解密码:
import time
import binascii
incorrectpasswords = 0
password=("mypass")
originpassword = password
x = 1
algorithm = 2
while x==1:
passwordattempt =raw_input("Enter Password:")
if passwordattempt == password:
print("Correct")
x = 2
if passwordattempt!= password:
print("Incorrect")
incorrectpasswords = incorrectpasswords + 1
if incorrectpasswords > 2:
if x == 1:
password = (generatedpassword)
print("Too many wrong attempts, please try again in one minute.")
time.sleep(60)
password=originpassword
encrypted = float(input("Enter text to unencrypt:"))
formatted = "%.9f" % encrypted
formatted2 = formatted
one = formatted2 / algorithm
print ("%.9f" % one)
two = binascii.unhexlify(one)
unencrypted = binascii.unhexlify(two)
print(unencrypted)而且,python 2.7中的binascii在python 3中不适用于我。
发布于 2017-04-09 02:25:46
您不应该尝试将格式化的字符串除以数字。
algorithm = 2
encrypted = float(input("Enter text to unencrypt:"))
one = encrypted / algorithm
print("%.9f" % one)https://stackoverflow.com/questions/43302347
复制相似问题