Provides option 'string' or 'file' to take input and prints the calculated SHA1 hash. unittest.main() has been commented because we probably dont want to run the test each time.
()
| 108 | |
| 109 | |
| 110 | def main(): |
| 111 | """ |
| 112 | Provides option 'string' or 'file' to take input and prints the calculated SHA1 hash. |
| 113 | unittest.main() has been commented because we probably dont want to run |
| 114 | the test each time. |
| 115 | """ |
| 116 | # unittest.main() |
| 117 | parser = argparse.ArgumentParser(description="Process some strings or files") |
| 118 | parser.add_argument( |
| 119 | "--string", |
| 120 | dest="input_string", |
| 121 | default="Hello World!! Welcome to Cryptography", |
| 122 | help="Hash the string", |
| 123 | ) |
| 124 | parser.add_argument("--file", dest="input_file", help="Hash contents of a file") |
| 125 | args = parser.parse_args() |
| 126 | input_string = args.input_string |
| 127 | # In any case hash input should be a bytestring |
| 128 | if args.input_file: |
| 129 | hash_input = open(args.input_file, "rb").read() |
| 130 | else: |
| 131 | hash_input = bytes(input_string, "utf-8") |
| 132 | print(SHA1Hash(hash_input).final_hash()) |
| 133 | |
| 134 | |
| 135 | # starting point of code |
no test coverage detected