The ultimate objective is to flip the last bit of byte at position X. Let's say we start off with a string from a website and we base64 decode it so it's something we can work with:
IV = "2RDs+xm/AxtYj+XViJmBPQ=="
IV = base64.b64decode(IV)
That gives us something that looks like (����X��Ո��=) which looks like garbage but it's something we can work with. The best way to work with this would be to put it in a list.
woop = list(IV)
Let's say in this example that we're looking to flip the last bit at the 2nd byte. Python starts counting from zero so we need to reduce our counter by 1. Otherwise, we'll be pointing our program at the 3rd byte! To flip anything you XOR it by 1. Now here's my problem...
CounterX = CounterX - 1
woop[CounterX] = chr(ord(IV[CounterX]) ^ 1)
woop = "".join(woop)
IV = woop
I'm pretty sure that flips the entire byte. How can I tell it to flip only the last bit of the byte at IV[CounterX]?
base64.decode
returns a stringbytes(IV)
to ensure 8 bit chunks ... but Im not sure I dont use python3 muchprint bin(0xff ^ 0x01)
so again we return to what makes you think that this is not the behavior you are seeing? can you give us an example that demonstrates the issue?