-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecrypt.py
646 lines (534 loc) · 21.6 KB
/
Decrypt.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
import sys
from pathlib import Path
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
QHBoxLayout, QLineEdit, QPushButton, QProgressBar,
QTextEdit, QLabel, QFrame, QStatusBar, QFileDialog)
from PyQt6.QtCore import Qt, pyqtSignal, QTimer, QThread, pyqtProperty
from PyQt6.QtWidgets import *
from PyQt6.QtCore import *
from PyQt6.QtGui import QPainter, QColor, QLinearGradient, QPixmap
import PyPDF2
import random
import zipfile
import py7zr
import math
class FileDropArea(QFrame):
fileDropped = pyqtSignal(list)
def __init__(self):
super().__init__()
self.setAcceptDrops(True)
self.setStyleSheet("""
QFrame {
border: 3px dashed #3daee9;
border-radius: 12px;
background: rgba(29, 91, 121, 0.4);
min-height: 120px;
}
QFrame:hover {
border-color: #50fa7b;
background: rgba(29, 91, 121, 0.6);
}
""")
layout = QVBoxLayout()
self.label = QLabel("Drop files here or click to browse")
self.label.setStyleSheet("color: #8be9fd; font-size: 16px;")
layout.addWidget(self.label, alignment=Qt.AlignmentFlag.AlignCenter)
self.setLayout(layout)
def mousePressEvent(self, event):
super().mousePressEvent(event)
files, _ = QFileDialog.getOpenFileNames(
self,
"Select Files to Decrypt",
"",
"Encrypted Files (*.pdf *.zip *.7z)"
)
if files:
self.fileDropped.emit(files)
APP_STYLE = """
QMainWindow {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 rgba(26, 64, 89, 1),
stop:1 rgba(15, 37, 55, 1))
+ qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 rgba(0, 150, 255, 0.1),
stop:0.5 rgba(0, 211, 255, 0.2),
stop:1 rgba(0, 150, 255, 0.1));
}
/* Underwater rays effect */
#central_widget {
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 rgba(255, 255, 255, 0),
stop:0.3 rgba(255, 255, 255, 0.05),
stop:0.5 rgba(255, 255, 255, 0),
stop:0.7 rgba(255, 255, 255, 0.05),
stop:1 rgba(255, 255, 255, 0));
}
/* FIRST Robotics theme colors */
#header {
font-size: 28px;
font-weight: bold;
color: #50fa7b;
padding: 20px;
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 rgba(0, 103, 166, 0.8), /* FIRST Blue */
stop:0.5 rgba(237, 28, 36, 0.4), /* FIRST Red */
stop:1 rgba(0, 103, 166, 0.8));
border-radius: 10px;
border: 2px solid rgba(80, 250, 123, 0.5);
}
/* Enhanced drop zone with reef effect */
#dropZone {
border: 3px dashed #3daee9;
border-radius: 12px;
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 rgba(29, 91, 121, 0.4),
stop:0.5 rgba(41, 128, 185, 0.3),
stop:1 rgba(29, 91, 121, 0.4));
min-height: 120px;
}
#dropZone:hover {
border-color: #50fa7b;
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 rgba(29, 91, 121, 0.6),
stop:0.5 rgba(41, 128, 185, 0.5),
stop:1 rgba(29, 91, 121, 0.6));
}
/* Glowing buttons */
QPushButton {
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #2d7ba7,
stop:1 #205a7b);
border-radius: 8px;
padding: 12px;
color: white;
font-weight: bold;
font-size: 14px;
border: 1px solid #3daee9;
}
QPushButton:hover {
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 #3daee9,
stop:1 #2d7ba7);
border: 1px solid #50fa7b;
}
/* Enhanced progress bar */
QProgressBar {
border: 2px solid #3daee9;
border-radius: 5px;
text-align: center;
background-color: rgba(26, 63, 90, 0.4);
}
QProgressBar::chunk {
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop:0 #50fa7b,
stop:0.5 #3daee9,
stop:1 #50fa7b);
}
/* Glowing status bar */
QStatusBar {
color: #8be9fd;
padding: 8px;
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 rgba(0, 0, 0, 0.4),
stop:1 rgba(0, 0, 0, 0.2));
font-size: 14px;
border-top: 1px solid rgba(61, 174, 233, 0.5);
}
/* Log area with underwater effect */
QTextEdit {
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1,
stop:0 rgba(30, 30, 30, 0.9),
stop:1 rgba(30, 30, 30, 0.7));
color: #ffffff;
border: 1px solid #3daee9;
border-radius: 4px;
padding: 8px;
}
/* Password input styling */
QLineEdit {
background: rgba(30, 30, 30, 0.7);
border: 1px solid #3daee9;
border-radius: 4px;
color: #ffffff;
padding: 5px;
}
QLineEdit:focus {
border: 1px solid #50fa7b;
background: rgba(30, 30, 30, 0.9);
}
"""
class ReefscapeUI(QMainWindow):
def __init__(self):
super().__init__()
self.coral_chars = ['🐠', '🐟', '🐡', '🦈', '🐋', '🐳']
self.coral_index = 0
self.wave_offset = 0
self.files_to_process = []
self.init_ui()
def init_ui(self):
self.setWindowTitle('🌊 FIRST Robotics Competition - REEFSCAPE Decryptor')
self.setMinimumSize(1000, 700)
# Create central widget and main layout
self.background = BackgroundWidget(self)
self.background.setGeometry(self.rect())
self.background.lower()
# Make central widget transparent
central_widget = QWidget()
central_widget.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
self.setCentralWidget(central_widget)
main_layout = QVBoxLayout(central_widget)
# Apply the main stylesheet
self.setStyleSheet(APP_STYLE)
# Create header
header_label = QLabel("🌊 REEFSCAPE Decryptor")
header_label.setObjectName("header")
main_layout.addWidget(header_label)
# File Drop Area
self.drop_area = FileDropArea()
self.drop_area.setObjectName("dropZone")
self.drop_area.fileDropped.connect(self.handle_dropped_files)
main_layout.addWidget(self.drop_area)
password_frame = QFrame()
password_layout = QHBoxLayout(password_frame)
self.password_input = QLineEdit()
self.password_input.setPlaceholderText("Enter decryption password")
self.password_input.setEchoMode(QLineEdit.EchoMode.Password)
self.password_input.returnPressed.connect(self.start_decryption)
self.toggle_password_btn = QPushButton("👁")
self.toggle_password_btn.setFixedWidth(40)
self.toggle_password_btn.clicked.connect(self.toggle_password_visibility)
password_layout.addWidget(QLabel("Password:"))
password_layout.addWidget(self.password_input)
password_layout.addWidget(self.toggle_password_btn)
main_layout.addWidget(password_frame)
# Progress Section
self.progress_bar = QProgressBar()
self.progress_bar.setTextVisible(True)
self.progress_bar.setAlignment(Qt.AlignmentFlag.AlignCenter)
main_layout.addWidget(self.progress_bar)
# Log Area
self.log_area = QTextEdit()
self.log_area.setReadOnly(True)
self.log_area.setStyleSheet("""
QTextEdit {
background-color: #1e1e1e;
color: #ffffff;
border: 1px solid #333;
border-radius: 4px;
padding: 8px;
}
""")
main_layout.addWidget(self.log_area)
# Control Buttons
button_frame = QFrame()
button_layout = QHBoxLayout(button_frame)
self.decrypt_btn = QPushButton("🔓 Start Decryption")
self.decrypt_btn.setFixedSize(200, 50)
self.decrypt_btn.clicked.connect(self.start_decryption)
self.reset_btn = QPushButton("🔄 Reset")
self.reset_btn.setFixedSize(100, 50)
self.reset_btn.setEnabled(False)
self.reset_btn.clicked.connect(self.reset_process)
button_layout.addStretch()
button_layout.addWidget(self.decrypt_btn)
button_layout.addWidget(self.reset_btn)
button_layout.addStretch()
main_layout.addWidget(button_frame)
# Status Bar
self.status_bar = QStatusBar()
self.setStatusBar(self.status_bar)
self.status_bar.showMessage("Ready")
# Initialize animation timer
self.animation_timer = QTimer()
self.animation_timer.timeout.connect(self.update_animations)
self.animation_timer.start(150)
def handle_dropped_files(self, files):
self.log_message(f"Files added: {len(files)} files")
self.files_to_process = files
def toggle_password_visibility(self):
if self.password_input.echoMode() == QLineEdit.EchoMode.Password:
self.password_input.setEchoMode(QLineEdit.EchoMode.Normal)
self.toggle_password_btn.setText("🔒")
else:
self.password_input.setEchoMode(QLineEdit.EchoMode.Password)
self.toggle_password_btn.setText("👁")
def log_message(self, message, level="info"):
colors = {
"info": "#ffffff",
"success": "#50fa7b",
"error": "#ff5555"
}
self.log_area.append(f'<span style="color: {colors[level]}">{message}</span>')
def update_animations(self):
self.coral_index = (self.coral_index + 1) % len(self.coral_chars)
current_fish = self.coral_chars[self.coral_index]
waves = "~" * (5 + self.wave_offset) + "🌊" + "~" * (5 - self.wave_offset)
self.wave_offset = (self.wave_offset + 1) % 10
status_text = f"REEFSCAPE {waves} {current_fish} Ready for decryption"
self.status_bar.showMessage(status_text)
def start_decryption(self):
if not hasattr(self, 'files_to_process') or not self.files_to_process:
self.log_message("No files selected", "error")
return
if not self.password_input.text():
self.log_message("Please enter a password", "error")
return
self.decrypt_btn.setEnabled(False)
self.reset_btn.setEnabled(True)
self.progress_bar.setValue(0)
self.worker = DecryptWorker(self.files_to_process, self.password_input.text())
self.worker.progress.connect(self.progress_bar.setValue)
self.worker.status.connect(self.log_message)
self.worker.finished.connect(self.decryption_finished)
self.worker.start()
def decryption_finished(self, success):
self.decrypt_btn.setEnabled(True)
self.reset_btn.setEnabled(False)
if success:
self.log_message("Decryption completed successfully", "success")
else:
self.log_message("Decryption process failed", "error")
def reset_process(self):
if hasattr(self, 'worker') and self.worker.isRunning():
self.worker.stop()
self.worker.wait()
self.progress_bar.setValue(0)
self.password_input.clear()
self.files_to_process = []
self.log_message("Process reset", "info")
self.decrypt_btn.setEnabled(True)
self.reset_btn.setEnabled(False)
self.status_bar.showMessage("Ready")
class BackgroundWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setAttribute(Qt.WidgetAttribute.WA_StyledBackground)
self.setAttribute(Qt.WidgetAttribute.WA_OpaquePaintEvent)
self.buffer = None
self.bubbles = []
self._wave_offset = 0.0
self._ray_opacity = 0.2
self.first_blue = QColor(0, 103, 166, 100)
self.first_red = QColor(237, 28, 36, 80)
self.bubble_color = QColor(255, 255, 255, 100)
self.setupAnimations()
self.setMouseTracking(True)
self.update_timer = QTimer(self)
self.update_timer.timeout.connect(self.smoothUpdate)
self.update_timer.start(16)
@pyqtProperty(float)
def wave_offset(self):
return self._wave_offset
@wave_offset.setter
def wave_offset(self, value):
self._wave_offset = value
self.update()
@pyqtProperty(float)
def ray_opacity(self):
return self._ray_opacity
@ray_opacity.setter
def ray_opacity(self, value):
self._ray_opacity = value
self.update()
def setupAnimations(self):
self.wave_anim = QPropertyAnimation(self, b"wave_offset")
self.wave_anim.setDuration(8000) # Slower wave movement
self.wave_anim.setStartValue(0.0)
self.wave_anim.setEndValue(1.0)
self.wave_anim.setEasingCurve(QEasingCurve.Type.InOutSine)
self.wave_anim.setLoopCount(-1)
self.ray_anim = QPropertyAnimation(self, b"ray_opacity")
self.ray_anim.setDuration(10000) # Slower ray movement
self.ray_anim.setStartValue(0.2)
self.ray_anim.setEndValue(0.8)
self.ray_anim.setEasingCurve(QEasingCurve.Type.InOutSine)
self.ray_anim.setLoopCount(-1)
self.wave_anim.start()
self.ray_anim.start()
self.bubble_timer = QTimer(self)
self.bubble_timer.timeout.connect(self.updateBubbles)
self.bubble_timer.start(50) # Smoother bubble updates
def createBuffer(self):
pixelRatio = self.devicePixelRatio()
size = self.size()
bufferSize = size * pixelRatio
self.buffer = QPixmap(bufferSize)
self.buffer.setDevicePixelRatio(pixelRatio)
self.buffer.fill(Qt.GlobalColor.transparent)
def resizeEvent(self, event):
super().resizeEvent(event)
self.createBuffer()
if hasattr(self, 'bubbles') and event.oldSize().width() > 0:
scale_x = event.size().width() / event.oldSize().width()
scale_y = event.size().height() / event.oldSize().height()
for bubble in self.bubbles:
bubble['pos'] = QPointF(
bubble['pos'].x() * scale_x,
bubble['pos'].y() * scale_y
)
def smoothUpdate(self):
self.update()
def paintEvent(self, event):
if not self.buffer:
self.createBuffer()
buffer_painter = QPainter(self.buffer)
buffer_painter.setRenderHint(QPainter.RenderHint.Antialiasing)
buffer_painter.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
self.buffer.fill(Qt.GlobalColor.transparent)
buffer_painter.setCompositionMode(QPainter.CompositionMode.CompositionMode_SourceOver)
self.paintWaves(buffer_painter)
buffer_painter.setCompositionMode(QPainter.CompositionMode.CompositionMode_Screen)
self.paintRays(buffer_painter)
buffer_painter.setCompositionMode(QPainter.CompositionMode.CompositionMode_SourceOver)
self.paintBubbles(buffer_painter)
buffer_painter.end()
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
painter.drawPixmap(0, 0, self.buffer)
def paintWaves(self, painter):
width = self.width()
height = self.height()
wave_gradient = QLinearGradient(
width * self._wave_offset, 0,
width * (1 + self._wave_offset), height
)
wave_gradient.setColorAt(0.0, self.first_blue)
wave_gradient.setColorAt(0.5, self.first_red)
wave_gradient.setColorAt(1.0, self.first_blue)
painter.fillRect(self.rect(), wave_gradient)
def paintRays(self, painter):
"""Paint underwater light rays effect"""
width = self.width()
height = self.height()
for i in range(5):
ray_gradient = QLinearGradient(
width * (0.2 + i * 0.15), 0,
width * (0.3 + i * 0.15), height
)
ray_color = QColor(255, 255, 255, int(self._ray_opacity * 255 * 0.3))
ray_gradient.setColorAt(0.0, ray_color)
ray_gradient.setColorAt(1.0, QColor(255, 255, 255, 0))
painter.fillRect(0, 0, width, height, ray_gradient)
def paintBubbles(self, painter):
"""Paint animated bubbles"""
for bubble in self.bubbles:
painter.setPen(Qt.PenStyle.NoPen)
painter.setBrush(self.bubble_color)
painter.drawEllipse(bubble['pos'], bubble['size'], bubble['size'])
def updateBubbles(self):
width = self.width()
height = self.height()
if random.random() < 0.03:
size = random.randint(5, 15)
self.bubbles.append({
'pos': QPointF(random.randint(0, width), height + size),
'size': size,
'speed': random.uniform(0.3, 1.5)
})
for bubble in self.bubbles:
bubble['pos'].setY(bubble['pos'].y() - bubble['speed'])
bubble['pos'].setX(bubble['pos'].x() + math.sin(bubble['pos'].y() * 0.01) * 0.5)
self.bubbles = [b for b in self.bubbles if b['pos'].y() + b['size'] > 0]
if len(self.bubbles) > 30:
self.bubbles = self.bubbles[-30:]
self.update()
def cleanup(self):
self.wave_anim.stop()
self.bubble_timer.stop()
self.ray_anim.stop()
self.update_timer.stop()
self.buffer = None
class DecryptWorker(QThread):
progress = pyqtSignal(int)
status = pyqtSignal(str, str)
finished = pyqtSignal(bool)
def __init__(self, files, password):
super().__init__()
self.files = files
self.password = password
self.is_running = True
def process_file(self, file_path):
if not file_path.exists():
raise DecryptionError(f"File not found: {file_path}")
suffix = file_path.suffix.lower()
output_dir = file_path.parent / "decrypted"
output_dir.mkdir(exist_ok=True)
if suffix == '.pdf':
self._decrypt_pdf(file_path, output_dir)
elif suffix == '.zip':
self._decrypt_zip(file_path, output_dir)
elif suffix == '.7z':
self._decrypt_7z(file_path, output_dir)
else:
raise DecryptionError(f"Unsupported file type: {suffix}")
def _decrypt_pdf(self, file_path, output_dir):
try:
reader = PyPDF2.PdfReader(file_path)
if reader.is_encrypted:
if not reader.decrypt(self.password):
raise DecryptionError("Incorrect PDF password")
writer = PyPDF2.PdfWriter()
for page in reader.pages:
writer.add_page(page)
output_path = output_dir / f"decrypted_{file_path.name}"
with open(output_path, 'wb') as out_file:
writer.write(out_file)
except PyPDF2.errors.PdfReadError as e:
raise DecryptionError(f"PDF decryption failed: {str(e)}")
except Exception as e:
raise DecryptionError(f"Error processing PDF: {str(e)}")
def _decrypt_zip(self, file_path, output_dir):
try:
with zipfile.ZipFile(file_path) as zf:
try:
zf.extractall(path=output_dir, pwd=self.password.encode('utf-8'))
except RuntimeError:
raise DecryptionError("Incorrect ZIP password")
except UnicodeEncodeError:
raise DecryptionError("Invalid password encoding")
except zipfile.BadZipFile:
raise DecryptionError("Invalid or corrupted ZIP file")
except Exception as e:
raise DecryptionError(f"Error processing ZIP: {str(e)}")
def _decrypt_7z(self, file_path, output_dir):
try:
with py7zr.SevenZipFile(file_path, mode='r', password=self.password) as sz:
sz.extractall(output_dir)
except py7zr.Bad7zFile:
raise DecryptionError("Invalid or corrupted 7Z file")
except Exception as e:
raise DecryptionError(f"Error processing 7Z: {str(e)}")
def run(self):
try:
total_files = len(self.files)
success = True
for idx, file_path in enumerate(self.files, 1):
if not self.is_running:
break
progress = int((idx / total_files) * 100)
self.progress.emit(progress)
try:
self.process_file(Path(file_path))
self.status.emit(f"Successfully processed: {file_path}", "success")
except DecryptionError as e:
self.status.emit(str(e), "error")
success = False
except Exception as e:
self.status.emit(f"Unexpected error: {str(e)}", "error")
success = False
self.finished.emit(success)
except Exception as e:
self.status.emit(f"Process failed: {str(e)}", "error")
self.finished.emit(False)
def stop(self):
self.is_running = False
class DecryptionError(Exception):
"""Custom exception for decryption failures"""
pass
def main():
app = QApplication(sys.argv)
window = ReefscapeUI()
window.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()