バイナリ暗号文をテキストに変換してから、暗号文を解読しようとしています。しかし、次のエラーが発生し続けます: ValueError: 基数 2 の int() の無効なリテラル: '[0,'
私のコードを見て、何が起こっているのか見ていただけますか?
def onetimepad():
plaintext = str(input("please input plaintext string: "))
key = input("please input key: ")
#convert string to binary
# printing original string
print("The original string is : " + str(plaintext))
# using join() + ord() + format()
# Converting String to binary
plaintext_bi = ''.join(format(ord(i), '08b') for i in plaintext)
# printing result
print("The PlainText after binary conversion : " + str(plaintext_bi))
if (len(plaintext_bi) != len(key)):
#length of plaintext is not the same length of the key so break
print("ERROR : Plaintext is not the same size of Key")
else:
# if the length is correct then xor
cipher_bi = [ord(a) ^ ord(b) for a,b in zip(plaintext_bi,key)]
print("Binary Ciphertext: "+ str(cipher_bi))
#convert binary to ciphertext
ascii_string = "".join([chr(int(binary, 2)) for binary in str(cipher_bi).split(" ")])
print(ascii_string)
def main():
onetimepad()
main()