-
-
Save PhoeniXkrypT/22b978dee79f3092d63f to your computer and use it in GitHub Desktop.
Reversing shift-XORed in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse_right_shift(value, shift, mult=0xffffffff): | |
output, i = 0, 0 | |
while i * shift < 32: | |
compartment = int(bin(0xffffffff << (32 - shift))[-32:], 2) >> (shift * i) | |
part_output = value & compartment | |
value ^= part_output >> shift & mult | |
output |= part_output | |
i += 1 | |
return output | |
def reverse_left_shift(value, shift, mult=0xffffffff): | |
output, i = 0, 0 | |
while i * shift < 32: | |
compartment = int(bin((0xffffffff >> (32- shift)) << (shift * i))[-32:], 2) | |
part_output = value & compartment | |
value ^= part_output << shift & mult | |
output |= part_output | |
i += 1 | |
return output | |
value = 3009615726 | |
_value = value ^ value >> 10 | |
assert reverse_right_shift(_value, 10) == value | |
_value = value ^ value << 15 & 15141003 | |
assert reverse_left_shift(_value, 15, 15141003) == value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment