开发者

Ruby, XOR random bytes in binary string

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 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜