title: Forcing integer overflow in Python
body: <p>I am trying to emulate something written in Java in python.  There is a symmetric encryption algorithm in the Java part, where key generation relies on Java long integers overflowing. I now need to do this in Python to be able to decrypt there. I did not write the encryption algorithm, and I cannot change that.  This is part of the key generator function in Java:</p>
  
  <pre><code>long a;
  long b;
  ...
  for (...)
      ...
      a = b + ((b &lt;&lt; 1) + (b &lt;&lt; 4) + (b &lt;&lt; 7) + (b &lt;&lt; 8) + (b &lt;&lt; 35));
  </code></pre>
  
  <p>Now when I copy this as it is to Python, I will receive massive numbers, as Python does what it is supposed to do and adds more bytes to my integer, while in Java the integers just keep overflowing and eventually a 64 bit key is returned.  This is not the entirety of the code, it is actually a loop that keeps doing this and other things to a and b, so I cannot just take the highest 64 bits or something like that and treat that as my new a. </p>
  
  <p>However, I now need to emulate this behaviour in Python to get my decryption key. </p>
  
  <p>How do I do this in Python? Is it even possible, or do I need to rely on a C function for this part, and do the key generation there? </p>