nishanth
nishanth

Reputation: 11

TypeError: a bytes-like object is required, not 'str' in known plain text attack

  1. I am writing a code in python to print a string as output but i get the following errors:

Traceback (most recent call last): File "xopa.py", line 413, in Main() File "xopa.py", line 410, in Main XOR(args[0], args[1], options) File "xopa.py", line 364, in XOPA print('Key (hex): 0x%s' % binascii.b2a_hex(result.key)) TypeError: a bytes-like object is required, not 'str'

  1. i had removed ord() function because I thought its deprecated
  2. https://raw.githubusercontent.com/DidierStevens/DidierStevensSuite/master/xor-kpa.py

The line which error shows is below

print('Key (hex): 0x%s' % binascii.b2a_hex(result.key))

Upvotes: 0

Views: 366

Answers (1)

Abhiram Satputé
Abhiram Satputé

Reputation: 604

According to the official documentation the input for binascii.b2a_hex(result.key) is a byte object, not a string.

You can try this instead : print('Key (hex): 0x%s' % binascii.b2a_hex(b(result.key)))

or

print('Key (hex): 0x%s' % binascii.b2a_hex((result.key).encode()))

Upvotes: 0

Related Questions