-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCrypt.py
More file actions
3403 lines (2927 loc) · 122 KB
/
GCrypt.py
File metadata and controls
3403 lines (2927 loc) · 122 KB
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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# CODED BY D3F417
# GUARDIRAN SECURITY TEAM
# https://github.com/Sir-D3F417
# https://d3f417.info
# https://t.me/hex_aa
# https://guardiran.org
import os
import sys
import json
import hashlib
import base64
import zlib
import lzma
import bz2
import time
import random
import webbrowser
from datetime import datetime
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives.padding import PKCS7
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
from PyQt6.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QPushButton, QLabel, QLineEdit, QFileDialog, QMessageBox,
QDialog, QProgressBar, QComboBox, QSpinBox, QTextEdit,
QGroupBox, QRadioButton, QListWidget, QTableWidget,
QMenuBar, QMenu, QStatusBar, QCheckBox, QTableWidgetItem,
QHeaderView, QProgressDialog, QTabWidget
)
from PyQt6.QtCore import Qt, QThread, pyqtSignal
from PyQt6.QtGui import (
QFont, QPalette, QColor, QIcon,
QDragEnterEvent, QDropEvent, QDragMoveEvent
)
import logging
import tempfile
import psutil
import requests
import secrets
import string
ASCII_LOGO = """
═══════ GUARDIRAN SECURITY TOOLS ═══════
"""
STYLE_SHEET = """
/* Main Window */
QMainWindow {
background-color: #0a0b14;
}
/* Card Containers */
.card-container {
background-color: #12152d;
border: 2px solid #00ff9d;
border-radius: 10px;
padding: 20px;
margin: 10px;
}
/* Logo Container */
.logo-container {
background-color: #12152d;
border: 2px solid #00ff9d;
border-radius: 10px;
padding: 20px;
margin: 10px 10px 20px 10px;
}
/* Section Headers */
.section-header {
color: #00ff9d;
font-size: 16px;
font-weight: bold;
text-transform: uppercase;
padding: 5px 0;
}
/* Input Fields */
QLineEdit {
background-color: #0a0b14;
color: #ffffff;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 8px;
font-size: 13px;
}
QLineEdit:focus {
border-color: #00ff9d;
background-color: #12152d;
}
/* Buttons */
QPushButton {
background-color: transparent;
color: #00ff9d;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 8px 15px;
font-size: 13px;
font-weight: bold;
}
QPushButton:hover {
background-color: #00ff9d;
color: #0a0b14;
}
QPushButton:pressed {
background-color: #00cc7d;
}
/* Combo Boxes */
QComboBox {
background-color: #0a0b14;
color: #ffffff;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 8px;
font-size: 13px;
}
QComboBox:hover {
border-color: #00ff9d;
}
QComboBox::drop-down {
border: none;
width: 20px;
}
QComboBox::down-arrow {
image: url(assets/dropdown.png);
width: 12px;
height: 12px;
}
/* Checkboxes */
QCheckBox {
color: #ffffff;
spacing: 5px;
}
QCheckBox::indicator {
width: 18px;
height: 18px;
border: 2px solid #00ff9d;
border-radius: 3px;
background-color: #0a0b14;
}
QCheckBox::indicator:checked {
background-color: #00ff9d;
image: url(assets/checkmark.png);
}
/* Progress Bar */
QProgressBar {
border: 2px solid #00ff9d;
border-radius: 5px;
text-align: center;
color: #ffffff;
}
QProgressBar::chunk {
background-color: #00ff9d;
}
/* Labels */
QLabel {
color: #ffffff;
}
/* Title Bar */
#title-bar {
background-color: #12152d;
border-bottom: 2px solid #00ff9d;
}
.title-text {
color: #00ff9d;
font-size: 14px;
font-weight: bold;
}
.subtitle-text {
color: #00ff9d;
font-family: 'Consolas', monospace;
font-size: 12px;
}
"""
class EncryptionSettings:
ALGORITHMS = {
'AES-256-GCM': {'key_size': 32, 'mode': modes.GCM},
'AES-256-CBC': {'key_size': 32, 'mode': modes.CBC},
'AES-256-CFB': {'key_size': 32, 'mode': modes.CFB},
'AES-256-OFB': {'key_size': 32, 'mode': modes.OFB},
'ChaCha20-Poly1305': {'key_size': 32, 'mode': None},
'Camellia-256': {'key_size': 32, 'mode': modes.CBC}
}
COMPRESSION_METHODS = {
'None': None,
'ZLIB': {'module': zlib, 'compress': lambda d, l: zlib.compress(d, level=l),
'decompress': lambda d: zlib.decompress(d)},
'LZMA': {'module': lzma, 'compress': lambda d, l: lzma.compress(d, preset=l),
'decompress': lambda d: lzma.decompress(d)},
'BZ2': {'module': bz2, 'compress': lambda d, l: bz2.compress(d, compresslevel=l),
'decompress': lambda d: bz2.decompress(d)}
}
class SecureFileHandler:
def __init__(self):
self.cipher = None
self.key = None
def generate_key(self, password, salt=None):
if salt is None:
salt = os.urandom(32)
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend()
)
key = base64.b64encode(kdf.derive(password.encode()))
return key, salt
def encrypt_file(self, input_file, output_file, password, algorithm='AES-256-GCM',
compression_method='ZLIB', compression_level=6):
try:
key, salt = self.generate_key(password)
with open(input_file, 'rb') as f:
data = f.read()
if compression_method != 'None':
if compression_method == 'ZLIB':
data = zlib.compress(data, compression_level)
elif compression_method == 'LZMA':
data = lzma.compress(data, preset=compression_level)
elif compression_method == 'BZ2':
data = bz2.compress(data, compresslevel=compression_level)
nonce = os.urandom(12)
cipher = Cipher(
algorithms.AES(base64.b64decode(key)),
modes.GCM(nonce),
backend=default_backend()
)
encryptor = cipher.encryptor()
ciphertext = encryptor.update(data) + encryptor.finalize()
metadata = {
'algorithm': algorithm,
'compression': compression_method,
'salt': base64.b64encode(salt).decode('utf-8'),
'nonce': base64.b64encode(nonce).decode('utf-8'),
'tag': base64.b64encode(encryptor.tag).decode('utf-8')
}
with open(output_file, 'wb') as f:
f.write(json.dumps(metadata).encode() + b'\n')
f.write(ciphertext)
return True, "File encrypted successfully"
except Exception as e:
return False, f"Encryption failed: {str(e)}"
def decrypt_file(self, input_file, output_file, password):
try:
with open(input_file, 'rb') as f:
metadata_line = b''
while True:
byte = f.read(1)
if byte == b'\n':
break
metadata_line += byte
try:
metadata = json.loads(metadata_line.decode('utf-8'))
except json.JSONDecodeError:
return False, "Invalid file format or corrupted metadata"
ciphertext = f.read()
try:
salt = base64.b64decode(metadata['salt'])
nonce = base64.b64decode(metadata['nonce'])
tag = base64.b64decode(metadata['tag'])
except KeyError:
return False, "Missing required metadata fields"
except Exception:
return False, "Invalid metadata format"
key, _ = self.generate_key(password, salt)
try:
cipher = Cipher(
algorithms.AES(base64.b64decode(key)),
modes.GCM(nonce, tag),
backend=default_backend()
)
decryptor = cipher.decryptor()
data = decryptor.update(ciphertext) + decryptor.finalize()
if metadata.get('compression', 'None') != 'None':
try:
if metadata['compression'] == 'ZLIB':
data = zlib.decompress(data)
elif metadata['compression'] == 'LZMA':
data = lzma.decompress(data)
elif metadata['compression'] == 'BZ2':
data = bz2.decompress(data)
except Exception as e:
return False, f"Decompression failed: {str(e)}"
with open(output_file, 'wb') as f:
f.write(data)
return True, "File decrypted successfully"
except Exception as e:
return False, f"Decryption failed: {str(e)}"
except Exception as e:
return False, f"File reading failed: {str(e)}"
class CryptoWorker(QThread):
progress = pyqtSignal(int)
finished = pyqtSignal(bool, str)
def __init__(self, mode, input_file, output_file, password, algorithm, use_compression=False, compression_method=None):
super().__init__()
self.mode = mode
self.input_file = input_file
self.output_file = output_file
self.password = password
self.algorithm = algorithm
self.use_compression = use_compression
self.compression_method = compression_method
def run(self):
try:
with open(self.input_file, 'rb') as f:
data = f.read()
# Update progress
self.progress.emit(20)
# Compress if needed
if self.use_compression and self.mode == 'encrypt':
if self.compression_method == 'ZLIB':
data = zlib.compress(data)
elif self.compression_method == 'LZMA':
data = lzma.compress(data)
elif self.compression_method == 'BZIP2':
data = bz2.compress(data)
# Update progress
self.progress.emit(40)
# Process data based on mode
if self.mode == 'encrypt':
# Generate salt
salt = os.urandom(16)
# Derive key
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend()
)
key = kdf.derive(self.password.encode())
# Encrypt
cipher = Fernet(base64.urlsafe_b64encode(key))
encrypted_data = cipher.encrypt(data)
# Combine salt and encrypted data
final_data = salt + encrypted_data
else:
# Extract salt
salt = data[:16]
encrypted_data = data[16:]
# Derive key
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend()
)
key = kdf.derive(self.password.encode())
# Decrypt
cipher = Fernet(base64.urlsafe_b64encode(key))
final_data = cipher.decrypt(encrypted_data)
# Decompress if needed
if self.use_compression:
if self.compression_method == 'ZLIB':
final_data = zlib.decompress(final_data)
elif self.compression_method == 'LZMA':
final_data = lzma.decompress(final_data)
elif self.compression_method == 'BZIP2':
final_data = bz2.decompress(final_data)
# Update progress
self.progress.emit(80)
# Write output file
with open(self.output_file, 'wb') as f:
f.write(final_data)
# Complete
self.progress.emit(100)
self.finished.emit(True, "File processed successfully!")
except Exception as e:
self.finished.emit(False, str(e))
class AboutDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("About GCrypt")
self.setMinimumSize(600, 400)
self.setup_ui()
# Apply cyberpunk theme
self.setStyleSheet("""
QDialog {
background-color: #0a0b14;
border: 2px solid #00ff9d;
border-radius: 10px;
}
QLabel {
color: #ffffff;
font-size: 13px;
}
QLabel[class="title-label"] {
color: #00ff9d;
font-size: 24px;
font-weight: bold;
}
QLabel[class="section-label"] {
color: #00ff9d;
font-size: 16px;
font-weight: bold;
padding-top: 10px;
}
QPushButton {
background-color: transparent;
color: #00ff9d;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 8px 15px;
font-size: 13px;
}
QPushButton:hover {
background-color: #00ff9d;
color: #0a0b14;
}
QTextEdit {
background-color: #12152d;
color: #ffffff;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 8px;
}
""")
def setup_ui(self):
layout = QVBoxLayout(self)
layout.setSpacing(20)
layout.setContentsMargins(30, 30, 30, 30)
# Title and Version
title = QLabel("GCrypt")
title.setProperty("class", "title-label")
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(title)
version = QLabel("Version 1.0.0")
version.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(version)
# Description
desc = QTextEdit()
desc.setReadOnly(True)
desc.setMinimumHeight(150) # Increased height
desc.setHtml("""
<p style='color: #ffffff; margin: 10px;'>
GCrypt is a state-of-the-art file encryption tool developed by GuardIran Security Team.
It implements industry-standard encryption algorithms and compression methods to ensure
the highest level of security for your files.
</p>
<p style='color: #ffffff; margin: 10px;'>
This tool is part of the GuardIran Security Tools suite, designed to provide robust
security solutions for both personal and professional use.
</p>
""")
layout.addWidget(desc)
# Features
features_label = QLabel("Key Features")
features_label.setProperty("class", "section-label")
layout.addWidget(features_label)
features = QLabel("""
• Multiple encryption algorithms (AES-256-GCM, ChaCha20-Poly1305)
• Various compression methods (ZLIB, LZMA, BZ2)
• File integrity verification
• Password generator
• Hash checker
• File analyzer
• Secure file deletion
• Batch processing support
• Drag and drop support
• Command-line interface
""")
features.setWordWrap(True) # Enable word wrap
layout.addWidget(features)
# Links section
links_label = QLabel("Important Links")
links_label.setProperty("class", "section-label")
layout.addWidget(links_label)
# Use horizontal layout for links
links_layout = QHBoxLayout()
# Left column
left_links = QVBoxLayout()
website_link = QLabel("<a href='https://guardiran.org' style='color: #00ff9d;'>Official Website</a>")
website_link.setOpenExternalLinks(True)
docs_link = QLabel("<a href='https://t.me/d3f417ir' style='color: #00ff9d;'>Telegram Channel</a>")
docs_link.setOpenExternalLinks(True)
left_links.addWidget(website_link)
left_links.addWidget(docs_link)
# Right column
right_links = QVBoxLayout()
github_link = QLabel("<a href='https://github.com/Sir-D3F417/GCrypt' style='color: #00ff9d;'>GitHub Repository</a>")
github_link.setOpenExternalLinks(True)
issues_link = QLabel("<a href='https://github.com/Sir-D3F417/GCrypt/issues' style='color: #00ff9d;'>Report Issues</a>")
issues_link.setOpenExternalLinks(True)
right_links.addWidget(github_link)
right_links.addWidget(issues_link)
links_layout.addLayout(left_links)
links_layout.addLayout(right_links)
layout.addLayout(links_layout)
# Contact Information
contact_label = QLabel("Contact Information")
contact_label.setProperty("class", "section-label")
layout.addWidget(contact_label)
contact_info = QLabel("""
Email: info@d3f417.ir
Telegram: @hex_aa
Instagram: @theguardiran
""")
layout.addWidget(contact_info)
# License
license_label = QLabel("License")
license_label.setProperty("class", "section-label")
layout.addWidget(license_label)
license_text = QLabel("This software is released under the GNU General Public License v3.0")
license_text.setWordWrap(True)
layout.addWidget(license_text)
# Close button
close_btn = QPushButton("Close")
close_btn.clicked.connect(self.close)
layout.addWidget(close_btn, alignment=Qt.AlignmentFlag.AlignCenter)
# Set fixed width for the dialog
self.setFixedWidth(600)
def open_link(self, url):
webbrowser.open(url)
class PasswordGenerator(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Password Generator")
self.setMinimumSize(400, 350) # Adjusted size
layout = QVBoxLayout(self)
layout.setSpacing(15) # Increased spacing
layout.setContentsMargins(20, 20, 20, 20) # Added margins
# Generated Password Label
password_label = QLabel("Generated Password:")
password_label.setStyleSheet("color: #ffffff; font-size: 13px;")
layout.addWidget(password_label)
# Password display
self.password_display = QLineEdit()
self.password_display.setReadOnly(True)
self.password_display.setMinimumHeight(35) # Increased height
layout.addWidget(self.password_display)
# Options Group
options_group = QGroupBox("Options")
options_layout = QVBoxLayout()
options_layout.setSpacing(10) # Adjusted spacing
# Length with spinbox
length_layout = QHBoxLayout()
length_label = QLabel("Length:")
self.length_spin = QSpinBox()
self.length_spin.setRange(8, 64)
self.length_spin.setValue(16)
self.length_spin.setMinimumHeight(25) # Adjusted height
length_layout.addWidget(length_label)
length_layout.addWidget(self.length_spin)
options_layout.addLayout(length_layout)
# Character types
self.uppercase = QCheckBox("Uppercase (A-Z)")
self.uppercase.setChecked(True)
self.lowercase = QCheckBox("Lowercase (a-z)")
self.lowercase.setChecked(True)
self.numbers = QCheckBox("Numbers (0-9)")
self.numbers.setChecked(True)
self.special = QCheckBox("Special (!@#$%^&*)")
self.special.setChecked(True)
options_layout.addWidget(self.uppercase)
options_layout.addWidget(self.lowercase)
options_layout.addWidget(self.numbers)
options_layout.addWidget(self.special)
options_group.setLayout(options_layout)
layout.addWidget(options_group)
# Buttons
button_layout = QHBoxLayout()
button_layout.setSpacing(10) # Added spacing between buttons
generate_btn = QPushButton("Generate")
generate_btn.setMinimumHeight(35) # Increased height
generate_btn.clicked.connect(self.generate_password)
copy_btn = QPushButton("Copy")
copy_btn.setMinimumHeight(35) # Increased height
copy_btn.clicked.connect(self.copy_password)
button_layout.addWidget(generate_btn)
button_layout.addWidget(copy_btn)
layout.addLayout(button_layout)
# Apply the updated style
self.apply_style()
# Generate initial password
self.generate_password()
def apply_style(self):
self.setStyleSheet("""
QDialog {
background-color: #0a0b14;
color: #ffffff;
border: 2px solid #00ff9d;
border-radius: 5px;
}
QLabel {
color: #ffffff;
font-size: 13px;
}
QLineEdit {
background-color: #12152d;
color: #00ff9d;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 8px;
font-size: 13px;
selection-background-color: #00ff9d;
selection-color: #0a0b14;
}
QPushButton {
background-color: #0a0b14;
color: #00ff9d;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 8px 15px;
font-size: 13px;
min-width: 100px;
}
QPushButton:hover {
background-color: #00ff9d;
color: #0a0b14;
}
QGroupBox {
color: #00ff9d;
border: 2px solid #00ff9d;
border-radius: 5px;
margin-top: 1em;
padding: 15px;
font-size: 13px;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 10px;
padding: 0 5px;
color: #00ff9d;
}
QCheckBox {
color: #ffffff;
spacing: 8px;
font-size: 13px;
}
QCheckBox::indicator {
width: 18px;
height: 18px;
border: 2px solid #00ff9d;
border-radius: 3px;
background-color: #0a0b14;
}
QCheckBox::indicator:checked {
background-color: #00ff9d;
image: url(assets/checkmark.png);
}
QSpinBox {
background-color: #12152d;
color: #00ff9d;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 5px;
min-width: 80px;
}
QSpinBox::up-button, QSpinBox::down-button {
border: none;
background-color: #00ff9d;
color: #0a0b14;
width: 15px;
}
QSpinBox::up-button:hover, QSpinBox::down-button:hover {
background-color: #00cc7a;
}
""")
def generate_password(self):
length = self.length_spin.value()
chars = ''
if not any([self.uppercase.isChecked(), self.lowercase.isChecked(),
self.numbers.isChecked(), self.special.isChecked()]):
QMessageBox.warning(self, "Error", "Please select at least one character type!")
return
if self.uppercase.isChecked():
chars += string.ascii_uppercase
if self.lowercase.isChecked():
chars += string.ascii_lowercase
if self.numbers.isChecked():
chars += string.digits
if self.special.isChecked():
chars += "!@#$%^&*()_+-=[]{}|;:,.<>?"
while True:
password = ''.join(secrets.choice(chars) for _ in range(length))
# Verify password meets requirements
has_upper = any(c.isupper() for c in password)
has_lower = any(c.islower() for c in password)
has_digit = any(c.isdigit() for c in password)
has_special = any(c in "!@#$%^&*()_+-=[]{}|;:,.<>?" for c in password)
if ((not self.uppercase.isChecked() or has_upper) and
(not self.lowercase.isChecked() or has_lower) and
(not self.numbers.isChecked() or has_digit) and
(not self.special.isChecked() or has_special)):
break
self.password_display.setText(password)
def copy_password(self):
password = self.password_display.text()
if password:
clipboard = QApplication.clipboard()
clipboard.setText(password)
QMessageBox.information(self, "Success", "Password copied to clipboard!")
class HashChecker(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Hash Checker")
self.setMinimumSize(500, 400)
layout = QVBoxLayout(self)
# File selection
file_layout = QHBoxLayout()
self.file_path = QLineEdit()
self.file_path.setPlaceholderText("Select file to check")
browse_btn = QPushButton("Browse")
browse_btn.clicked.connect(self.browse_file)
file_layout.addWidget(self.file_path)
file_layout.addWidget(browse_btn)
layout.addWidget(QLabel("File:"))
layout.addLayout(file_layout)
# Hash type selection
hash_layout = QHBoxLayout()
self.hash_combo = QComboBox()
self.hash_combo.addItems(['MD5', 'SHA1', 'SHA256', 'SHA512'])
hash_layout.addWidget(QLabel("Hash Type:"))
hash_layout.addWidget(self.hash_combo)
layout.addLayout(hash_layout)
# Hash input
self.hash_input = QLineEdit()
self.hash_input.setPlaceholderText("Enter hash to verify")
layout.addWidget(QLabel("Expected Hash:"))
layout.addWidget(self.hash_input)
# Results
self.results = QTextEdit()
self.results.setReadOnly(True)
layout.addWidget(QLabel("Results:"))
layout.addWidget(self.results)
# Buttons
button_layout = QHBoxLayout()
calculate_btn = QPushButton("Calculate Hash")
calculate_btn.clicked.connect(self.calculate_hash)
verify_btn = QPushButton("Verify Hash")
verify_btn.clicked.connect(self.verify_hash)
button_layout.addWidget(calculate_btn)
button_layout.addWidget(verify_btn)
layout.addLayout(button_layout)
self.apply_style()
def apply_style(self):
self.setStyleSheet("""
QDialog {
background-color: #0a0b14;
color: #ffffff;
}
QLabel {
color: #ffffff;
font-size: 13px;
}
QLineEdit {
background-color: #12152d;
color: #ffffff;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 8px;
font-size: 13px;
}
QTextEdit {
background-color: #12152d;
color: #00ff9d;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 10px;
font-family: 'Courier New', monospace;
}
QPushButton {
background-color: transparent;
color: #00ff9d;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 8px 15px;
font-size: 13px;
}
QPushButton:hover {
background-color: #00ff9d;
color: #0a0b14;
}
QComboBox {
background-color: #12152d;
color: #ffffff;
border: 2px solid #00ff9d;
border-radius: 5px;
padding: 5px;
}
QComboBox::drop-down {
border: none;
}
QComboBox::down-arrow {
image: url(assets/down_arrow.png);
width: 12px;
height: 12px;
}
""")
def browse_file(self):
file_path, _ = QFileDialog.getOpenFileName(self, "Select File")
if file_path:
self.file_path.setText(file_path)
def calculate_hash(self):
file_path = self.file_path.text()
if not file_path:
QMessageBox.warning(self, "Error", "Please select a file!")
return
try:
hash_type = self.hash_combo.currentText().lower()
hasher = getattr(hashlib, hash_type)()
with open(file_path, 'rb') as f:
while chunk := f.read(8192):
hasher.update(chunk)
hash_value = hasher.hexdigest()
self.results.setPlainText(f"File: {os.path.basename(file_path)}\n"
f"Hash Type: {hash_type.upper()}\n"
f"Hash: {hash_value}")
# Copy hash to clipboard
clipboard = QApplication.clipboard()
clipboard.setText(hash_value)
except Exception as e:
QMessageBox.critical(self, "Error", f"Hash calculation failed: {str(e)}")
def verify_hash(self):
file_path = self.file_path.text()
expected_hash = self.hash_input.text().lower()
if not file_path:
QMessageBox.warning(self, "Error", "Please select a file!")
return
if not expected_hash:
QMessageBox.warning(self, "Error", "Please enter the expected hash!")
return
try:
hash_type = self.hash_combo.currentText().lower()
hasher = getattr(hashlib, hash_type)()
with open(file_path, 'rb') as f:
while chunk := f.read(8192):
hasher.update(chunk)
calculated_hash = hasher.hexdigest()
if calculated_hash == expected_hash:
self.results.setPlainText("✅ Hash verification successful!\n\n"
f"File: {os.path.basename(file_path)}\n"
f"Hash Type: {hash_type.upper()}\n"
f"Calculated Hash: {calculated_hash}\n"
f"Expected Hash: {expected_hash}")
self.results.setStyleSheet("color: #00ff9d;")
else:
self.results.setPlainText("❌ Hash verification failed!\n\n"
f"File: {os.path.basename(file_path)}\n"
f"Hash Type: {hash_type.upper()}\n"
f"Calculated Hash: {calculated_hash}\n"
f"Expected Hash: {expected_hash}")
self.results.setStyleSheet("color: #ff4444;")
except Exception as e:
QMessageBox.critical(self, "Error", f"Hash verification failed: {str(e)}")
class FileAnalyzer(QDialog):