+2

How to write a function to find values to decode a hidden text of an image BMP file

I'm trying to find an appropriate value for p & q to decode a hidden text of an image BMP file. The relevant code is as follows: def est_extract(): image_byte_array = est_get_bytes_containing_message() header_len = 54 message_bit_array = est_extract_bits_from_image( image_byte_array, header_len, p, q ) message_byte_array = est_convert_bits_to_bytes( message_bit_array ) est_write_message_text( message_byte_array ) if __name__ == '__main__': est_extract() i need to do it by following the steps below: **i need to write a function called est_bit_proportion which takes a Python array as an argument and computes the proportion of ones in it. And I am going to apply this to the existing message_bit_array for a particular choice of values for p and q. **A code which will try different values of p and q, namely all combinations of p = 1, 2, 3 and q = 1, 2, 3. There are thus nine combinations which I am going to try. **For each combination of p and q, you are going to run function est_bit_proportion to find the proportion of ones. **If the proportion of ones for some combination is less than 1 and greater than 0.5, I have the answer. Save those values of p and q and continue with the loop. So far I have tried with below-mentioned code for a in range(1, 4, 1): for b in range(1, 4, 1): bp = a/b print( "p =", a, "q =", b, "bp =", "%6.3f" % bp) if (bp > .5 and bp < 1): p = a q = b print( "The answer is:", "p =", p, "q =", q) But it's not working properly. The output is looking like below: p = 1 q = 1 bp = 1.000 p = 1 q = 2 bp = 0.500 p = 1 q = 3 bp = 0.333 p = 2 q = 1 bp = 2.000 p = 2 q = 2 bp = 1.000 p = 2 q = 3 bp = 0.667 The answer is: p = 2 q = 3 p = 3 q = 1 bp = 3.000 p = 3 q = 2 bp = 1.500 p = 3 q = 3 bp = 1.000 It would be really great if someone helps me to find the appropriate way to solve it.

2/13/2020 10:01:52 PM

Earl

2 Answers

New Answer

+3

It's really hard to get what the code is doing and copying it will just mess up with the indentation. Try writing the code into python playground and share the link over here.

+1

Thanks, but I was able to make it work