Print the representation with repr()
or the %r
string formatting placeholder:
print '\nplain text: %r' % text
print '\nActual key: %r' % key
print '\nCipher text: %r' % cipher_text
or you can explicitly encode the text to the string_escape
encoding:
print '\nplain text:', text.encode('string_escape')
print '\nActual key:', key.encode('string_escape')
print '\nCipher text:', cipher_text.encode('string_escape')
Neither method will turn all bytes into \xhh
escape sequences, only those outside of the printable ASCII character range.
To turn all characters into escape sequences, you'd have to use something like:
def tohex(string):
return ''.join('\\x{:02x}'.format(ord(c)) for c in string)
and then
print '\nplain text:', tohex(text)
print '\nActual key:', tohex(key)
print '\nCipher text:', tohex(cipher_text)