Skip to content

Commit f17a721

Browse files
authored
Merge pull request #34 from harshareddy794/harsha
Added script for hashing files
2 parents 59d8a1d + 7a26efe commit f17a721

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

Hashing file/app.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
print("Done writing data to file hash data.txt")
40+
41+
if __name__ == "__main__":
42+
help()
43+
if len(sys.argv) < 2:
44+
help()
45+
print("No file specified")
46+
exit(0)
47+
48+
filename = sys.argv[1]
49+
50+
content = file_read(filename)
51+
method=int(input())
52+
if(method > 4 or method < 1):
53+
print("No method or wrong method specified. Using default md5 hashing method")
54+
method = 1
55+
56+
hashed_content = hash_text(content,str(method))
57+
58+
write_content(hashed_content)

Hashing file/readme.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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**
11+
12+
### Installing required libraries
13+
14+
`` pip install -r"requirements.txt" ``
15+
16+
17+
### Using script
18+
19+
* `` python app.py <name of the file to hash> ``
20+
21+
* Script will display avaliable hasing methods
22+
23+
* Enter hashing algorithm that you want to hash
24+
25+
* A file with name hash data.txt with hashed content will be saved in same directory
26+
27+
### Output file
28+
29+
![output](https://user-images.githubusercontent.com/48166328/96407352-cfc39980-11fe-11eb-989e-5fc5036e828b.png)

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)