I have a list of 100 bit, for example:
X=''.join([random.choice(['0', '1']) for i in range(100)])
X=[0,1,0,1,1...]
At the beginning of the cycle, I have been generate random initialization vector with n length:
Xlen=5
IV=''.join([random.choice(['0', '1']) for i in range(Xlen)])
The problem is I need to generate new IV based on the previous X[n] and IV[n] using the bit addition function. Note that n=5.
For example X[0]=[0,1,0,0,1] and IV[0]=[1,0,1,0,1]. The new IV should be updated to X[0]+IV[0]=IV[1] which will produce the result of [1,1,1,1,0].
X[0] and IV[0] is the list of bit and initialization vector at cycle 0.
And operation of generating new IV will be continuously repeated for the next n=5 until n=100.
Please help me to solve this issue. Thank you.
I think what you want is a function that XORs two lists of integers (the IV and part of the data) and generates the XORed version of it. The function can be implemented using the operator
^in pythonI am using here the 'bits' as integers, but if you need to use strings, you can just convert each char using
int()before calling the functionHere is one example of how to use this function to calculate a new IV for each 5 elements of X
The result is this: