Python3 reading a binary file, 4 bytes at a time and xor it with a 4 byte long key
<p>I want to read a binary file, get the content four bytes by four bytes and perform int operations on these packets.</p>

<p>Using a dummy binary file, opened this way:</p>

<pre><code>with open('MEM_10001000_0000B000.mem', 'br') as f:
    for byte in f.read():
            print (hex(byte))
</code></pre>

<p>I want to perform an encryption with a 4 byte long key, <code>0x9485A347</code> for example.</p>

<p>Is there a simple way I can read my files 4 bytes at a time and get them as int or do I need to put them in a temporary result using a counter?</p>

<p>My original idea is the following:</p>

<pre><code>        current_tmp = []
        for byte in data:
            current_tmp.append(int(byte))
            if (len(current_tmp) == 4):
                    print (current_tmp)
                    # but current_tmp is an array not a single int
                    current_tmp = []
</code></pre>

<p>In my example, instead of having <code>[132, 4, 240, 215]</code> I would rather have <code>0x8404f0d7</code></p>