-
Notifications
You must be signed in to change notification settings - Fork 0
/
lockdown.py
193 lines (144 loc) · 4.31 KB
/
lockdown.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import encrypt as e
import geocoder as g
import threading, time, os, socket
from getpass import getpass
import sys
import socket, traceback
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
sys.argv.pop(0)
def pad(str, length):
while len(str) < length:
str = '0' + str
return str
def sithex(str):
return pad(hex(int(str))[2:],2)
hostname = socket.gethostname()
IPAddr = socket.gethostbyname(hostname)
key = "".join(list(map(sithex, IPAddr.split('.'))))
try:
os.system("clear")
except:
os.system("cls")
msg = ""
longitude = ""
latitude = ""
wrong = False
password = getpass()
def connect():
global longitude, latitude, wrong
'''
client, addr = s.accept()
print(f"Connection from {addr} has been established")
'''
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('',17388))
msg_size = s.recv(3)
msg_size = int(msg_size.decode('utf-8'))
msg = s.recv(msg_size).decode('utf-8')
p = msg.split('/')[0]
k = int(float(msg.split('/')[3]))
try:
for i in range(len(p)):
if ord(p[i])^k != ord(password[i]):
#if p[i] != password[i]
print("Password does not match\nExiting now")
wrong = True
return
except:
print("Password does not match\nExiting now")
wrong = True
exit(-1)
longitude = float(msg.split('/')[1])
latitude = float(msg.split('/')[2])
def waiting():
c = [f"connecting\tKEY={key}\r",f"connecting.\tKEY={key}\r",f"connecting..\tKEY={key}\r",f"connecting...\tKEY={key}\r"]
while t.is_alive():
for i in c:
if not t.is_alive():
break
print(i, end = "")
time.sleep(.5)
if wrong == True:
exit(-1)
else:
try:
os.system("clear")
except:
os.system("cls")
'''
print("connecting", end="")
if t.isAlive():
time.sleep(.5)
print(".",end="")
else:
break
if t.isAlive():
time.sleep(.5)
print(".", end="")
else:
break
if t.isAlive():
time.sleep(.5)
print(".", end="")
else:
break
time.sleep(.5)
print()
'''
time.sleep(.5)
if wrong == True:
exit(-1)
else:
try:
os.system("clear")
except:
os.system("cls")
t = threading.Thread(target = connect, name = "connect")
t2 = threading.Thread(target = waiting, name = "wait")
def main():
msg = ""
try:
client = None
addr = ""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('',17389))
t.start()
t2.start()
#print("connecting".upper())
t.join()
t2.join()
if wrong == True:
return
if len(sys.argv) == 0:
# file_name = input("file name:\n>\t")
file_name = filedialog.askopenfilename()
arg = False
with open(file_name, encoding="utf-8", errors='ignore') as f:
msg = e.encrypt(longitude, latitude, f.read())
option = input("(E)ncrypt or (D)ecrypt:\n>\t")
if option.upper() == 'D':
file_name = file_name[:file_name.index('.')]+'_decrypted' + file_name[file_name.index('.'):]
with open(file_name, 'w') as f:
f.write(msg)
else:
option = input("(E)ncrypt or (D)ecrypt:\n>\t")
while len(sys.argv) > 0:
file_name = sys.argv.pop(0)
with open(file_name, encoding="utf-8", errors='ignore') as f:
for line in f:
msg += e.encrypt(longitude, latitude, line)
if option.upper() == 'D':
file_name = file_name[:file_name.index('.')]+'_decrypted' + file_name[file_name.index('.'):]
with open(file_name, 'w') as f:
f.write(msg)
except Exception as err:
try:
os.system("clear")
except:
os.system("cls")
traceback.print_exc()
print("ERROR\nExiting now")
main()