forked from qianxiao996/CTF-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTF-Tools.py
1325 lines (1291 loc) · 62.4 KB
/
CTF-Tools.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
import binascii
import html,base64,sys,string,os,urllib.parse,random,collections,re
import importlib.machinery
import webbrowser
import configparser
import requests
if hasattr(sys, 'frozen'):
os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH']
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import pyperclip
import json
from GUI.main import Ui_MainWindow
from GUI.KEY_1 import Ui_KEY1
from GUI.Binary import Ui_Binary
from GUI.KEY_2 import Ui_KEY2
import frozen_dir
SETUP_DIR = frozen_dir.app_path()
sys.path.append(SETUP_DIR)
version = '1.3.0'
update_time = '20210928'
class MainWindows(QtWidgets.QMainWindow,Ui_MainWindow):
def __init__(self,parent=None):
super(MainWindows,self).__init__(parent)
self.Ui = Ui_MainWindow()
self.Ui.setupUi(self)
self.about_text = "\t\t\tAbout\n 此程序为CTF密码学辅助工具,可进行常见的编码、解码、加密、解密操作,请勿非法使用!\n\t\t\tPowered by qianxiao996"
self.author_text = "作者邮箱:[email protected]\nGithub:https://github.com/qianxiao996"
self.load_config()
self.setWindowTitle('CTF-Tools V '+version+' '+update_time+' By qianxiao996 ')
# self.setFixedSize(self.width(), self.height()) ##设置宽高不可变
self.setWindowIcon(QtGui.QIcon('./logo.ico'))
self.Ui.Source_clear_Button.clicked.connect(lambda:self.Ui.Source_text.clear()) # clear_source
self.Ui.Result_clear_Button.clicked.connect(lambda:self.Ui.Result_text.clear()) # clear_result
self.Ui.Source_Copy_Button.clicked.connect(lambda:self.Copy_text('Source')) # copy_source
self.Ui.Result_Copy_Button.clicked.connect(lambda:self.Copy_text('result')) # copy_result
self.Ui.Source_tihuan_Button.clicked.connect(lambda:self.tihuan('Source')) # tihuan_source
self.Ui.Result_tihuan_Button.clicked.connect(lambda:self.tihuan('result')) # tihuan_result
self.Ui.Source_Paste_Button.clicked.connect(lambda: self.paste('Source')) # paste_Source
self.Ui.Result_Paste_Button.clicked.connect(lambda: self.paste('result')) # paste_result
#encode
self.Ui.actionURL_UTF8_encode.triggered.connect(lambda:self.encode(self.Ui.actionURL_UTF8_encode.text()))
self.Ui.actionURL_GB2312_encode.triggered.connect(lambda: self.encode(self.Ui.actionURL_GB2312_encode.text()))
self.Ui.actionUnicode_encode.triggered.connect(lambda: self.encode(self.Ui.actionUnicode_encode.text()))
self.Ui.actionEscape_U_encode.triggered.connect(lambda: self.encode(self.Ui.actionEscape_U_encode.text()))
self.Ui.actionHtmlEncode_encode.triggered.connect(lambda: self.encode(self.Ui.actionHtmlEncode_encode.text()))
self.Ui.actionASCII_encode.triggered.connect(lambda: self.encode(self.Ui.actionASCII_encode.text()))
self.Ui.actionBase16_encode.triggered.connect(lambda: self.encode(self.Ui.actionBase16_encode.text()))
self.Ui.actionBase32_encode.triggered.connect(lambda: self.encode(self.Ui.actionBase32_encode.text()))
self.Ui.actionBase64_encode.triggered.connect(lambda: self.encode(self.Ui.actionBase64_encode.text()))
self.Ui.actionStr_Hex_encode.triggered.connect(lambda: self.encode(self.Ui.actionStr_Hex_encode.text()))
self.Ui.actionShellcode_encode.triggered.connect(lambda: self.encode(self.Ui.actionShellcode_encode.text()))
self.Ui.actionQwerty_encode.triggered.connect(lambda: self.encode(self.Ui.actionQwerty_encode.text()))
self.Ui.actiontupian_base64_encode.triggered.connect(lambda: self.encode(self.Ui.actiontupian_base64_encode.text()))
self.Ui.actiontupian_hex_encode.triggered.connect(lambda: self.encode(self.Ui.actiontupian_hex_encode.text()))
#decode
self.Ui.actionURL_UTF8_decode.triggered.connect(lambda:self.decode(self.Ui.actionURL_UTF8_decode.text()))
self.Ui.actionURL_GB2312_decode.triggered.connect(lambda: self.decode(self.Ui.actionURL_GB2312_decode.text()))
self.Ui.actionUnicode_decode.triggered.connect(lambda: self.decode(self.Ui.actionUnicode_decode.text()))
self.Ui.actionEscape_U_decode.triggered.connect(lambda: self.decode(self.Ui.actionEscape_U_decode.text()))
self.Ui.actionHtmlEncode_decode.triggered.connect(lambda: self.decode(self.Ui.actionHtmlEncode_decode.text()))
self.Ui.actionASCII_decode.triggered.connect(lambda: self.decode(self.Ui.actionASCII_decode.text()))
self.Ui.actionBase16_decode.triggered.connect(lambda: self.decode(self.Ui.actionBase16_decode.text()))
self.Ui.actionBase32_decode.triggered.connect(lambda: self.decode(self.Ui.actionBase32_decode.text()))
self.Ui.actionBase64_decode.triggered.connect(lambda: self.decode(self.Ui.actionBase64_decode.text()))
self.Ui.actionHex_Str_decode.triggered.connect(lambda: self.decode(self.Ui.actionHex_Str_decode.text()))
self.Ui.actionShellcode_decode.triggered.connect(lambda: self.decode(self.Ui.actionShellcode_decode.text()))
self.Ui.actionQwerty_decode.triggered.connect(lambda: self.decode(self.Ui.actionQwerty_decode.text()))
self.Ui.actionbase64_tupian_decode.triggered.connect(lambda: self.decode(self.Ui.actionbase64_tupian_decode.text()))
self.Ui.actionhex_tupian_decode.triggered.connect(
lambda: self.decode(self.Ui.actionhex_tupian_decode.text()))
#encrypt
self.Ui.actionRot13_encrypt.triggered.connect(lambda:self.encrypt(self.Ui.actionRot13_encrypt.text()))
self.Ui.action_kaisa_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_kaisa_encrypt.text()))
self.Ui.action_zhalan_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_zhalan_encrypt.text()))
self.Ui.action_zhalan_w_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_zhalan_w_encrypt.text()))
self.Ui.action_peigen_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_peigen_encrypt.text()))
self.Ui.action_mosi_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_mosi_encrypt.text()))
self.Ui.action_yunying_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_yunying_encrypt.text()))
self.Ui.action_dangpu_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_dangpu_encrypt.text()))
self.Ui.action_sifang_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_sifang_encrypt.text()))
self.Ui.action_weinijiya_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_weinijiya_encrypt.text()))
self.Ui.action_Atbash_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_Atbash_encrypt.text()))
self.Ui.action_fangshe_encrypt.triggered.connect(lambda: self.encrypt(self.Ui.action_fangshe_encrypt.text()))
#decrypt
self.Ui.actionRot13_decrypt.triggered.connect(lambda:self.decrypt(self.Ui.actionRot13_decrypt.text()))
self.Ui.action_kaisa_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_kaisa_decrypt.text()))
self.Ui.action_zhalan_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_zhalan_decrypt.text()))
self.Ui.action_zhalan_w_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_zhalan_w_decrypt.text()))
self.Ui.action_peihen_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_peihen_decrypt.text()))
self.Ui.action_mosi_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_mosi_decrypt.text()))
self.Ui.action_yiwei_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_yiwei_decrypt.text()))
self.Ui.action_yunxing_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_yunxing_decrypt.text()))
self.Ui.action_dangpu_decry.triggered.connect(lambda: self.decrypt(self.Ui.action_dangpu_decry.text()))
self.Ui.action_sifang_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_sifang_decrypt.text()))
self.Ui.action_weinijiya_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_weinijiya_decrypt.text()))
self.Ui.action_Atbash_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_Atbash_decrypt.text()))
self.Ui.action_fangshe_decrypt.triggered.connect(lambda: self.decrypt(self.Ui.action_fangshe_decrypt.text()))
#进制转换
self.Ui.action2_8.triggered.connect(lambda:self.Binary(self.Ui.action2_8.text()))
self.Ui.action2_10.triggered.connect(lambda: self.Binary(self.Ui.action2_10.text()))
self.Ui.action2_16.triggered.connect(lambda: self.Binary(self.Ui.action2_16.text()))
self.Ui.action8_2.triggered.connect(lambda: self.Binary(self.Ui.action8_2.text()))
self.Ui.action8_10.triggered.connect(lambda: self.Binary(self.Ui.action8_10.text()))
self.Ui.action8_16.triggered.connect(lambda: self.Binary(self.Ui.action8_16.text()))
self.Ui.action10_2.triggered.connect(lambda: self.Binary(self.Ui.action10_2.text()))
self.Ui.action10_8.triggered.connect(lambda: self.Binary(self.Ui.action10_8.text()))
self.Ui.action10_16.triggered.connect(lambda: self.Binary(self.Ui.action10_16.text()))
self.Ui.action16_2.triggered.connect(lambda: self.Binary(self.Ui.action16_2.text()))
self.Ui.action16_8.triggered.connect(lambda: self.Binary(self.Ui.action16_8.text()))
self.Ui.action16_10.triggered.connect(lambda: self.Binary(self.Ui.action16_10.text()))
self.Ui.action_others.triggered.connect(lambda: self.Binary(self.Ui.action_others.text()))
self.Ui.actionAbout.triggered.connect(self.about)
self.Ui.actionAuthor.triggered.connect(self.author)
self.Ui.actionUpdate_2.triggered.connect(self.Update)
self.readfile()
#Website
websitemenubar = self.menuBar() # 获取窗体的菜单栏
Website = websitemenubar.addMenu("Website")
for i in json_data:
impMenu = QMenu(i, self)
url_list = json_data[i].split('\n')
for j in url_list:
sub_action = QAction(QIcon(''), j, self)
impMenu.addAction(sub_action)
Website.addMenu(impMenu)
Website.triggered[QAction].connect(self.show_json)
#Plugins
Pluginsmenubar = self.menuBar() # 获取窗体的菜单栏
plugins = Pluginsmenubar.addMenu("Plugins")
for k in plugins_data:
# print(k)
sub_action = QAction(QIcon(''), k, self)
plugins.addAction(sub_action)
plugins.triggered[QAction].connect(self.show_plugins)
#Others
othersmenubar = self.menuBar() # 获取窗体的菜单栏
others = othersmenubar.addMenu("Others")
for j in ["About",'Author','Update']:
sub_action = QAction(QIcon(''), j, self)
others.addAction(sub_action)
impMenu = QMenu("Style", self)
for z in config_setup.options('QSS_List'):
sub_action = QAction(QIcon(''), z, self)
impMenu.addAction(sub_action)
others.addMenu(impMenu)
others.triggered[QAction].connect(self.show_others)
def load_config(self):
try:
global config_setup
global qss_style
# 实例化configParser对象
config_setup = configparser.ConfigParser()
# -read读取ini文件
config_setup.read('config.ini', encoding='utf-8')
if 'QSS_Setup' not in config_setup: # 如果分组type不存在则插入type分组
config_setup.add_section('QSS_Setup')
config_setup.set("QSS_Setup", "QSS", 'default.qss')
config_setup.write(open('config.ini', "r+", encoding="utf-8")) # r+模式
qss_Setup = 'default.qss'
else:
qss_Setup = config_setup.get('QSS_Setup', 'QSS')
with open("QSS/" + qss_Setup, 'r', encoding='utf-8') as f:
qss_style = f.read()
f.close()
MainWindows.setStyleSheet(self, qss_style)
f.close()
except Exception as e:
QMessageBox.critical(self, 'Error', str(e))
pass
def show_others(self,q):
if q.text() =="About":
self.about()
return
if q.text() =="Author":
self.author()
return
if q.text() =="Update":
self.Update()
return
else:
try:
filename = config_setup.get('QSS_List', q.text())
with open("QSS/" +filename, 'r', encoding='utf-8') as f:
qss_style = f.read()
f.close()
MainWindows.setStyleSheet(self, qss_style)
config_setup.set("QSS_Setup", "QSS", filename)
f.close()
# python = sys.executable
# os.execl(python, python, *sys.argv)
except Exception as e:
QMessageBox.critical(self, 'Error', str(e))
pass
def show_plugins(self,q):
try:
plugins_methods = "Plugins/" + plugins_data[q.text()][:-3]
filename = "Plugins/" + plugins_data[q.text()]
text = self.Ui.Source_text.toPlainText()
if text=='':
self.Ui.Result_text.setPlainText('请输入一个源字符串!')
return 0
nnnnnnnnnnnn1 = importlib.machinery.SourceFileLoader(plugins_methods, filename).load_module()
result = nnnnnnnnnnnn1.run(text)
self.Ui.Result_text.setPlainText(str(result))
except Exception as e:
QMessageBox.critical(self, 'Error', str(e))
pass
def show_json(self,q):
# print(q.text())
pyperclip.copy(q.text())
reply = QMessageBox.question(self, 'Message', "链接已复制到剪切板,是否在浏览器中打开链接?", QMessageBox.Yes | QMessageBox.No,
QMessageBox.Yes)
if reply == QMessageBox.Yes:
webbrowser.open(q.text())
else:
pass
def readfile(self):
try:
global json_data
f=open('Plugins//data.json','r',encoding='utf-8')
json_data=json.load(f)
# print(json_data)
f.close()
qss_Setup = config_setup.get('QSS_Setup', 'QSS')
with open("QSS/"+qss_Setup, 'r', encoding='utf-8') as f:
qss_style = f.read()
f.close()
MainWindows.setStyleSheet(self,qss_style)
# print(json_data)
f.close()
global plugins_data
f = open('Plugins/Plugins.json', 'r', encoding='utf-8')
plugins_data = json.load(f)
# print(plugins_data)
f.close()
except Exception as e :
QMessageBox.critical(self,'Error',str(e))
pass
#编码
def encode(self,encode_type):
try:
result_text=''
# print(encode_type)
if encode_type == '图片->Base64':
try:
filename = self.file_open(r"Text Files (*.jpg);;All files(*.*)")
with open(filename, 'rb') as f:
base64_data = base64.b64encode(f.read())
s = base64_data.decode()
self.Ui.Result_text.setPlainText(str('data:image/%s;base64,%s' % (filename[-3:],s)))
return
except:
self.Ui.Result_text.setPlainText('转换失败!')
return
elif encode_type == '图片->Hex':
try:
filename = self.file_open(r"Text Files (*.jpg);;All files(*.*)")
with open(filename, 'rb') as f:
hex_data =f.read()
hexstr = binascii.hexlify(hex_data).decode("utf-8")
hexstr =hexstr.upper()
self.Ui.Result_text.setPlainText(str('%s' % (hexstr)))
return
except:
self.Ui.Result_text.setPlainText('转换失败!')
return
text = self.Ui.Source_text.toPlainText()
if text=='':
self.Ui.Result_text.setPlainText('请输入一个源字符串!')
return 0
# print(encode_type)
if encode_type=='URL-UTF8':
text = text.encode('utf-8')
result_text = urllib.parse.quote(text)
elif encode_type == 'URL-GB2312':
text = text.encode('gb2312')
result_text = urllib.parse.quote(text)
elif encode_type=='Unicode':
text = text.encode('unicode_escape')
result_text = str(text, encoding='utf-8')
elif encode_type=='Escape(%U)':
text = text.encode('unicode_escape')
result_text = str(text, encoding='utf-8').replace('\\u', '%u')
elif encode_type=='HtmlEncode':
result_text = html.escape(text)
elif encode_type=='ASCII':
result = ''
for i in text:
result = str(result) + str(ord(str(i))) + ' '
result_text=str(result)[:-1]
elif encode_type=='Base16':
text = text.lower()
text = base64.b16encode(text.encode("utf-8"))
result_text=str(text, encoding='utf-8')
elif encode_type=='Base32':
text = base64.b32encode(text.encode("utf-8"))
result_text=str(text, encoding='utf-8')
elif encode_type=='Base64':
text = base64.b64encode(text.encode("utf-8"))
result_text=str(text, encoding='utf-8')
elif encode_type=='Str->Hex':
result = ''
for i in text:
single = str(hex(ord(str(i))))
result = result + single
result_text=(str(result)).replace('0x', '')
elif encode_type=='Shellcode':
result = ''
for i in text:
single = str(hex(ord(str(i))))
result = result + single
result_text=(str(result)).replace('0x', '\\x')
elif encode_type=='Qwerty':
str1 = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
str2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
result_text = ""
for s in text:
if s in str1:
if s !=' ':
result_text = result_text + str1[str2.index(s)]
else:
result_text = result_text+' '
else:
result_text ='Qwerty只能对字母加密!'
if result_text!="":
self.Ui.Result_text.setPlainText(str(result_text))
else:
self.Ui.Result_text.setPlainText("编码失败!")
except Exception as e :
self.Ui.Result_text.setPlainText(str(e))
pass
# print(str(e))
#解码
def decode(self,decode_type):
try:
result_text=''
# print(decode_type)
text = self.Ui.Source_text.toPlainText().strip()
if text=='':
self.Ui.Result_text.setPlainText('请输入一个源字符串!')
return 0
if decode_type=='URL-UTF8':
result_text = str(urllib.parse.unquote(text))
elif decode_type == 'URL-GB2312':
result_text = str(urllib.parse.unquote(text, 'gb2312'))
elif decode_type=='Unicode':
result_text = bytes(text, encoding="utf8").decode('unicode_escape')
elif decode_type=='Escape(%U)':
text = text.replace('%u', '\\u').replace('%U', '\\u')
result_text = bytes(text, encoding="utf8").decode('unicode_escape')
elif decode_type=='HtmlEncode':
result_text = html.unescape(text)
elif decode_type=='ASCII':
if ':' in text:
text = text.split(":")
elif ' ' in text:
text = text.split(" ")
elif ';' in text:
text = text.split(";")
elif ',' in text:
text = text.split(",")
else:
list22 = []
list22.append(text)
text=list22
# print(text)
result = ''
for i in text:
if i != '':
# print(i)
# print(chr(int(i)))
result = result + chr(int(i))
result_text =result
elif decode_type=='Base16':
text = text.upper()
text = base64.b16decode(text.encode("utf-8"))
result_text=str(text, encoding='utf-8')
elif decode_type=='Base32':
text = base64.b32decode(text.encode("utf-8"))
result_text=str(text, encoding='utf-8')
elif decode_type=='Base64':
text = base64.b64decode(text.encode("utf-8"))
result_text=str(text, encoding='utf-8')
elif decode_type=='Hex->Str':
text = text.replace('0x', '').replace('0X', '')
result_text = str(bytes.fromhex(text), encoding="utf-8")
elif decode_type=='Shellcode':
text =text.lower()
result = ''
if "0x" in text and "\\x" not in text:
text = text.split('0x')
elif "\\x" in text and "0x" not in text:
text = text.split('\\x')
else:
result_text="请输入正确的格式,如:\n\\x61\\x00\\x62\\x00\\x63\n0x610x000x620x000x63"
self.Ui.Result_text.setPlainText(str(result_text))
return
for i in text:
single = str(bytes.fromhex(i.rjust(2,'0')), encoding="utf-8")
result = result + single
result_text =str(result)
elif decode_type=='Qwerty':
letter = {
'q': 'a', 'w': 'b', 'e': 'c', 'r': 'd', 't': 'e', 'y': 'f', 'u': 'g',
'i': 'h', 'o': 'i', 'p': 'j', 'a': 'k', 's': 'l', 'd': 'm', 'f': 'n',
'g': 'o', 'h': 'p', 'j': 'q', 'k': 'r', 'l': 's', 'z': 't',
'x': 'u', 'c': 'v', 'v': 'w', 'b': 'x', 'n': 'y', 'm': 'z',
'Q': 'A', 'W': 'B', 'E': 'C', 'R': 'D', 'T': 'E', 'Y': 'F', 'U': 'G',
'I': 'H', 'O': 'I', 'P': 'J', 'A': 'K', 'S': 'L', 'D': 'M', 'F': 'N',
'G': 'O', 'H': 'P', 'J': 'Q', 'K': 'R', 'L': 'S', 'Z': 'T',
'X': 'U', 'C': 'V', 'V': 'W', 'B': 'X', 'N': 'Y', 'M': 'Z',
}
result_text = ''
for i in range(0, len(text)):
if text[i] != ' ':
result_text = result_text + letter.get(text[i])
else:
result_text = result_text + ' '
elif decode_type == 'Base64->图片':
try:
file_name = self.file_save('tupian.jpg')
# print(file_name)
str2 = base64.b64decode(text.replace('data:image/jpg;base64,','').replace('data:image/jpeg;base64,','').replace('data:image/png;base64,','').replace('data:image/gif;base64,',''))
file1 = open(file_name, 'wb')
file1.write(str2)
file1.close()
QMessageBox.information(self,'Success','转换成功,文件位置:%s'%file_name)
result_text='转换成功,文件位置:\n%s'%file_name
except:
result_text="转换失败!"
pass
elif decode_type == 'Hex->图片':
try:
file_name = self.file_save('hextupian.jpg')
# print(file_name)
file1 = open(file_name, 'wb')
pic = binascii.a2b_hex(text.encode())
file1.write(pic)
file1.close()
QMessageBox.information(self,'Success','转换成功,文件位置:%s'%file_name)
result_text='转换成功,文件位置:\n%s'%file_name
except:
result_text="转换失败!"
pass
if result_text!="":
self.Ui.Result_text.setPlainText(str(result_text))
else:
self.Ui.Result_text.setPlainText('解码失败!')
except Exception as e :
self.Ui.Result_text.setPlainText(str(e))
# print(e)
pass
#encrypt
def encrypt(self,encrypt_type):
try:
result_text=''
# print(encrypt_type)
text = self.Ui.Source_text.toPlainText().strip()
if text=='':
self.Ui.Result_text.setPlainText('请输入一个源字符串!')
return 0
if encrypt_type=='Rot13':
d = {chr(i + c): chr((i + 13) % 26 + c) for i in range(26) for c in (65, 97)}
result_text = ''.join([d.get(c, c) for c in text])
elif encrypt_type=='凯撒密码':
t = ""
for c in text:
if 'a' <= c <= 'z': # str是可以直接比较的
t += chr(ord('a') + ((ord(c) - ord('a')) + 3) % 26)
elif 'A' <= c <= 'Z':
t += chr(ord('A') + ((ord(c) - ord('A')) + 3) % 26)
else:
t += c
result_text=t
elif encrypt_type=='栅栏密码':
self.WChild_zhalan = Ui_KEY1()
self.dialog = QtWidgets.QDialog(self)
self.WChild_zhalan.setupUi(self.dialog)
self.dialog.setWindowTitle(encrypt_type)
self.WChild_zhalan.label.setText("请输入栏数:")
self.dialog.show()
self.WChild_zhalan.keyenter.clicked.connect(self.zhalanEncrypto)
return 0
elif encrypt_type=='栅栏密码(W型)':
self.WChild_zhalan = Ui_KEY1()
self.dialog = QtWidgets.QDialog(self)
self.WChild_zhalan.setupUi(self.dialog)
self.dialog.setWindowTitle(encrypt_type)
self.WChild_zhalan.label.setText("请输入栏数:")
self.dialog.show()
self.WChild_zhalan.keyenter.clicked.connect(self.zhalan_w_Encrypto)
return 0
elif encrypt_type=='培根密码':
CODE_TABLE = { # 培根字典
'aaaaa': 'a', 'aaaab': 'b', 'aaaba': 'c', 'aaabb': 'd', 'aabaa': 'e', 'aabab': 'f', 'aabba': 'g',
'aabbb': 'h', 'abaaa': 'i', 'abaab': 'j', 'ababa': 'k', 'ababb': 'l', 'abbaa': 'm', 'abbab': 'n',
'abbba': 'o', 'abbbb': 'p', 'baaaa': 'q', 'baaab': 'r', 'baaba': 's', 'baabb': 't', 'babaa': 'u',
'babab': 'v', 'babba': 'w', 'babbb': 'x', 'bbaaa': 'y', 'bbaab': 'z'
}
str = text.lower()
listStr = ''
for i in str:
if i in CODE_TABLE.values():
# 将键、值各化为一个列表,取出i在value的位置后根据下标找到对应的键
listStr += list(CODE_TABLE.keys())[list(CODE_TABLE.values()).index(i)]
result_text = listStr.upper() # 大写输出
elif encrypt_type=='摩斯密码':
CODE = {'A': '.-', 'B': '-...', 'C': '-.-.',
'D': '-..', 'E': '.', 'F': '..-.',
'G': '--.', 'H': '....', 'I': '..',
'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---',
'P': '.--.', 'Q': '--.-', 'R': '.-.',
'S': '...', 'T': '-', 'U': '..-',
'V': '...-', 'W': '.--', 'X': '-..-',
'Y': '-.--', 'Z': '--..',
'0': '-----', '1': '.----', '2': '..---',
'3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..',
'9': '----.', '?': '..--..','/': '-..-.',
'()': '-.--.-','-': '-....-','.': '.-.-.-'
}
msg = ''
for char in text.upper() :
if char in CODE:
if char == ' ':
pass
else:
msg+=(CODE[char.upper()] + ' ')
else:
msg = '文本中含有不能识别的字符!'
result_text =msg
elif encrypt_type=='云影密码':
charList = [chr(i) for i in range(ord('A'), ord('Z') + 1)]
cipher = [i for i in text.upper()]
tmp = []
ret = []
for i in range(len(cipher)):
for j in range(len(charList)):
if charList[j] == cipher[i]:
tmp.append(j + 1)
for i in tmp:
res = ''
if i >= 8:
for j in range(0,int(i/8)):
res+= '8'
if i % 8 >= 4:
for j in range(0,int(i % 8 / 4)):
res+= '4'
if i % 4 >= 2:
for j in range(0,int(i % 4 / 2)):
res+= '2'
if i % 2 >= 1:
for j in range(0,int(i % 2 / 1)):
res+= '1'
ret.append(res + '0')
result_text= ''.join(ret)[:-1]
# print(result_text)
elif encrypt_type == '四方密码':
self.WChild = Ui_KEY2()
self.dialog = QtWidgets.QDialog(self)
self.WChild.setupUi(self.dialog)
self.dialog.setWindowTitle(encrypt_type)
self.WChild.key_1.setText("Key square 1:")
self.WChild.keyl_2.setText("Key square 2:")
self.dialog.show()
self.WChild.enter.clicked.connect(self.sifang_encrypt)
return
elif encrypt_type == '当铺密码':
mapping_data =[['田'], ['由'], ['中'], ['人'], ['工'], ['大'], ['王'], ['夫'], ['井'], ['羊']]
try:
result = []
for c in text:
c_list = mapping_data[int(c)]
c_index = random.randint(0, len(c_list) - 1)
result.append(c_list[c_index])
result_text = ''.join(result)
except:
result_text='未找到该字符串对应的中文!'
elif encrypt_type == '仿射密码':
self.WChild = Ui_KEY2()
self.dialog = QtWidgets.QDialog(self)
self.WChild.setupUi(self.dialog)
self.dialog.setWindowTitle(encrypt_type)
self.WChild.key_1.setText("a:")
self.WChild.keyl_2.setText("b:")
self.dialog.show()
self.WChild.enter.clicked.connect(self.fangshe_encrypt)
return
elif encrypt_type=='维吉尼亚密码':
self.WChild = Ui_KEY1()
self.dialog = QtWidgets.QDialog(self)
self.WChild.setupUi(self.dialog)
self.dialog.setWindowTitle(encrypt_type)
self.WChild.label.setText("Keyword:")
self.dialog.show()
self.WChild.keyenter.clicked.connect(self.VigenereEncrypto)
return 0
elif encrypt_type=='埃特巴什码':
str1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
str2 = "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA"
result_text = ""
for s in text:
if s in str1:
if s != ' ':
result_text = result_text + str2[str1.index(s)]
else:
result_text = result_text + ' '
else:
result_text = '埃特巴什码只能对英文字母加密!'
if result_text!="":
self.Ui.Result_text.setPlainText(result_text)
else:
self.Ui.Result_text.setPlainText('加密失败!')
except Exception as e :
self.Ui.Result_text.setPlainText(str(e))
# QMessageBox.critical(self,'Error',str(e))
# print(str(e))
pass
def zhalan_w_encode(self,string, n):
'''加密'''
array = self.generate_w(string, n)
msg = []
for row in range(n): # 将每行的字符连起来
for col in range(len(string)):
if array[row][col] != '.':
msg.append(array[row][col])
return array, msg
def generate_w(self,string, n):
'''将字符排列成w型'''
array = [['.'] * len(string) for i in range(n)] # 生成初始矩阵
row = 0
upflag = False
for col in range(len(string)): # 在矩阵上按w型画出string
array[row][col] = string[col]
if row == n - 1:
upflag = True
if row == 0:
upflag = False
if upflag:
row -= 1
else:
row += 1
return array
def VigenereEncrypto(self):
try:
self.dialog.close()
text = self.Ui.Source_text.toPlainText().strip().lower()
key = self.WChild.key.text()
ptLen = len(text)
keyLen = len(key)
if keyLen==0:
self.Ui.Result_text.setPlainText(str('请输入一个合法的key!'))
return 0
quotient = ptLen // keyLen #商
remainder = ptLen % keyLen #余
out = ""
for i in range (0 , quotient) :
for j in range (0 , keyLen) :
c = int((ord(text[i*keyLen+j]) - ord('a') + ord(key[j]) - ord('a')) % 26 + ord('a'))
#global output
out += chr (c)
for i in range (0 , remainder) :
c = int((ord(text[quotient*keyLen+i]) - ord('a') + ord(key[i]) - ord('a')) % 26 + ord('a'))
#global output
out += chr (c)
if out!='':
self.Ui.Result_text.setPlainText(out)
else:
self.Ui.Result_text.setPlainText('加密失败!')
except Exception as e :
self.Ui.Result_text.setPlainText(str(e))
def sifang_encrypt(self):
self.dialog.close()
try:
text = (self.Ui.Source_text.toPlainText().strip()).lower()
key1 = self.WChild.Key1.text().upper()
key2 = self.WChild.Key2.text().upper()
matrix = "ABCDEFGHIJKLMNOPRSTUVWXYZ"
pla = "abcdefghijklmnoprstuvwxyz"
key1 = '['+key1+"]"
key2 = '['+key2+"]"
key1 = ''.join(collections.OrderedDict.fromkeys(key1))
key2 = ''.join(collections.OrderedDict.fromkeys(key2))
matrix1 = re.sub('[\[\]]', '', key1) + re.sub(key1, '', matrix)
matrix2 = re.sub('[\[\]]', '', key2) + re.sub(key2, '', matrix)
matrix_list1 = []
matrix_list2 = []
pla_list = []
for i in range(0, len(matrix1), 5):
matrix_list1.append(list(matrix1[i:i + 5]))
for i in range(0, len(matrix2), 5):
matrix_list2.append(list(matrix2[i:i + 5]))
for i in range(0, len(pla), 5):
pla_list.append(list(pla[i:i + 5]))
pla = text.replace(' ', '')
if len(pla) % 2 != 0:
pla += 'x'
cip = ""
for i in range(0, len(pla), 2):
data = pla[i:i + 2]
# 两个子母中第一个字母位置
first = self.find_index(data[0],pla_list)
# 两个子母中第二个字母位置
second = self.find_index(data[1],pla_list)
return_cip = ""
return_cip += matrix_list1[first[0]][second[1]]
return_cip += matrix_list2[second[0]][first[1]]
cip += return_cip
if cip != '':
self.Ui.Result_text.setPlainText(cip)
else:
self.Ui.Result_text.setPlainText('加密失败!')
except Exception as e:
# print(str(e))
pass
def gcd(self,a, b):
if (a < b):
t = a
a = b
b = t
while (0 != b):
t = a
a = b
b = t % b
return a
def fangshe_encrypt(self):
self.dialog.close()
try:
letter_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" # 字母表
text = (self.Ui.Source_text.toPlainText().strip())
key1 = self.WChild.Key1.text()
key2 = self.WChild.Key2.text()
# print(text,key2,key1)
try:
if (0 == int(key1.isdigit()) or 0 == int(key2.isdigit())):
self.Ui.Result_text.setPlainText('输入有误! 密钥为数字。')
if (self.gcd(int(key1),26)!=1):
self.Ui.Result_text.setPlainText('输入有误! key1和26必须互素。')
return 0
except:
self.Ui.Result_text.setPlainText('输入有误!')
else:
ciphertext = ""
for ch in text: # 遍历明文
if ch.isalpha(): # 明文是否为字母,如果是,则判断大小写,分别进行加密
if ch.isupper():
ciphertext += letter_list[(int(key1) * (ord(ch) - 65) + int(key2)) % 26]
else:
ciphertext += letter_list[(int(key1) * (ord(ch) - 97) + int(key2)) % 26].lower()
else: # 如果密文不为字母,直接添加到密文字符串里
ciphertext += ch
self.Ui.Result_text.setPlainText(ciphertext)
except Exception as e:
self.Ui.Result_text.setPlainText('加密失败!')
# print(str(e))
pass
# 查询明文字母位置
def find_index(self,x,pla_list):
for i in range(len(pla_list)):
for j in range(len(pla_list[i])):
if pla_list[i][j] == x:
return i, j
def zhalan_w_Encrypto(self):
self.dialog.close()
plain = self.Ui.Source_text.toPlainText().strip()
try:
array,msg = self.zhalan_w_encode(plain,int(self.WChild_zhalan.key.text()))
except Exception as e:
self.Ui.Result_text.setPlainText(str(e))
return
self.Ui.Result_text.setPlainText(''.join(msg))
# for i in array: print(i)
# print(''.join(msg))
def zhalanEncrypto(self):
self.dialog.close()
plain = self.Ui.Source_text.toPlainText().strip()
try:
n = int(self.WChild_zhalan.key.text())
ans = ''
for i in range(n):
for j in range(int(plain.__len__() / n + 0.5)):
try:
ans += plain[j * n + i]
except:
pass
except:
ans = "请输入正确的分组!"
if ans != '':
self.Ui.Result_text.setPlainText(ans)
else:
self.Ui.Result_text.setPlainText('加密失败!')
#decrypt
def decrypt(self,decrypt_type):
try:
result_text=''
# print(decrypt_type)
text = self.Ui.Source_text.toPlainText().strip()
if text=='':
self.Ui.Result_text.setPlainText('请输入一个源字符串!')
return 0
if decrypt_type == 'Rot13':
PAIRS= {
"a": "n", "b": "o", "c": "p", "d": "q", "e": "r",
"f": "s", "g": "t", "h": "u", "i": "v", "j": "w",
"k": "x", "l": "y", "m": "z", "n": "a", "o": "b",
"p": "c", "q": "d", "r": "e", "s": "f", "t": "g",
"u": "h", "v": "i", "w": "j", "x": "k", "y": "l",
"z": "m", "A": "N", "B": "O", "C": "P", "D": "Q",
"E": "R", "F": "S", "G": "T", "H": "U", "I": "V",
"J": "W", "K": "X", "L": "Y", "M": "Z", "N": "A",
"O": "B", "P": "C", "Q": "D", "R": "E", "S": "F",
"T": "G", "U": "H", "V": "I", "W": "J", "X": "K",
"Y": "L", "Z": "M"
}
result_text = "".join(PAIRS.get(c, c) for c in text)
elif decrypt_type == '凯撒密码':
t = ""
for c in text:
if 'a' <= c <= 'z': # str是可以直接比较的
t += chr(ord('a') + ((ord(c) - ord('a')) -3) % 26)
elif 'A' <= c <= 'Z':
t += chr(ord('A') + ((ord(c) - ord('A')) - 3) % 26)
else:
t += c
result_text=t
elif decrypt_type == '栅栏密码':
factors = [fac for fac in range(2, len(text)) if len(text) % fac == 0] # 取得密文长度的所有因数
for fac in factors:
flag = ''
for i in range(fac): # 按一定的步长取几组字符,并连接起来,这里组数就等于步长数
flag += text[i::fac]
result_text+="分为%s栏,解密结果为:%s\n"%(fac,flag)
elif decrypt_type == '栅栏密码(W型)':
for n in range(2, len(text)): # 遍历所有可能的栏数
# print(str(n) + '栏:' + ''.join(self.zhanlan_w_decode(text, n)[1]))
result_text+="分为%s栏,解密结果为:%s\n"%(str(n),''.join(self.zhanlan_w_decode(text, n)[1]))
elif decrypt_type == '培根密码':
return_str = ''
dicts = {'aabbb': 'H', 'aabba': 'G', 'baaab': 'R', 'baaaa': 'Q', 'bbaab': 'Z', 'bbaaa': 'Y',
'abbab': 'N',
'abbaa': 'M', 'babaa': 'U', 'babab': 'V', 'abaaa': 'I', 'abaab': 'J', 'aabab': 'F',
'aabaa': 'E',
'aaaaa': 'A', 'aaaab': 'B', 'baabb': 'T', 'baaba': 'S', 'aaaba': 'C', 'aaabb': 'D',
'abbbb': 'P',
'abbba': 'O', 'ababa': 'K', 'ababb': 'L', 'babba': 'W', 'babbb': 'X'}
sums = len(text)
j = 5 ##每5个为一组
for i in range(int(sums / j)):
result = text[j * i:j * (i + 1)].lower()
return_str+=str(dicts[result],)
result_text=return_str
elif decrypt_type == '摩斯密码':
dict = {'.-': 'A','-...': 'B','-.-.': 'C','-..': 'D',
'.': 'E','..-.': 'F','--.': 'G','....': 'H',
'..': 'I','.---': 'J','-.-': 'K','.-..': 'L',
'--': 'M','-.': 'N','---': 'O','.--.': 'P',
'--.-': 'Q','.-.': 'R','...': 'S','-': 'T',
'..-': 'U','...-': 'V', '.--': 'W','-..-': 'X',
'-.--': 'Y','--..': 'Z','.----': '1','..---': '2',
'...--': '3','....-': '4','.....': '5', '-....': '6',
'--...': '7', '---..': '8','----.': '9','-----': '0',
'..--..': '?','-..-.': '/', '-.--.-': '()','-....-': '-',
'.-.-.-': '.'
}
msg = ''
s= text.split(' ')
for item in s:
if item!=''and item!=' ':
msg += (dict[item])
result_text = msg
elif decrypt_type == '移位密码':
inputStr = text
#
result=''
for j in range(26):
result_list = []
for i, num in zip(inputStr, range(len(inputStr))):
#print(i)
if i.islower:
caseS1 = string.ascii_lowercase * 2
if i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
caseS1 = string.ascii_uppercase * 2
status = caseS1.find(i)
if status != -1:
result_list.append(caseS1[status + j])
else:
result_list.append(inputStr[num])
text2=("".join(result_list), "向右偏移了{}位".format(j))
result+= text2[0]+' '+text2[1]+'\n'
result_text =result
elif decrypt_type == '云影密码':
other_letters = []
for s in text:
if not ['0','1','2','4','8'].count(s):
other_letters.append(s)
if other_letters:
result_text='加密字符串内只能包含0、1、2、4、8'
else:
charList = [chr(i) for i in range(ord('A'), ord('Z') + 1)]
ret = []
plaintext = [i for i in text.split('0')]
for i in plaintext:
tmp = 0
for j in range(len(i)):
tmp += int(i[j])
ret.append(charList[tmp - 1])
result_text= ''.join(ret)
elif decrypt_type == '当铺密码':
mapping_data ={'田': 0, '由': 1, '中': 2, '人': 3, '工': 4, '大': 5, '王': 6, '夫': 7, '井': 8, '羊': 9}
result_text = ''.join(map(lambda x: str(mapping_data[x]), text))
elif decrypt_type == '四方密码':
self.WChild = Ui_KEY2()
self.dialog = QtWidgets.QDialog(self)
self.WChild.setupUi(self.dialog)
self.dialog.setWindowTitle(decrypt_type)
self.WChild.key_1.setText("Key square 1:")
self.WChild.keyl_2.setText("Key square 2:")
self.dialog.show()
self.WChild.enter.clicked.connect(self.sifang_decrypt)
return 0
elif decrypt_type == '仿射密码':
self.WChild = Ui_KEY2()
self.dialog = QtWidgets.QDialog(self)
self.WChild.setupUi(self.dialog)
self.dialog.setWindowTitle(decrypt_type)
self.WChild.key_1.setText("a:")
self.WChild.keyl_2.setText("b:")
self.dialog.show()
self.WChild.enter.clicked.connect(self.fangshe_decrypt)
return 0
elif decrypt_type == '维吉尼亚密码':
self.WChild = Ui_KEY1()
self.dialog = QtWidgets.QDialog(self)
self.WChild.setupUi(self.dialog)
self.dialog.setWindowTitle(decrypt_type)
self.WChild.label.setText("Keyword:")
self.dialog.show()
self.WChild.keyenter.clicked.connect(self.VigenereDecrypto)
return 0
elif decrypt_type=='埃特巴什码':
str1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
str2 = "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA"
result_text = ""
for s in text:
if s != ' ':
result_text = result_text + str1[str2.index(s)]
else:
result_text = result_text + ' '
if result_text!="":
self.Ui.Result_text.setPlainText(result_text)
else:
self.Ui.Result_text.setPlainText('解密失败!')
except Exception as e :
self.Ui.Result_text.setPlainText(str(e))
# QMessageBox.critical(self,'Error',str(e))
pass
# print(str(e))
def VigenereDecrypto(self):
try:
self.dialog.close()
letter_list = string.ascii_uppercase
letter_list2 = string.ascii_lowercase
message = self.Ui.Source_text.toPlainText().strip()
key = self.WChild.key.text()
if len(key)==0:
self.Ui.Result_text.setPlainText(str('请输入一个合法的key!'))
return 0
key_list = []
for i in key:
key_list.append(ord(i.upper()) - 65)
plaintext = ""
flag = 0
for cipher in message: