문제

i am newbie in python, and cannot do some easy stuf. I have a code from java

raw[j] = (byte) (chksum & 0xff)
raw[j + 1] = (byte) (chksum >> 0x08 & 0xff)
raw[j + 2] = (byte) (chksum >> 0x10 & 0xff)
raw[j + 3] = (byte) (chksum >> 0x18 & 0xff)

Where raw is a array of bytes I need to do it in python. But how can i cast int to bytes? And maybe anybody knows where can i get the library for using Blowfish crypting?

도움이 되었습니까?

해결책

Use the struct module to cast to and from bytes.

Your example would be:

raw[j] = struct.pack("B", chksum & 0xff)
etc..

Reference: http://docs.python.org/3/library/struct.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top