MCPcopy Create free account
hub / github.com/geekcomputers/Python / main

Function main

sha1.py:110–132  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

108
109
110def 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

Callers 1

sha1.pyFile · 0.70

Calls 2

SHA1HashClass · 0.85
final_hashMethod · 0.80

Tested by

no test coverage detected