私は初心者ですが、これは明白です。これが前に答えられたのであれば、本当にうまくいくものは見つけられません。binascii /: 'str'と 'int'のサポートされていないオペランドのタイプ
私は、テキストファイルを暗号化して解読するプログラムを作ろうとしています。
私の考えは、文字を数値形式に暗号化し、それらを暗号として乗算し、もちろん解読として分割することです。
暗号化の部分は完全に動作しますが、復号化コードを実行しているとき、私は私がfloatとint型を試してみた
unsupported operand type(s) for /: 'str' and '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)
はまた、binasciiとしてPython 2.7で、これはあなたがいけないのpythonで私のために3
'formatted2'は文字列であり、' algorithm'は整数です。彼らはそのような数学的操作を行うことはできません。おそらくあなたは '暗号化された/アルゴリズム'を使用するつもりでしたか? – zondo
'formatted2 = formatted'はむしろ無意味なようです...' formatted'を使用してください –