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

Function main

hashes/sha1.py:124–144  ·  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

122
123
124def 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
147if __name__ == '__main__':

Callers 1

sha1.pyFile · 0.70

Calls 2

SHA1HashClass · 0.85
final_hashMethod · 0.80

Tested by

no test coverage detected