Provides option 'string' or 'file' to take input and prints the calculated SHA1 hash. unittest.main() has been commented out because we probably don't want to run the test each time.
()
| 136 | |
| 137 | |
| 138 | def main(): |
| 139 | """ |
| 140 | Provides option 'string' or 'file' to take input and prints the calculated SHA1 |
| 141 | hash. unittest.main() has been commented out because we probably don't want to run |
| 142 | the test each time. |
| 143 | """ |
| 144 | # unittest.main() |
| 145 | parser = argparse.ArgumentParser(description="Process some strings or files") |
| 146 | parser.add_argument( |
| 147 | "--string", |
| 148 | dest="input_string", |
| 149 | default="Hello World!! Welcome to Cryptography", |
| 150 | help="Hash the string", |
| 151 | ) |
| 152 | parser.add_argument("--file", dest="input_file", help="Hash contents of a file") |
| 153 | args = parser.parse_args() |
| 154 | input_string = args.input_string |
| 155 | # In any case hash input should be a bytestring |
| 156 | if args.input_file: |
| 157 | with open(args.input_file, "rb") as f: |
| 158 | hash_input = f.read() |
| 159 | else: |
| 160 | hash_input = bytes(input_string, "utf-8") |
| 161 | print(SHA1Hash(hash_input).final_hash()) |
| 162 | |
| 163 | |
| 164 | if __name__ == "__main__": |
no test coverage detected