I have a string of binary data and want to开发者_如何学Python pick a single character, and ^ it by 0xff. Is there a simple way to do this? For example:
x = "test\223\434t"
r = rand(x.length)
c = x[r].unpack("H*") ^ 0xff # This doesnt work
# Re concat the string
bytes = x.bytes.to_a
# => [116, 101, 115, 116, 147, 28, 116]
bytes[rand(bytes.length)] ^ 0xff
# => 139
精彩评论