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.
()
| 122 | |
| 123 | |
| 124 | def main(): |
| 125 | """ |
| 126 | Provides option 'string' or 'file' to take input and prints the calculated SHA1 hash. |
| 127 | unittest.main() has been commented because we probably dont want to run |
| 128 | the test each time. |
| 129 | """ |
| 130 | # unittest.main() |
| 131 | parser = argparse.ArgumentParser(description='Process some strings or files') |
| 132 | parser.add_argument('--string', dest='input_string', |
| 133 | default='Hello World!! Welcome to Cryptography', |
| 134 | help='Hash the string') |
| 135 | parser.add_argument('--file', dest='input_file', help='Hash contents of a file') |
| 136 | args = parser.parse_args() |
| 137 | input_string = args.input_string |
| 138 | #In any case hash input should be a bytestring |
| 139 | if args.input_file: |
| 140 | with open(args.input_file, 'rb') as f: |
| 141 | hash_input = f.read() |
| 142 | else: |
| 143 | hash_input = bytes(input_string, 'utf-8') |
| 144 | print(SHA1Hash(hash_input).final_hash()) |
| 145 | |
| 146 | |
| 147 | if __name__ == '__main__': |
no test coverage detected