File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Expand file tree Collapse file tree 3 files changed +72
-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
+
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 )
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**
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