-
Notifications
You must be signed in to change notification settings - Fork 0
/
safe.py
69 lines (60 loc) · 1.87 KB
/
safe.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
import sqlite3 as sql
import random
conn = sql.connect('files.db')
PASSWORD = "password"
try:
conn.execute("""CREATE TABLE files
(ID INT NOT NULL,
VALUE BLOB NOT NULL,
TYPE TEXT NOT NULL
)
""")
except:
pass
cursor = conn.cursor()
def get_extension(path):
ext = ""
for i in range(len(path) -1 , -1, -1):
if not path[i] == ".":
ext = path[i] + ext
else:
break
return ext
def write_files(path):
with open(path, 'rb') as file:
binary_data = file.read()
data_tuple = (random.randint(10000, 99999), binary_data.strip(), get_extension(path))
blob_query = f"""INSERT INTO files (ID, VALUE, TYPE) VALUES (?, ?, ?)"""
cursor.execute(blob_query, data_tuple)
def retrieve_files():
m = cursor.execute("""SELECT * FROM files """)
for x in m:
data = x[1]
with open(str(random.randint(1, 100000)) + "." + x[2], 'wb') as file:
file.write(data)
count = 0
while True:
password = input("Please enter the password:\n>")
if(password == PASSWORD and count <= 3):
print("________________________________")
store = input("Do you want to store files?(y/n)\n>")
if store == "y":
path = input("\nPaste the absolute path of the file you want to store:\n>")
write_files(path)
break
elif store == "n":
retrieve = input("Would you like to retrieve files?(y/n)\n>")
if retrieve == "y":
retrieve_files()
break
elif retrieve == "n":
print("Well, that's all I can do for you.")
break
else:
print("Please enter one of the listed options 'y' or 'n'")
elif count > 3:
print("Security check failed.")
break
else:
count+=1
conn.commit()