File tree Expand file tree Collapse file tree 3 files changed +89
-0
lines changed Expand file tree Collapse file tree 3 files changed +89
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
1
+ hashlib
2
+ sys
You can’t perform that action at this time.
0 commit comments