#!/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)