-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeltacode.py
More file actions
780 lines (714 loc) · 32 KB
/
Copy pathDeltacode.py
File metadata and controls
780 lines (714 loc) · 32 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
# TEAM DELTA / DELTA's TEAM
# By daisseur, discord : daisseur#7755
import os
import string as s
import time
import sys
import shutil
from unidecode import unidecode
def chercher(txt, premier, deuxieme):
if deuxieme == "'":
deuxieme = "' "
result = (txt[txt.find(premier): txt.find(deuxieme)])
if result == "":
result = "#La chaîne de caractères n'a pas été trouvée#"
result = str(result)
if not result.startswith(deuxieme, 18) and result != "#La chaîne de caractères n'a pas été trouvée#":
result = result + deuxieme
return result
def no_accent_char(char):
return unidecode(char)
def print_color(string, color='white', effect='classic', highlight='False') -> None:
nocolor = "\033[0;0m"
colors = {
'black': '0;',
'red': '1;',
'green': '2;',
'yellow': '3;',
'blue': '4;',
'violet': '5;',
'cyan': '6;',
'grey': '7;',
'white': '9;'}
effects = {
'bold': '1m',
'classic': '2m',
'italic': '3m',
'underline': '4m',
'strike': '9m'}
highlights = {
'False': '\033[3',
'True': '\033[4'}
print(highlights[highlight] + colors[color] + effects[effect] + str(string) + nocolor)
class Cesar:
def __init__(self, rot, string: str):
self.lower = s.ascii_lowercase
self.upper = s.ascii_uppercase
self.rot = rot
self.string = string
def encode(self):
if not isinstance(self.rot, int):
try:
self.rot = int(self.rot)
except:
return "ERREUR: La rotation doit être un nombre /!\\"
if self.rot > 26:
return "ERREUR: La rotation ne doit pas dépasser 26"
result = str()
for i in range(len(self.string)):
char = no_accent_char(char=self.string[i])
try:
if char in self.lower:
result += self.lower[self.lower.index(char) + self.rot % 26]
elif char in self.upper:
result += self.upper[self.upper.index(char) + self.rot % 26]
else:
result += char
except:
if char in self.lower:
result += f"[ERROR string:'{self.lower.index(char)}', rot:'{self.rot}']"
elif char in self.upper:
result += f"[ERROR string:'{self.upper.index(char)}', rot:'{self.rot}']"
return result
def decode(self):
if not isinstance(self.rot, int):
try:
self.rot = int(self.rot)
except:
return "ERROR: La rotation doit être un nombre /!\\"
if self.rot > 26:
return "ERREUR: La rotation ne doit pas dépasser 26"
result = str()
for i in range(len(self.string)):
char = no_accent_char(char=self.string[i])
if char in self.lower:
result += self.lower[self.lower.index(char) - self.rot % 26]
elif char in self.upper:
result += self.upper[self.upper.index(char) - self.rot % 26]
else:
result += char
return result
class ROT:
def __init__(self, password: str, string: str, error_input=False):
self.result = str()
self.password = password
self.string = string
self.password_len = len(password)
self.error_input = error_input
def error(self, error, fatal_error="[FATAL ERROR]"):
try:
if self.error_input:
self.result += error
else:
print_color(error, color='red', effect='underline')
except:
if self.error_input:
self.result += fatal_error
else:
print_color(fatal_error, color='red', effect='underline', highlight='True')
def encode(self):
for i in range(len(self.string)):
char = self.string[i]
try:
if char not in s.printable:
char = no_accent_char(char=char)
if char not in s.printable:
char = "?"
self.result += s.printable[
(s.printable.index(char) + s.printable.index(self.password[i % self.password_len])) % len(s.printable)]
except:
self.error(f"[ERROR string:'{s.printable.index(char)}', password:'{self.password[i % self.password_len]}']", fatal_error=f"[FATAL ERROR: '{char}']")
return self.result
def decode(self):
for i in range(len(self.string)):
char = self.string[i]
try:
if char not in s.printable:
char = no_accent_char(char=char)
self.result += s.printable[(s.printable.index(char) - s.printable.index(self.password[i % self.password_len]))]
except:
self.error(f"[ERROR string:'{s.printable.index(char)}', password:'{self.password[i % self.password_len]}']", fatal_error=f"[FATAL ERROR: '{char}']")
return self.result
class PersoEncoding:
def __init__(self, password: str, string, shift: int, spe_line: str | list, hexa=True, debug=False, error_input=True, type_return=str):
pass
class DayEncoding:
def __init__(self, password: str, string: str | list | tuple, shift: int, hexa=True, debug=False, error_input=True, type_return=str):
self.result = str()
self.password_len = len(password)
self.string = string
self.password = password
self.shift = shift
self.type_return = type_return
if hexa:
self.hexa = True
else:
self.hexa = False
self.debug_var = debug
self.error_input = error_input
self.debug(f"DayEncoding vient d'être appelée, result = {type(self.result)} = {self.result}")
self.debug(hexa)
if not isinstance(shift, int):
try:
self.shift = int(shift)
except:
self.error("ERREUR: le shift doit être un nombre /!\\",)
return
if shift > 1114111:
self.error("ERREUR: le shift ne doit pas dépasser 1114111")
return
type_authorized = [str, tuple, list, 'hex']
if type_return not in type_authorized:
self.error("ERREUR: les types autorisés sont: str, tuple, list et 'hex'")
return
def return_(self, string):
to_return = None
if self.type_return is str:
to_return = str()
if isinstance(string, list) or isinstance(string, tuple):
for i in string:
to_return += i
else:
to_return = str(string)
elif self.type_return is tuple:
to_return = tuple()
if isinstance(string, list) or isinstance(string, tuple):
for i in string:
to_return += (i,)
else:
to_return = str(string)
elif self.type_return is list or self.type_return == "hex":
to_return = list()
if isinstance(string, list) or isinstance(string, tuple):
for i in string:
to_return.append(i)
else:
to_return = str(string)
self.debug(self.type_return)
return to_return
def add_instance(self, to_be_add, string: str):
string = str(string)
self.debug(f"Adding instance... {type(to_be_add)} + {string}")
if isinstance(to_be_add, list):
to_be_add.append(string)
self.debug("added")
if isinstance(to_be_add, tuple):
to_be_add += (string,)
self.debug("added")
if isinstance(to_be_add, str):
to_be_add += string
self.debug("added")
return to_be_add
def error(self, error, fatal_error="[FATAL ERROR]"):
try:
if self.error_input:
self.result = self.add_instance(self.result, error)
else:
print_color(error, color='red', effect='underline')
except Exception:
if self.error_input:
self.result = self.add_instance(self.result, fatal_error)
else:
print_color(fatal_error, color='red', effect='underline', highlight='True')
if self.debug_var:
raise Exception
def debug(self, debug_message):
if self.debug_var:
print_color(debug_message, color='green', effect='bold')
time.sleep(0.005)
def encode(self):
self.string = self.string
for i in range(len(self.string)):
char = self.string[i]
for car in char:
try:
if self.hexa:
self.debug("hexa")
self.result = tuple(self.result)
encoding = hex((ord(car) + ord(self.password[i % self.password_len])) + self.shift % 1114111)
self.debug(f"'{car}' / {hex(ord(car))} == '{chr((ord(car) + ord(self.password[i % self.password_len])) + self.shift % 1114111)}' / {encoding}")
else:
self.debug("normal")
encoding = chr((ord(car) + ord(self.password[i % self.password_len])) + self.shift % 1114111)
self.debug(encoding)
self.result = self.add_instance(self.result, encoding)
except:
self.error(f"[ERROR string:'{car}', password:'{self.password[i % self.password_len]}']", fatal_error=f"[FATAL ERROR '{car}']")
return self.return_(self.result)
def decode(self):
# Résultat en valeurs hexadecimales
# self.result = str()
self.debug(f"string = {self.string}")
if self.hexa:
self.debug("hexa")
to_tuple = list()
if isinstance(self.string, str):
for hexa in self.string[2:].split('0x'):
to_tuple.append('0x' + hexa)
elif isinstance(self.string, tuple) or isinstance(self.string, list):
to_tuple = self.string
try:
string = tuple(to_tuple)
except:
self.error("Une erreur s'est produite lors de la préparation au décodage")
else:
nbr = 0
self.debug(string)
for i in string:
letter_ord = int(i, 16)
self.result = self.add_instance(self.result, chr((letter_ord - ord(self.password[nbr % self.password_len]) - self.shift) % 1114111))
self.debug(f"'{chr(int(i, 16))}' / {i} == '{self.result[-1]}' / {hex((letter_ord - self.shift) % 1114111)}\n{self.result}")
nbr += 1
return self.return_(self.result)
else:
for i in range(len(self.string)):
char = self.string[i]
try:
self.result += chr((ord(char) - ord(self.password[i % self.password_len])) - self.shift)
except:
self.error(f"[ERROR, string:'{char}', password:'{self.password[i % self.password_len]}']", fatal_error=f"[FATAL ERROR '{char}']")
return self.return_(self.result)
class Deltacode:
""" \\\ DELTA-ENCODING //
To decode or encode a text/string with rotation using all the existing characters.
Pour encoder ou décoder un texte ou une chaîne de caractères avec une rotation utilisant tous les caractères existants.
Example\\Exemple :
"""
# Ce serait bien de faire que pour chaque encodage on mette une classe comme ça : Deltacode(DayEncoding, Cesar) et
# Deltacode s'adapterait.
def __init__(self):
self.use_copy = True
self.valid_char = s.printable
self.status = "in __init__"
self.center_y = int(chercher(str(shutil.get_terminal_size()), "columns=", ",").replace("columns=", '').replace(",", ''))
self.banner = ' \\\ DELTACODE // '
self.password_running = "None"
self.text_running = "None"
self.shift_running = 0
if os.path.exists("historique.txt"):
with open("historique.txt", 'r', encoding='UTF-8') as f: self.history = f.read()
else: self.history = "\n"
if os.name == "posix": self.OS = "LINUX"
elif os.name == "nt": self.OS = "WINDOWS"
def copy(self, txt):
if self.use_copy is True:
if os.name == "posix":
os.system(f"echo '{str(txt)}' | xclip")
else:
from clipboard import copy
copy(txt)
else:
return
def clear(self, effect='italic', color='blue'):
if self.OS == "LINUX":
os.system("clear")
elif self.OS == "WINDOWS":
os.system("cls")
print_color(self.banner.center(self.center_y, ' '), color='green', effect='bold')
print_color(f"OS: {self.OS}".center(self.center_y, ' '), color='violet', effect='bold')
print_color(self.history, color=color, effect=effect)
def curly(self, string: str):
return '{' + string + '}'
def add_history(self, Password, Text, coding, decode_encode: str, shift="None"):
if shift != "None":
shift_insert = self.curly(f"Shift = {shift}") + "\n"
else:
shift_insert = ''
if decode_encode == "encode":
self.history += f"==ENCODE==\n{shift_insert}{self.curly(f'Password = {Password}')}\n{self.curly(f'Texte = {Text}')}\n|--> {coding}\n"
elif decode_encode == "decode":
self.history += f"==DECODE==\n{shift_insert}{self.curly(f'Password = {Password}')}\n{self.curly(f'Texte = {Text}')}\n|--> {coding}\n"
def input_coding(self, coding_function, decode_encode: str, shift=False, password=True, warning="None", from_file=False, **kwargs):
def input_return():
if shift:
if from_file:
return {"Password": Password,
"Text": Text,
"Encoded": coding,
"Shift": Shift,
"Filename": filename,
"Hexa": hexa}
return {"Password": Password,
"Text": Text,
"Encoded": coding,
"Shift": Shift,
"Hexa": hexa}
else:
if from_file:
return {"Password": Password,
"Text": Text,
"Encoded": coding,
"Filename": filename,
"Hexa": hexa}
return {"Password": Password,
"Text": Text,
"Encoded": coding,
"Hexa": hexa}
if "hexa" in kwargs.keys():
hexa = kwargs.fromkeys("hexa")
else:
hexa = None
kwargs["hexa"] = None
self.clear()
if warning != "None":
print_color(warning, color='yellow', effect='underline')
self.copy(str(self.password_running))
if hexa:
hexa = input("Voulez-vous utiliser l'encodage hexadecimal ? ")
if hexa.lower() == "oui":
hexa = True
else:
hexa = False
if password:
Password = input('Mot de passe : ')
else:
Password = input("Nombre de rotation à effectuer : ")
self.copy(str(self.text_running))
if from_file:
while True:
filename = input('Nom du fichier : ')
if os.path.exists(filename):
with open(filename, 'r', encoding='UTF-8') as f:
Text = f.read()
break
else:
file = input(f"Voulez-vous {decode_encode}r à partir d'un fichier ? ")
if file.lower() == "oui":
from_file = True
while True:
filename = input('Nom du fichier : ')
if os.path.exists(filename):
with open(filename, 'r', encoding='UTF-8') as f:
Text = f.read()
break
else:
from_file = False
Text = input('Texte : ')
if shift:
Shift = input("Utiliser le shift ? ")
if Shift.lower() == "oui":
while True:
self.copy(str(self.shift_running))
Shift = input('Shift : ')
try:
Shift = int(Shift)
except:
print_color("/!\ Veuillez rentrer un nombre", color="red", effect="bold")
else:
break
if self.status == 'encode':
coding = coding_function(Password, Text, Shift, hexa=hexa).encode()
else:
coding = coding_function(Password, Text, Shift, hexa=hexa).decode()
print_color(coding, color='blue')
self.add_history(Password, Text, coding, decode_encode, shift=str(Shift))
self.text_running = coding
self.password_running = Password
self.shift_running = Shift
return input_return()
else:
Shift = 0
if self.status == 'encode':
coding = coding_function(Password, Text, Shift, hexa=hexa).encode()
else:
coding = coding_function(Password, Text, Shift, hexa=hexa).decode()
self.add_history(Password, Text, coding, decode_encode, shift=str(Shift))
self.shift_running = Shift
return input_return()
else:
if decode_encode == "encode":
coding = coding_function(Password, Text).encode()
else:
coding = coding_function(Password, Text).decode()
print_color(coding, color='blue')
self.add_history(Password, Text, coding, decode_encode)
self.text_running = coding
self.password_running = Password
return input_return()
def create_menu(self, tab: int, lst: list, encadr="│", centery: int = None):
if not centery:
centery = self.center_y
# print(centery)
menu_tab = "\t" * tab + encadr
end = encadr
menu = """"""
len_max = 0
number = 0
before = 4
for i in lst:
if len(i) > len_max:
len_max = len(i) + 4
calcul = tab*6 + 2*len(end) + len_max + len(str(len(lst))) + 3
# print(calcul)
if calcul > centery or (calcul + tab*6) > centery:
menu_tab = (centery - calcul) * " " + end
new_calcul = len(menu_tab) + 2*len(end) + len_max + len(str(len(lst))) + 3
if new_calcul > centery:
menu_tab = end
if new_calcul - 2*len(end) > centery:
end = ''
menu_tab = ''
# print("RESPONSIVE", self.center_y, "\n" + "-" * self.center_y, calcul)
# menu_tab = menu_tab.replace(" ", "\t")
menu_entry = menu_tab[:-1] + " "
else:
menu_entry = (tab * "\t")[:-1] + 4 * ' '
menu += f"{menu_tab}{'—' * len_max}{end}\n"
for i in lst:
if i == '':
end_tab = (len_max - len(i)) * ' ' + end
menu += f"{menu_tab}{end_tab}\n"
elif i == ' ':
end_tab = (len_max - len(i) - 2) * ' ' + end
menu += f"{menu_tab}[ ]{end_tab}\n"
number += 1
else:
number += 1
before = len(str(number)) + 3
end_tab = (len_max - len(i) - before) * ' ' + end
menu += f"{menu_tab}[{number}] {i}{end_tab}\n"
menu += f"{menu_tab}{'—'*len_max}{end}\n\n{menu_entry}>> "
return menu
class main(Deltacode):
def __init__(self, copy=None):
super().__init__()
sys.tracebacklimit = 0
if copy is None:
self.use_copy = input("Voulez-vous utiliser la fonction copier ? Elle vous aidera à copier vos mots de passe, et texte déjà encodés directement quand vous en aurez besoin.\n")
if self.use_copy.lower() == "oui":
self.use_copy = True
else:
self.use_copy = False
elif copy:
self.use_copy = True
elif copy is False:
self.use_copy = False
def choice_encoding(self):
"""
Choice to encoding
Choix pour encoder
"""
self.banner += "- ENCODE"
self.clear()
self.status = "encode"
choice_encode = input(self.create_menu(2, ["Code Cesar",
"Rotation avec caractères affichables",
"Rotation avec tous les caractères existants",
"Test infaillible"]))
if choice_encode == "1":
self.input_coding(Cesar, decode_encode=self.status, password=False)
elif choice_encode == "2":
self.input_coding(ROT, decode_encode=self.status,
warning="/!\ S'il y a une lettre avec un accent dans le texte à encoder ou \
dans le password, la lettre sera transformée pour qu'il n'y ait pas d'accent (à -> a)")
elif choice_encode == "3":
self.input_coding(DayEncoding, decode_encode=self.status, shift=True, hexa=True)
elif choice_encode == "4":
print("Développement en cours...")
else:
print_color('Invalid choice', color='red', effect='bold')
def choice_decoding(self, return_choice=False):
"""
Choice to decoding
Choix pour decoder
"""
self.banner += "- DECODE"
self.clear()
self.status = "decode"
choice_decode = input(self.create_menu(2, ["Code Cesar",
"Rotation avec caractères affichables",
"Rotation avec tous les caractères existants",
"Test infaillible"]))
if return_choice:
return choice_decode
if choice_decode == "1":
self.input_coding(Cesar, decode_encode=self.status, password=False)
elif choice_decode == "2":
self.input_coding(ROT, decode_encode=self.status)
elif choice_decode == "3":
self.input_coding(DayEncoding, decode_encode=self.status, shift=True, hexa=True)
elif choice_decode == "4":
print("Développement en cours...")
else:
print_color('Invalid choice', color='red', effect='bold')
def encoding_decoding(self, choice_code="0"):
"""
To encode and decode with the encoding that has been chosen
Pour encoder et décoder avec l'encodage qui a été choisi
"""
self.banner += "- ENCODE & DECODE"
self.clear()
self.status = "encode"
if choice_code == "0":
choice_code = input(self.create_menu(2, ["Code Cesar",
"Rotation avec caractères affichables",
"Rotation avec tous les caractères existants",
"Test infaillible"]))
if choice_code == "1":
info = self.input_coding(Cesar, decode_encode=self.status, password=False).copy()
try:
Password = info["Password"]
Text = info["Encoded"]
self.status = "decode"
coding = Cesar(rot=Password, string=Text).decode()
print_color(coding, color='blue')
self.history += f"==DECODE==\n{self.curly(f'Password = {Password}')}\n{self.curly(f'Texte = {Text}')}\n|--> {coding}\n"
except:
print("KEY ERROR")
elif choice_code == "2":
info = self.input_coding(ROT, decode_encode=self.status).copy()
try:
Password = info["Password"]
Text = info["Encoded"]
coding = ROT(Password, Text).decode()
print_color(coding, color='blue')
self.history += f"==DECODE==\n{self.curly(f'Rotation = {Password}')}\n{self.curly(f'Texte = {Text}')}\n|--> {coding}\n"
except:
print("KEY ERROR")
elif choice_code == "3":
info = self.input_coding(DayEncoding, decode_encode=self.status, shift=True, hexa=True).copy()
try:
Password = info["Password"]
Text = info["Encoded"]
Shift = info["Shift"]
Hexa = info["Hexa"]
self.status = "decode"
coding = DayEncoding(Password, Text, Shift, hexa=Hexa).decode()
print_color(coding, color='blue')
self.history += f"==DECODE==\n{self.curly(f'Shift = {Shift}')}\n{self.curly(f'Password = {Password}')}\n{self.curly(f'Texte = {Text}')}\n|--> {coding}\n"
except:
print("KEY ERROR")
elif choice_code == "4":
print("Développement en cours...")
else:
print_color('Invalid choice', color='red', effect='bold')
def encode_decode_file(self):
self.clear()
def replace_file(filename: str, update: str):
with open(filename, 'w') as file:
update = str(update)
file.write(update)
while True:
encode_decode = input("Encoder ou decoder votre fichier ? ")
if encode_decode.lower() == "encoder" or encode_decode.lower() == "decoder":
encode_decode = encode_decode[:-1]
self.banner += f"- {encode_decode.upper()}"
self.clear()
self.status = encode_decode
choice_decode = input(self.create_menu(2, ["Code Cesar",
"Rotation avec caractères affichables",
"Rotation avec tous les caractères existants",
"Test infaillible"]))
if choice_decode == "1":
info = self.input_coding(Cesar, decode_encode=self.status, password=False, from_file=True).copy()
update = info["Encoded"]
filename = info["Filename"]
replace_file(filename, update)
elif choice_decode == "2":
info = self.input_coding(ROT, decode_encode=self.status, from_file=True).copy()
update = info["Encoded"]
filename = info["Filename"]
replace_file(filename, update)
elif choice_decode == "3":
info = self.input_coding(DayEncoding, decode_encode=self.status, shift=True, hexa=True, from_file=True).copy()
update = info["Encoded"]
filename = info["Filename"]
replace_file(filename, update)
elif choice_decode == "4":
print("Développement en cours...")
else:
print_color('Invalid choice', color='red', effect='bold')
break
else:
print_color('Invalid choice', color='red', effect='bold')
time.sleep(0.5)
def clear_history(self):
"""
To clear the program history
Pour effacer l'historique du programme
"""
self.clear(effect='strike')
time.sleep(0.5)
self.history = "\nL'historique actuelle a été vidé"
self.clear()
time.sleep(0.5)
self.history = "\n"
def save_history(self):
"""
To save the program history
Pour sauvegarder l'historique du programme
"""
with open("historique.txt", "a", encoding='utf-8') as f:
f.write(self.history)
print_color("L'historique a été sauvegardé", effect="italic")
time.sleep(0.5)
self.clear()
def del_save(self):
self.clear(effect='strike', color='red')
time.sleep(0.5)
self.history = "\n"
try:
os.remove("historique.txt")
except:
with open('historique.txt', 'w') as f:
f.write("deleted")
self.save_history()
self.clear()
print_color("La sauvegarde de l'historique a été supprimé", effect="italic")
def restart(self):
try:
os.execl(__file__, *sys.argv)
exit(0)
except:
print_color("Cette fonction n'est actuellement pas fonctionnel sur votre appareil", color="red", effect="bold")
time.sleep(1.5)
def test(self):
Shift = 10
Password = "DELTA's TEAM BY DAISSEUR"
Text = "Je ne sais pas pourquoi le mot de passe est en anglais mais bon. Alors ça marche ?"
self.status = "encode"
encoding = DayEncoding(password=Password, string=Text, shift=Shift, debug=True).encode()
print_color(encoding, color='blue')
self.add_history(Password, Text, encoding, decode_encode="encode", shift=str(Shift))
self.status = "decode"
decoding = DayEncoding(Password, encoding, Shift, hexa=True, debug=True, error_input=True).decode()
print_color(decoding, color='blue')
self.add_history(Password, encoding, decoding, decode_encode="decode", shift=str(Shift))
def run(self):
while True:
self.banner = ' \\\ DELTA // '
self.clear()
choice = input(self.create_menu(2, ["Encoder",
"Décoder",
"Encoder et Décoder",
"Encoder ou decoder un fichier",
'',
"Effacer l'historique actuel",
"Sauvegarder l'historique",
"Effacer la sauvegarde de l'historique",
'',
"Redémarrer le programme",
'',
" ",
]))
if choice == '1':
self.choice_encoding()
elif choice == '2':
self.choice_decoding()
elif choice == "3":
self.encoding_decoding()
elif choice == "4":
self.encode_decode_file()
elif choice == "5":
self.clear_history()
elif choice == "6":
self.save_history()
elif choice == "7":
self.del_save()
elif choice == "8":
self.restart()
elif choice == "9":
self.test()
time.sleep(0.5)
if __name__ == '__main__' or "debug" in sys.argv:
main(copy=True).run()