[英]python how to convert Special string u'\x08' u'\x09' u'\x03' to 8 9 3
use crypto encrypt string in Go. 在Go中使用加密加密字符串。
PKCS7 Padding for ciphertext, because ciphertext must be a multiple of the block size (16). PKCS7填充密文,因为密文必须是块大小(16)的倍数。
exa: ciphertext is : 123456789abcde. (len:14)
pandding: []byte("123456789abcdef") + []byte(2) + []byte(2)
Python decode: Python解码:
list: [u'1', u'2', u'3', ...,u'd', u'e', u'\x02', u'\x02']
now, can not get u'\\x02' to number 2. 现在,无法将u'\\ x02'设置为数字2。
I'm sure this is not the best way to do this in python, but I tend to think in C, so here goes. 我敢肯定这不是在python中执行此操作的最佳方法,但我倾向于在C语言中进行思考,因此请继续。 It is probably pretty bad according to most people, but it gets the job done.
对大多数人来说,这可能是很糟糕的,但它可以完成工作。
c = u'\x02'
byte = bytearray(c, 'utf-8')[0]
print(chr(ord('0') + byte))
=> 2
Inspired by andars 受到安达斯的启发
c = ord(u'\x02') + ord('0')
print chr(c)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.