开发者

Ruby, XOR random bytes in binary string

开发者 https://www.devze.com 2023-02-28 04:20 出处:网络
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:

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

精彩评论

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