I need to test the randomness of a Blum Blum Shub generator I built in Python, using the ENT randomness tests. I have a python array of pseudo random bits of form
[0, 1, 1, 1, 0, 0, 1, 0, 0, ...], and I need to write this sequence of bits into a binary file that I can then run through the ENT randomness test platform (ENT website linked here).
Would anyone be able to help me find a way to do this? I tried using the struct package, but I do not think I am using it correctly: if p is the bit array as shown above, I am writing to the file as follows using struct:
f=open("myfile","wb")
myfmt='b'*len(p)
bin=struct.pack(myfmt,*p)
f.write(bin)
f.close()
Could anyone point out how to correctly do this? Further, if instead the array was not of 0, 1 values but instead composed of the pseudo random positive integers, what would be the correct way to write these to a file to test for randomness?
pso we can't check :( I see from docs.python.org/3/library/struct.html#format-characters that the 'b' format string for a byte, so whateverpis an array of (something between -128 and 127), it should dump them into a binary file, one byte per input. For example, the following emits a 3-byte file as expected:with open('myfile', 'wb') as fid: fid.write(struct.pack('3b', *[1,0,1]))plooks like the array[0, 1, 1, 0, 1, 1, 0, 1, ...]. It is not that I get an error but that I am not sure if this is correct.H,I,L, orQformat characters for 1, 2, 4, or 8-bytes per element in the output file respectively. I'm not familiar with ENT though, so it's possible this isn't the format it requires (i.e., it might want random bits packed with no padding).