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

Function main

hashes/sha1.py:138–161  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

136
137
138def 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
164if __name__ == "__main__":

Callers 1

sha1.pyFile · 0.70

Calls 2

SHA1HashClass · 0.85
final_hashMethod · 0.45

Tested by

no test coverage detected