Skip to content

Commit 8561554

Browse files
Added script for hashing files
1 parent 241d62f commit 8561554

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

Hashing file/app.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import sys
2+
import hashlib
3+
4+
methods = {
5+
'1':'md5',
6+
'2':'sha1',
7+
'3':'sha256',
8+
'4':'sha512',
9+
}
10+
11+
def help():
12+
print("Usage: python app.py filename")
13+
print("""
14+
Available hash methods
15+
[1] MD5
16+
[2] SHA1
17+
[3] SHA256
18+
[4] SHA512
19+
""")
20+
21+
22+
def file_read(filename):
23+
try:
24+
content = open(filename, "r").read()
25+
content = content.encode('utf-8')
26+
return content
27+
except:
28+
print("Openning file error")
29+
exit(0)
30+
31+
def hash_text(content,method):
32+
return hashlib.new(methods[method],content).hexdigest()
33+
34+
35+
def write_content(hashed_content):
36+
new_file=open('Hased data.txt','w')
37+
new_file.write(hashed_content)
38+
new_file.close()
39+
40+
41+
42+
43+
if __name__ == "__main__":
44+
help()
45+
if len(sys.argv) < 2:
46+
help()
47+
print("No file specified")
48+
exit(0)
49+
50+
filename = sys.argv[1]
51+
52+
content = file_read(filename)
53+
method=int(input())
54+
if(method > 4 or method < 1):
55+
print("No method or wrong method specified. Using default md5 hashing method")
56+
method = 1
57+
58+
hashed_content = hash_text(content,str(method))
59+
60+
write_content(hashed_content)

Hashing file/readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Hashing a file is a python script which takes data from a text file and hash it with some algorithms
2+
3+
### Encryption algorithms
4+
* MD5
5+
* SHA1
6+
* SHA256
7+
* SHA512
8+
9+
10+
It will store all the hashed data into a new text file called as **Hased data.txt**

Hashing file/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hashlib
2+
sys

0 commit comments

Comments
 (0)