Skip to content

Instantly share code, notes, and snippets.

@bandrel
Created October 4, 2022 15:05
Show Gist options
  • Save bandrel/9271b3a89fe00efd66b59e788da42cc6 to your computer and use it in GitHub Desktop.
Save bandrel/9271b3a89fe00efd66b59e788da42cc6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import re
import sys
def convert_hex_base64(input):
from base64 import b64encode, b64decode
# hex -> base64
b64 = b64encode(bytes.fromhex(input)).decode()
# base64 -> hex
s2 = b64decode(b64.encode()).hex()
assert input == s2
return b64
def convert_dollar_r(input):
c = re.search('\$1\$R:1000:(\S+):(\S+)', input)
if c is not None:
a = convert_hex_base64(c.group(1))
b = convert_hex_base64(c.group(2))
return f"sha256:1000:{a}:{b}"
else:
c = re.search('\$1\$A:1000:(\S+):(\S+)', input)
a = convert_hex_base64(c.group(1))
b = convert_hex_base64(c.group(2))
return f"sha1:1000:{a}:{b}"
a = sys.argv[1]
c = convert_dollar_r(a)
print(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment