Created
November 27, 2018 15:36
-
-
Save samueltangz/86ca6ec7cde14915c32aabb15f91c295 to your computer and use it in GitHub Desktop.
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 encrypt(exp, num, key): | |
assert key >> 512 <= 1 | |
num = num + key | |
msg = bin(num)[2:][::-1] | |
C, i = 0, 1 | |
for b in msg: | |
C += int(b) * (exp**i + (-1)**i) | |
i += 1 | |
try: | |
enc = hex(C)[2:].rstrip('L').decode('hex') | |
except: | |
enc = ('0' + hex(C)[2:].rstrip('L')).decode('hex') | |
return enc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment