Created
October 4, 2022 15:05
-
-
Save bandrel/9271b3a89fe00efd66b59e788da42cc6 to your computer and use it in GitHub Desktop.
Revisions
-
bandrel created this gist
Oct 4, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ #!/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)