-
Notifications
You must be signed in to change notification settings - Fork 0
/
christopher.py
1687 lines (1582 loc) · 84.9 KB
/
christopher.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
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
#!/usr/bin/env python
#
# \ \ 16 21 05 22 06 07 02 03 21 18 05 / /
# \ \ Pp Uu Ee Vv Ff Gg Bb Cc Uu Rr Ee / /
# \ \__/\__/\__/\__/\__/\__/\__/\__/\__/\__/\__/ /
# \ abcd efgh ijkl m-n opqr stuv wxyz /
# \__/\__/\__/\__/\__/\__/\__/\__/\__/\__/\__/
# /Cc Hh Rr Ii Ss Tt Oo Pp Hh Ee Rr\
# \__________________________________________/
# Tool for Encryption & Decryption
# Github: mammaddrik
#::::: Library :::::
from lib.banner import Banner
from lib.color import Color, color_banner
from lib.clearscr import clearScr
from lib.slowprint import slowprint
#::::: Detect :::::
from detect.detectenglish import isEnglish
#::::: Src :::::
from src.atbash import atbash
from src.caesar import caesar_encryption, caesar_decryption, caesar_crack
from src.affine import affine_encryption, affine_decryption, affine_crack, extended_gcd
from src.vigenère import vigenère_encrypt, vigenère_decrypt
from src.revers import revers
from src.playfair import massageKey, massageMessage, showgrid, playfair, showres
from src.railfence import railfence_encrypt, railfence_decrypt
from src.scytale import scytale_encrypt, scytale_decrypt
from src.polybiussquare import polybius_square_encrypt, polybius_square_decrypt
from src.columnar import columnar_encrypt, columnar_decrypt
from src.simplesubstitution import simple_substitution_encrypt, simple_substitution_decrypt, generateKey, crack
from src.makewordpatterns import getWordPattern
from src.baconian import baconian_encryption, baconian_decryption
from src.morsecode import morse, morsetext
from src.rot13 import rot13
from src.hashgenerator import hashgenerator
from src.hashid import hashid
from src.keyboard import Keyboard
from src.plugboard import Plugboard
from src.rotor import Rotor
from src.reflector import Reflector
from src.enigma import Enigma
from src.aes import aes_encrypt, aes_decrypt, generate_key
from src.keygenerator import generateKeys, writeKeysToFile
from src.publickeycipher import publickey_encrypt, publickey_decrypt, readKeysFromFile
from src.image import image_encrypt, image_decrypt
from src.audio import audio_encrypt, audio_decrypt
#::::: Tools :::::
from src.wordlist import wordlist
from src.customwordlist import interactive
from src.passwordgenerator import passwordgenerate
from src.passwordmanager import get_master_password, encrypt, decrypt, create_csv, add, edit, delete
from src.frequencyanalysis import getFrequencyOrder, getFrequencyScore
#::::: Default Library :::::
import os
import sys
import time
import hashlib
import string
import re
import secrets
import webbrowser
from datetime import datetime
from itertools import product
from hmac import compare_digest
#::::: Libraries to be installed :::::
try:
import pandas as pd
import rsa
from pwinput import pwinput
except ImportError:
os.system("pip install -r requirements.txt")
#::::: Again :::::
def again():
"A Function To Ask The User To Restart The Program."
christopher_again = input(Color.BCyan+"\nDo You Want To Continue?"+Color.End+"\n┌───(christopher)─[~/again]─[Y/n]\n└─"+color_banner[0]+"$ "+Color.End)
if (christopher_again.upper() == "Y" or christopher_again == ""):
clearScr()
time.sleep(0.4)
christopher()
elif (christopher_again.upper() == "N"):
print("\n\tGoodbye :)")
time.sleep(0.4)
clearScr()
sys.exit()
else:
clearScr()
christopher()
#::::: Keep :::::
def keep():
"A Function To Ask The User To Decrypt with different keys."
christopher_keep = input(Color.BCyan+"\nDo You Want To try more keys?"+Color.End+"\n┌───(christopher)─[~/continue]─[Y/n]\n└─"+color_banner[0]+"$ "+Color.End)
if (christopher_keep.upper() == "Y" or christopher_keep == ""):
pass
elif (christopher_keep.upper() == "N"):
again()
else:
again()
#::::: Christopher :::::
def christopher():
"The function of christoper."
clearScr()
time.sleep(0.4)
print(Banner.christopher_banner)
choice = input("\n┌───(christopher)─[~/christopher]─[99]Exit\n└─"+color_banner[0]+"$ "+Color.End)
#::::: Cryptography :::::
if (choice == "1" or choice == "01"):
clearScr()
time.sleep(0.4)
print(Banner.cipher_banner)
select = input("\n┌───(christopher)─[~/christopher/Cryptography]─[99]Back to Main Menu\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Atbash Cipher :::::
if (select == "1" or select == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
message = input("\n┌───(christopher)─[~/christopher/Cryptography/Atbash Cipher]\n├─[Enter your message]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(message) == 0:
slowprint("└─["+Color.BRed+"Message cannot be empty"+Color.End+"]")
again()
elif message.isdigit():
slowprint("└─["+Color.BRed+"Message cannot be only number"+Color.End+"]")
again()
else:
print(f"└─[Output: {atbash(message)}]")
again()
#::::: Caesar Cipher :::::
elif (select == "2" or select == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Encryption [02]Decryption\n [03]Crack [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/Caesar Cipher]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Encryption :::::
if (pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
plaintext = input("\n┌───(christopher)─[~/christopher/Cryptography/Caesar Cipher/Encryption]\n├─[Enter your Text]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(plaintext) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
elif plaintext.isdigit():
slowprint("└─["+Color.BRed+"plaintext cannot be only number"+Color.End+"]")
again()
try:
shift = int(input("├─[Enter your shift number]"+color_banner[1]+"$ "+Color.End))
if shift >= 1 and shift <= 25:
print(f"└─[Output: {caesar_encryption(plaintext, shift)}]")
again()
else:
slowprint("├─["+Color.BRed+"Shift value must be a number Between 1 and 25 (Default: 3)"+Color.End+"]")
shift = 3
print(f"└─[Output: {caesar_encryption(plaintext, shift)}]")
again()
except ValueError:
slowprint("├─["+Color.BRed+"Shift value must be a number (Default: 3)"+Color.End+"]")
shift = 3
print(f"└─[Output: {caesar_encryption(plaintext, shift)}]")
again()
#::::: Decryption :::::
elif(pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Caesar Cipher/Decryption]\n├─[Enter your Text]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
elif ciphertext.isdigit():
slowprint("└─["+Color.BRed+"Ciphertext cannot be only number"+Color.End+"]")
again()
try:
shift = int(input("├─[Enter your shift number]"+color_banner[1]+"$ "+Color.End))
if shift >= 1 and shift <= 25:
print(f"└─[Output: {caesar_decryption(ciphertext, shift)}]")
again()
else:
slowprint("├─["+Color.BRed+"Shift value must be a number Between 1 and 25 (Default: 3)"+Color.End+"]")
shift = 3
print(f"└─[Output: {caesar_decryption(ciphertext, shift)}]")
again()
except ValueError:
slowprint("├─["+Color.BRed+"Shift value must be a number (Default: 3)"+Color.End+"]")
shift = 3
print(f"└─[Output: {caesar_decryption(ciphertext, shift)}]")
again()
#::::: Crack :::::
elif(pick == "3" or pick == "03"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Caesar Cipher/Crack]\n├─[Enter your Text]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
elif ciphertext.isdigit():
slowprint("└─["+Color.BRed+"Ciphertext cannot be only number"+Color.End+"]")
again()
decrypted_texts = caesar_crack(ciphertext)
for i, text in enumerate(decrypted_texts):
if isEnglish(text):
print("├─[Shift: "+Color.BGreen+f"{i+1}"+Color.End+f"]\n└─[The plaintext may be this: {text}]")
again()
elif (pick == "99"):
christopher()
else:
again()
#::::: Affine Cipher :::::
elif (select == "3" or select == "03"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Encryption [02]Decryption\n [03]Crack [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/Affine Cipher]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Encryption :::::
if (pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
plaintext = input("\n┌───(christopher)─[~/christopher/Cryptography/Affine Cipher/Encryption]\n├─[Enter your Plaintext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(plaintext) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
elif plaintext.isdigit():
slowprint("└─["+Color.BRed+"Plaintext cannot be only number"+Color.End+"]")
again()
try:
slope = int(input("├─[Enter your slope(a) number (The number must be odd)]"+color_banner[1]+"$ "+Color.End))
if slope % 2 == 0:
slowprint("└─["+Color.BRed+"Slope(a) value must be a number Between 1 and 25 (The number must be odd)"+Color.End+"]")
again()
intercept = int(input("├─[Enter your intercept(b) number]"+color_banner[1]+"$ "+Color.End))
if (slope >= 1 and slope <= 25):
print(f"└─[Output: {affine_encryption(plaintext, slope, intercept)}]")
again()
else:
slowprint("└─["+Color.BRed+"Slope(a) and Intercept(b) value must be a number Between 1 and 25"+Color.End+"]")
again()
except ValueError:
slowprint("└─["+Color.BRed+"Slope(a) and Intercept(b) value must be a number (Slope(a) number must be odd)"+Color.End+"]")
again()
#::::: Decryption :::::
elif(pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Affine Cipher/Decryption]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
elif ciphertext.isdigit():
slowprint("└─["+Color.BRed+"Ciphertext cannot be only number"+Color.End+"]")
again()
try:
slope = int(input("├─[Enter your slope(a) number (The number must be odd)]"+color_banner[1]+"$ "+Color.End))
if slope % 2 == 0:
slowprint("└─["+Color.BRed+"Slope(a) value must be a number Between 1 and 25 (The number must be odd)"+Color.End+"]")
again()
intercept = int(input("├─[Enter your intercept(b) number]"+color_banner[1]+"$ "+Color.End))
if (slope >= 1 and slope <= 25):
print(f"└─[Output: {affine_decryption(ciphertext, slope, intercept)}]")
again()
else:
slowprint("└─["+Color.BRed+"Slope(a) and Intercept(b) value must be a number Between 1 and 25"+Color.End+"]")
again()
except ValueError:
slowprint("└─["+Color.BRed+"Slope(a) and Intercept(b) value must be a number (Slope(a) number must be odd)"+Color.End+"]")
again()
#::::: Crack :::::
elif(pick == "3" or pick == "03"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Affine Cipher/Crack]\n└─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
elif ciphertext.isdigit():
slowprint("└─["+Color.BRed+"Ciphertext cannot be only number"+Color.End+"]")
again()
alphabet = string.ascii_lowercase
m = len(alphabet)
for a in range(1, m):
if extended_gcd(a, m)[0] == 1:
for b in range(0, m):
decrypted_text = affine_crack(ciphertext, a, b)
if isEnglish(decrypted_text):
print("┌─[Slope(a) = "+Color.BGreen+f"{a} "+Color.End+"Intercept(b) = "+Color.BGreen+f"{b}"+Color.End+f"]\n└─[The plaintext may be this: {decrypted_text}]")
keep()
again()
#::::: Back to Main Menu :::::
elif (pick == "99"):
christopher()
else:
again()
#::::: Vigenère Cipher :::::
elif (select == "4" or select == "04"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Encryption [02]Decryption\n [03]Crack [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/Vigenère Cipher]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Encryption :::::
if(pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
plaintext = input("\n┌───(christopher)─[~/christopher/Cryptography/Vigenère Cipher/Encryption]\n├─[Enter your Plaintext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(plaintext) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
key = input("├─[Enter the key]"+color_banner[1]+"$ "+Color.End).lower().strip()
if key.isdigit():
slowprint("└─["+Color.BRed+"Key cannot be number"+Color.End+"]")
again()
elif len(key) == 0:
slowprint("└─["+Color.BRed+"key cannot be empty"+Color.End+"]")
again()
key = re.sub(r'\d+', '', key)
ciphertext = vigenère_encrypt(plaintext, key)
print(f"└─[Ciphertext: {ciphertext}]")
again()
#::::: Decryption :::::
elif(pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Vigenère Cipher/Decryption]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
key = input("├─[Enter the key]"+color_banner[1]+"$ "+Color.End).lower().strip()
plaintext = vigenère_decrypt(ciphertext, key)
print(f"└─[Plaintext: {plaintext.lower()}]")
again()
#::::: Crack :::::
elif(pick == "3" or pick == "03"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Vigenère Cipher/Crack]\n└─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
character = string.ascii_lowercase
for i in range(1, 1000):
for j in product(character, repeat=i):
key = "".join(j)
key = re.sub(r'\d+', '', key)
print(f"├─[Key: {key}]", end='\r')
plaintext = vigenère_decrypt(ciphertext, key).upper()
if isEnglish(plaintext):
print(f"┌─[Key: "+Color.BGreen+f"{key}"+Color.End+"]")
print(f"└─[The plaintext may be this: {plaintext.lower()}]")
keep()
again()
#::::: Back to Main Menu :::::
elif (pick == "99"):
christopher()
else:
again()
#::::: Revers Text :::::
elif (select == "5" or select == "05"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
message = input("\n┌───(christopher)─[~/christopher/Cryptography/Revers Text]\n├─[Enter your message]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(message) == 0:
slowprint("└─["+Color.BRed+"message cannot be empty"+Color.End+"]")
again()
revers(message)
again()
#::::: Playfair Cipher :::::
elif (select == "6" or select == "06"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Encryption [02]Decryption\n [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/Playfair Cipher]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Encryption :::::
if(pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
enc = True
usermassage = input("\n┌───(christopher)─[~/christopher/Cryptography/Playfair Cipher/Encryption]\n├─[Enter your Plaintext]"+color_banner[1]+"$ "+Color.End).upper().strip()
if len(usermassage) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
massage = massageMessage(usermassage)
user_key = (input("└─[Enter the key]"+color_banner[1]+"$ "+Color.End)+'abcdefghijklmnopqrstuvwxyz').upper()
key = massageKey(user_key)
showgrid(key)
newmassage = playfair(enc,massage,key)
print('showing digraphs')
showres(massage, newmassage)
ciphertext = newmassage
print(f"[Ciphertext: {ciphertext}]")
again()
#::::: Decryption :::::
elif(pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
enc = False
usermassage = input("\n┌───(christopher)─[~/christopher/Cryptography/Playfair Cipher/Decryption]\n├─[Enter your Plaintext]"+color_banner[1]+"$ "+Color.End).upper().strip()
if len(usermassage) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
massage = massageMessage(usermassage)
user_key = (input("└─[Enter the key]"+color_banner[1]+"$ "+Color.End)+'abcdefghijklmnopqrstuvwxyz').upper()
key = massageKey(user_key)
showgrid(key)
newmassage = playfair(enc,massage,key)
print('showing digraphs')
showres(massage, newmassage)
plaintext = newmassage
print(f"[Plaintext: {plaintext}]")
again()
#::::: Back to Main Menu :::::
elif(pick == "99"):
christopher()
else:
again()
#::::: Rail Fence Cipher :::::
elif (select == "7" or select == "07"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Encryption [02]Decryption\n [03]Crack [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/Playfair Cipher]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Encryption :::::
if(pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
plaintext = input("\n┌───(christopher)─[~/christopher/Cryptography/Rail Fence Cipher/Encryption]\n├─[Enter your Plaintext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(plaintext) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
try:
key = int(input("├─[Enter the key]"+color_banner[1]+"$ "+Color.End))
if key >= 2 and key <= len(plaintext):
ciphertext = railfence_encrypt(plaintext, key)
print(f"└─[Ciphertext: {ciphertext}]")
again()
else:
slowprint("└─["+Color.BRed+f"Key value must be a number Between 2 and {len(plaintext)}"+Color.End+"]")
again()
except ValueError:
slowprint("└─["+Color.BRed+"Key value must be a number"+Color.End+"]")
again()
#::::: Decryption :::::
elif(pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Rail Fence Cipher/Decryption]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
try:
key = int(input("├─[Enter the key]"+color_banner[1]+"$ "+Color.End))
if key >= 2 and key <= len(ciphertext):
plaintext = railfence_decrypt(ciphertext, key)
print(f"└─[Plaintext: {plaintext}]")
again()
else:
slowprint("└─["+Color.BRed+f"Key value must be a number Between 2 and {len(plaintext)}"+Color.End+"]")
again()
except ValueError:
slowprint("└─["+Color.BRed+"Key value must be a number"+Color.End+"]")
again()
#::::: Crack :::::
elif(pick == "3" or pick == "03"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Rail Fence Cipher/Crack]\n└─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
for i in range(2, len(ciphertext)):
key = i
plaintext = railfence_decrypt(ciphertext, key).upper()
if isEnglish(plaintext):
print(f"┌─[Key: "+Color.BGreen+f"{key}"+Color.End+"]")
print(f"└─[Plaintext: {plaintext.lower()}]")
keep()
again()
#::::: Back to Main Menu :::::
elif(pick == "99"):
christopher()
else:
again()
#::::: Scytale Cipher :::::
elif (select == "8" or select == "08"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Encryption [02]Decryption\n [03]Crack [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/Playfair Cipher]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Encryption :::::
if(pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
plaintext = input("\n┌───(christopher)─[~/christopher/Cryptography/Scytale Cipher/Encryption]\n├─[Enter your Plaintext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(plaintext) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
try:
diameter = int(input("├─[Enter the diameter number]"+color_banner[1]+"$ "+Color.End))
ciphertext = scytale_encrypt(plaintext, diameter)
print(f"└─[Ciphertext: {ciphertext}]")
again()
except ValueError:
slowprint("├─["+Color.BRed+"diameter value must be a number"+Color.End+"]")
again()
#::::: Decryption :::::
if(pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Scytale Cipher/Decryption]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
try:
diameter = int(input("├─[Enter the diameter number]"+color_banner[1]+"$ "+Color.End))
plaintext = scytale_decrypt(ciphertext, diameter)
print(f"└─[Ciphertext: {plaintext}]")
again()
except ValueError:
slowprint("├─["+Color.BRed+"diameter value must be a number"+Color.End+"]")
again()
#::::: Crack :::::
if(pick == "3" or pick == "03"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Scytale Cipher/Crack]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
for i in range(2, len(ciphertext)):
diameter = i
plaintext = scytale_decrypt(ciphertext, diameter)
if isEnglish(plaintext):
print("├─[Diameter: "+Color.BGreen+f"{i}"+Color.End+f"]\n└─[The plaintext may be this: {plaintext}]")
keep()
again()
#::::: Back to Main Menu :::::
elif(pick == "99"):
christopher()
else:
again()
#::::: Polybius Square Cipher :::::
elif (select == "9" or select == "09"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
message = input("\n┌───(christopher)─[~/christopher/Cryptography/Polybius Square Cipher]\n├─[Enter your message]"+color_banner[1]+"$ "+Color.End).upper().strip()
if len(message) == 0:
slowprint("└─["+Color.BRed+"Message cannot be empty"+Color.End+"]")
again()
pick = all(char.isdigit() or char.isspace() for char in message)
if pick:
plaintext = polybius_square_decrypt(message)
print(f"└─[Plaintext: {plaintext.lower()}]")
again()
else:
ciphertext = polybius_square_encrypt(message)
print(f"└─[Ciphertext: {ciphertext}]")
again()
#::::: Columnar Cipher :::::
elif (select == "10"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Encryption [02]Decryption\n [03]Crack [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/Columnar Cipher]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Encryption :::::
if(pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
plaintext = input("\n┌───(christopher)─[~/christopher/Cryptography/Columnar Cipher/Encryption]\n├─[Enter your Plaintext]"+color_banner[1]+"$ "+Color.End).strip()
if len(plaintext) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
try:
key = int(input("├─[Enter the key]"+color_banner[1]+"$ "+Color.End))
if key >= 2 and key <= len(plaintext):
ciphertext = columnar_encrypt(plaintext, key)
print(f"└─[Ciphertext: {ciphertext}]")
again()
else:
slowprint("└─["+Color.BRed+f"Key value must be a number Between 2 and {len(plaintext)}"+Color.End+"]")
again()
except ValueError:
slowprint("└─["+Color.BRed+"Key value must be a number"+Color.End+"]")
again()
again()
#::::: Decryption :::::
elif(pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Columnar Cipher/Decryption]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
try:
key = int(input("├─[Enter the key]"+color_banner[1]+"$ "+Color.End))
if key >= 2 and key <= len(ciphertext):
plaintext = columnar_decrypt(ciphertext, key)
print(f"└─[Ciphertext: {plaintext}]")
again()
else:
slowprint("└─["+Color.BRed+f"Key value must be a number Between 2 and {len(ciphertext)}"+Color.End+"]")
again()
except ValueError:
slowprint("└─["+Color.BRed+"Key value must be a number"+Color.End+"]")
again()
#::::: Crack :::::
elif(pick == "3" or pick == "03"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Columnar Cipher/Crack]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
for key in range(1, len(ciphertext)):
plaintext = columnar_decrypt(ciphertext, key).upper()
if isEnglish(plaintext):
print(f"├─[Key: "+Color.BGreen+f"{key}"+Color.End+"]")
print(f"└─[Plaintext: {plaintext.lower()}]")
keep()
again()
#::::: Back to Main Menu :::::
elif (pick == "99"):
christopher()
else:
again()
#::::: Simple Substitution Cipher :::::
elif (select == "11"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Encryption [02]Decryption\n [03]Crack [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/Simple Substitution Cipher]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Encryption :::::
if(pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
plaintext = input("\n┌───(christopher)─[~/christopher/Cryptography/Simple Substitution Cipher/Encryption]\n├─[Enter your Plaintext]"+color_banner[1]+"$ "+Color.End).strip()
if len(plaintext) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
elif plaintext.isdigit():
slowprint("└─["+Color.BRed+"Plaintext cannot be only number"+Color.End+"]")
again()
key = generateKey()
print(f"├─[key: {key}]")
print(f"└─[Ciphertext: {simple_substitution_encrypt(plaintext, key)}]")
again()
#::::: Decryption :::::
if(pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Simple Substitution Cipher/Decryption]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
elif ciphertext.isdigit():
slowprint("└─["+Color.BRed+"Ciphertext cannot be only number"+Color.End+"]")
again()
key = input(f"├─[Enter your Key]"+color_banner[1]+"$ "+Color.End).strip()
contains_number = any(char.isdigit() for char in key)
if contains_number:
slowprint("└─["+Color.BRed+"The key must be 26 characters without numbers"+Color.End+"]")
again()
if len(key) == 26:
print(f"└─[Plaintext: {simple_substitution_decrypt(ciphertext, key)}]")
again()
else:
slowprint("└─["+Color.BRed+"The key must be 26 characters without numbers"+Color.End+"]")
again()
#::::: Crack :::::
if(pick == "3" or pick == "03"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/Simple Substitution Cipher/Crack]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
elif ciphertext.isdigit():
slowprint("└─["+Color.BRed+"Ciphertext cannot be only number"+Color.End+"]")
again()
patterns = input("├─[Do you have a Word Pattern file]─[Y/n]"+color_banner[1]+"$ "+Color.End).strip()
if (patterns.upper() == "Y" or patterns == ""):
crack(ciphertext)
again()
elif (patterns.upper() == "N"):
wordPatterns = {}
file = input("├─[Enter the file]"+color_banner[1]+"$ "+Color.End).strip()
try:
with open(file, "r") as f:
filesize = os.path.getsize((pwfile))
if filesize == 0:
slowprint("└─["+Color.BRed+"File is Empty"+Color.End+"]")
again()
except FileNotFoundError:
slowprint("└─["+Color.BRed+"File Not Found"+Color.End+"]")
again()
path = os.getcwd()
if os.name == "nt":
with open(file, "r") as f:
for word in f:
word = word.strip()
pattern = getWordPattern(word)
if pattern in wordPatterns:
wordPatterns[pattern].append(word)
else:
wordPatterns[pattern] = [word]
with open(path+"/src/wordpatterns.py", "w") as f:
f.write(f"wordPatterns = {wordPatterns}")
else:
try:
with open(path+"/src/wordpatterns.py", "w") as f:
f.write(f"wordPatterns = {wordPatterns}")
except FileNotFoundError:
dictionaryFile = open(path+'/src/wordpatterns.py')
crack(ciphertext)
again()
else:
again()
#::::: Back to Main Menu :::::
elif (pick == "99"):
christopher()
else:
again()
#::::: Baconian Cipher :::::
elif (select == "12"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
message = input("\n┌───(christopher)─[~/christopher/Cryptography/Baconian Cipher]\n├─[Enter your message]"+color_banner[1]+"$ "+Color.End).upper().strip()
if len(message) == 0:
slowprint("└─["+Color.BRed+"Message cannot be empty"+Color.End+"]")
again()
elif message.isdigit():
slowprint("└─["+Color.BRed+"Message cannot be only number"+Color.End+"]")
again()
elif re.fullmatch(r'[AB]*', message):
chunk_size = 5
print(f"└─[Plaintext: ", end='')
for i in range(0, len(message), chunk_size):
decoded = baconian_decryption(message[i:i + chunk_size])
print(f"{decoded.lower()}",end='')
print("]")
again()
else:
print(f"└─[Ciphertext: {baconian_encryption(message)}]")
again()
#::::: Morse Code :::::
elif (select == "13"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
message = input("\n┌───(christopher)─[~/christopher/Cryptography/Morse Code]\n├─[Enter your message]"+color_banner[1]+"$ "+Color.End).upper()
if len(message) == 0:
slowprint("└─["+Color.BRed+"Message cannot be empty"+Color.End+"]")
again()
elif message.isdigit():
slowprint("└─["+Color.BRed+"Message cannot be only number"+Color.End+"]")
again()
characters = {'-', '.', ' '}
pick = all(char in characters for char in message)
if pick:
morsetext(message)
again()
else:
morse(message)
again()
#::::: Rot13 Cipher :::::
elif (select == "14"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
message = input("\n┌───(christopher)─[~/christopher/Cryptography/Rot13]\n├─[Enter your text]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(message) == 0:
slowprint("└─["+Color.BRed+"Message cannot be empty"+Color.End+"]")
again()
elif message.isdigit():
slowprint("└─["+Color.BRed+"Message cannot be only number"+Color.End+"]")
again()
else:
print(f"└─[Output: {rot13(message)}]")
again()
# One-Time Pad Cipher
elif (select == "15"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Encryption [02]Decryption\n [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/One-Time Pad Cipher]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Encryption :::::
if(pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
plaintext = input("\n┌───(christopher)─[~/christopher/Cryptography/One-Time Pad Cipher/Encryption]\n├─[Enter your Plaintext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(plaintext) == 0:
slowprint("└─["+Color.BRed+"Plaintext cannot be empty"+Color.End+"]")
again()
SYMBOLS = string.ascii_letters
key = ""
for i in range(len(plaintext)):
key += secrets.choice(SYMBOLS)
print(f"├─[Key: {key}]")
ciphertext = vigenère_encrypt(plaintext, key)
print(f"└─[Ciphertext: {ciphertext}]")
again()
#::::: Decryption :::::
elif(pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
ciphertext = input("\n┌───(christopher)─[~/christopher/Cryptography/One-Time Pad Cipher/Decryption]\n├─[Enter your Ciphertext]"+color_banner[1]+"$ "+Color.End).lower().strip()
if len(ciphertext) == 0:
slowprint("└─["+Color.BRed+"Ciphertext cannot be empty"+Color.End+"]")
again()
key = input("├─[Enter the key]"+color_banner[1]+"$ "+Color.End).lower().strip()
plaintext = vigenère_decrypt(ciphertext, key)
print(f"└─[Plaintext: {plaintext.lower()}]")
again()
#::::: Back to Main Menu :::::
elif (pick == "99"):
christopher()
else:
again()
#::::: Hash Function :::::
elif (select == "16"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
pick = input(" [01]Hash Generator [02]Hash Cracker\n [03]Hash Identifier [99]Back to Main Menu\n\n┌───(christopher)─[~/christopher/Cryptography/Hash Function]\n└─"+color_banner[1]+"$ "+Color.End)
#::::: Hash Generator :::::
if (pick == "1" or pick == "01"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
password = input("\n┌───(christopher)─[~/christopher/Cryptography/Hash Function/Hash Generator]\n├─[Enter the password]"+color_banner[1]+"$ "+Color.End).strip()
if len(password) == 0:
slowprint("└─["+Color.BRed+"Password cannot be empty"+Color.End+"]")
again()
hashvalue = input("├───────────────┬───────────────┬───────────────┐\n├─[01]MD2 ├─[2]MD4 ├─[03]MD5 │\n├─[04]SHA1 ├─[05]SHA224 ├─[06]SHA256 │\n├─[07]SHA384 ├─[08]SHA512 ├─[09]sha3-224 │\n├─[10]sha3-256 ├─[11]sha3-384 ├─[12]sha3-512 │\n├─[13]shake-128 ├─[14]shake-256 ├─[15]blake2b │\n├─[16]blake2s ├─[17]NTLM ├─[18]adler32 │\n├─[19]crc32 ├─[20]all ├─[21]Back │\n├───────────────┴───────────────┴───────────────┘\n└─[Select the function]"+color_banner[1]+"$ "+Color.End)
if len(hashvalue) == 0:
slowprint("└─["+Color.BRed+"Hashvalue cannot be empty"+Color.End+"]")
again()
if (hashvalue == "1" or hashvalue == "01"):
hashvalue = "md2"
elif (hashvalue == "2" or hashvalue == "02"):
hashvalue = "md4"
elif (hashvalue == "3" or hashvalue == "03"):
hashvalue = "md5"
elif (hashvalue == "4" or hashvalue == "04"):
hashvalue = 'sha1'
elif (hashvalue == "5" or hashvalue == "05"):
hashvalue = 'sha224'
elif (hashvalue == "6" or hashvalue == "06"):
hashvalue = 'sha256'
elif (hashvalue == "7" or hashvalue == "07"):
hashvalue = 'sha384'
elif (hashvalue == "8" or hashvalue == "08"):
hashvalue = 'sha512'
elif (hashvalue == "9" or hashvalue == "09"):
hashvalue = 'sha3_224'
elif (hashvalue == "10"):
hashvalue = 'sha3_256'
elif (hashvalue == "11"):
hashvalue = 'sha3_384'
elif (hashvalue == "12"):
hashvalue = 'sha3_512'
elif (hashvalue == "13"):
hashvalue = 'shake_128'
elif (hashvalue == "14"):
hashvalue = 'shake_256'
elif (hashvalue == "15"):
hashvalue = 'blake2b'
elif (hashvalue == "16"):
hashvalue = 'blake2s'
elif (hashvalue == "17"):
hashvalue = 'NTLM'
elif (hashvalue == "18"):
hashvalue = 'adler32'
elif (hashvalue == "19"):
hashvalue = 'crc32'
elif (hashvalue == "20"):
hashvalue = 'all'
elif (hashvalue == "21"):
christopher()
else:
slowprint("└─["+Color.BRed+"Enter the Available Function"+Color.End+"]")
again()
hashgenerator(password, hashvalue)
again()
#::::: Hash Cracker :::::
elif (pick == "2" or pick == "02"):
clearScr()
time.sleep(0.4)
print(Banner.banner)
Hash = input("\n┌───(christopher)─[~/christopher/Cryptography/Hash Function/Hash Cracker]\n├─[Enter the hash]"+color_banner[1]+"$ "+Color.End).strip()
if len(Hash) == 32:
hashvalue = "md5"
elif len(Hash) == 40:
hashvalue = "sha1"
elif len(Hash) == 64:
hashvalue = "sha256"
elif len(Hash) == 96:
hashvalue = "sha384"
elif len(Hash) == 128:
hashvalue = "sha512"
else:
slowprint("└─["+Color.BRed+"Hash Function: Unknown"+Color.End+"]")
again()
pick = input("├─[Do you have a passwordlist]─[Y/n]"+color_banner[1]+"$ "+Color.End)
if (pick.upper() == "Y" or pick == ""):
pwfile = input("├─[Enter the password file name]"+color_banner[1]+"$ "+Color.End)
try:
with open(pwfile, "r") as f:
filesize = os.path.getsize((pwfile))
if filesize == 0:
slowprint("└─["+Color.BRed+"File is Empty"+Color.End+"]")
again()
with open(pwfile, "r") as f:
counter = 1
t1 = datetime.now()
for password in f:
h = hashlib.new(hashvalue)
setpass = bytes(password.strip(), "utf-8")
h.update(setpass)
hashedguess = h.hexdigest()
counter += 1