Skip to content

Instantly share code, notes, and snippets.

@samueltangz
Created November 27, 2018 15:36
Show Gist options
  • Save samueltangz/86ca6ec7cde14915c32aabb15f91c295 to your computer and use it in GitHub Desktop.
Save samueltangz/86ca6ec7cde14915c32aabb15f91c295 to your computer and use it in GitHub Desktop.
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