Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. def undoShiftRightAndXor(value, shift):
  2. i = 0
  3. result = 0
  4.  
  5. while ((i * shift) < 32):
  6. # Create Mask
  7. mask = (-1 << numpy.right_shift((32 - shift), (shift * i)))
  8. part = value & mask
  9. # Undo the xor
  10. value = value ^ numpy.right_shift(part, shift)
  11. # Add part to result
  12. result = result | part
  13. i += 1
  14.  
  15. return result
  16.  
  17. def undoShiftLeftAndXor(value, shift, mask):
  18. i = 0
  19. result = 0
  20.  
  21. while ((i * shift) < 32):
  22. # Create mask
  23. partialMask = (numpy.right_shift(-1, (32 - shift))) << (shift * i)
  24. part = value & partialMask
  25. # Undo the xor
  26. value = value ^ ((part << shift) & mask)
  27. # Add part to result
  28. result = result | part
  29. i += 1
  30.  
  31. return result
  32.  
  33. def originalValue(output):
  34. original = output
  35. original = undoShiftRightAndXor(original, 18)
  36. original = undoShiftLeftAndXor(original, 15, 0xefc60000)
  37. original = undoShiftLeftAndXor(original, 7, 0x9d2c5680)
  38. original = undoShiftRightAndXor(original, 11)
  39. return original
  40.  
  41. def getState(allNumber):
  42. state = []
  43. for n in allNumber:
  44. state.append(originalValue(n))
  45. return state
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement