Created
June 22, 2020 13:05
-
-
Save rvanlaar/b54a35cbe2f86b60b10990f0a4acfcdc to your computer and use it in GitHub Desktop.
Calculate Header TAGS
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
#!/usr/bin/env python3 | |
import argparse | |
import operator | |
from functools import reduce | |
def mktag(tag: str) -> int: | |
letters = [i for i in tag] | |
letters.reverse() | |
ords = [ord(i) for i in letters] | |
shifted = [operator.lshift(i, counter*8) for counter, i in enumerate(ords)] | |
return reduce(operator.or_, shifted) | |
def test() -> None: | |
assert mktag("CASt") == 1128354676 | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='Calculate TAG.') | |
parser.add_argument('tag', type=str, help='Tag to be calculated') | |
parser.add_argument('--test', help="run the test suite.", | |
action="store_true") | |
args = parser.parse_args() | |
if args.test: | |
test() | |
else: | |
print(mktag(args.tag)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment