-
Notifications
You must be signed in to change notification settings - Fork 10
/
crypto_puzzles.py
executable file
·2214 lines (1849 loc) · 80.2 KB
/
crypto_puzzles.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 python3
# crypto puzzles
# encryption for fun, never use for anything serious!
# Use utf8 save editor/IDE because it contains emoji
# Copyright 2020 Arnim Rupp
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import sys
import codecs
import pyqrcode
import random
import argparse
import upsidedown
import re
import roman
import base64
from pyfiglet import Figlet
from string import ascii_lowercase
from collections import defaultdict
from PIL import Image
from math import sqrt
vowels = list('aeiou')
consonants=list("bcdfghjklmnpqrstvwxyz")
# most difficult level
max_grade=13
# Emoji alphabet
# Beware, emoji look different depending on the plattform so only choose ones, where the character can be
# recognized everywhere
# seperate by comas because grapheme cluster support in python sucks, see https://hsivonen.fi/string-length/
# goal: have multiple options for common letters (ensirat) + don't use upside down because that's another function
# while editing, beware of the right to left characters ;)
emoji_letter={}
emoji_letter['a'] ='🅰️,ค,🃑,₳,ꬃ' # small ⎃ ?
emoji_letter['b'] ='🅱️,฿,𝔅,ᛒ,ℬ,ط'
emoji_letter['c'] ='©️,☪️,¢,℃' # too smal in some fonts: 🂬,𝄴,ᆮ
emoji_letter['d'] ='🌛,ԃ,Đ'
emoji_letter['e'] ='€,∈,📧,ℰ,モ' # 💶
emoji_letter['f'] ='℉,🎏,ƒ,₣,ᚩ'
emoji_letter['g'] ='Ⓖ,Ǥ,ﻮ,Ꮆ,₲'
emoji_letter['h'] ='♓,ℏ,ዙ,ᚺ'
emoji_letter['i'] ='ℹ️,🕕,𝔦,⌶,ï,༐'
emoji_letter['j'] ='⤴️,🕙,ɉ,ʝ,𝔧,ڸ' # too small in some fonts 🃛
emoji_letter['k'] ='Ⓚ,₭,㉿,ᛕ' # too small 🃞
emoji_letter['l'] ='👢,🕒,🛴,Ⱡ,ட' # 💷
emoji_letter['m'] ='♏,〽️,Ⓜ️,ℳ,₥,𝔐,ற,ᛖ'
emoji_letter['n'] ='♑,ℕ,И,🅽,ŋ,ᾗ,₦'
emoji_letter['o'] ='⭕,🍩,💍,𝔬'
emoji_letter['p'] ='🅿️,₱,🆊,₱,₽,𝔭,ᚹ'
emoji_letter['q'] ='Ǭ,Ɋ,𝔮' # too small 🂭
emoji_letter['r'] ='®️,Ȑ,Ɽ,ℜ,ℛ,ᚱ'
emoji_letter['s'] ='⚡,💲,💰,⑀,ى' # small 💵?
emoji_letter['t'] ='✝️,ƫ,ȶ,🆃,Ṭ,₮,𝔱,⍑,ァ,ኘ,ፖ'
emoji_letter['u'] ='ᶙ,⛎'
emoji_letter['v'] ='♈,✌'
emoji_letter['w'] ='〰️,₩,௰' # not like w on some systems: 🔱
emoji_letter['x'] ='❌,❎,⚒,🛠,⚔️,✖,⤫,𝔛,྾,ᚸ' # 🙅♀️ is bad because sometimes displayed as '🙅♀️♀️' in ubuntu (broken grapheme clustering?)
emoji_letter['y'] ='¥,💴,Ŷ,⑂,ℽ,Ỿ,Ӳ'
emoji_letter['z'] ='Ƶ,ʑ,ɀ,💤,ᶽ'
emoji_letter['ä'] ='Ἂ,Ȁ'
emoji_letter['ö'] ='ő,⍥,ȫ,Ӫ,ة'
emoji_letter['ü'] ='ű,Ǚ,ت'
emoji_letter['ß'] ='ẞ'
emoji_letter['1'] ='🥇,❶' #1️⃣ boring ... dice 1 ⚀ hard to recognize, very small ♳♴♵ ?
emoji_letter['2'] ='🥈,➁,🂲,⚁,ᆯ,༢' #2️⃣
emoji_letter['3'] ='🥉,ᗱ,⚂,༣' #3️⃣
emoji_letter['4'] ='4️⃣,ᔰ,🂴,⚃,༥'
emoji_letter['5'] ='5️⃣,Ƽ,🃅,⚄'
emoji_letter['6'] ='6️⃣,➅,🃖,⚅'
emoji_letter['7'] ='7️⃣,⑦,🂷,ㇴ'
emoji_letter['8'] ='∞,🎱,𝟠'
emoji_letter['9'] ='9️⃣,⑨'
emoji_letter['0'] ='🅾️,Ѳ' # 0️⃣
# might be too confusing?
#emoji_letter['10'] ='🔟'
#emoji_letter['11'] ='⓫'
# ...
#emoji_letter_multiple['100'] ='💯'
# domino, mahjong numbers also confusing: http://xahlee.info/comp/unicode_games_cards.html ?? for higher grades?
emoji_letter['*'] ='*️⃣✳️'
emoji_letter['#'] ='#️⃣'
emoji_letter['+'] ='➕'
emoji_letter['-'] ='➖'
#emoji_letter[':'] ='' # ???
emoji_letter['/'] ='/'
emoji_letter['!'] ='❕,❗️'
emoji_letter['?'] ='❓,�'
emoji_letter_multiple={}
# boooooring
#emoji_letter_multiple['ii'] ='ⅱ'
#emoji_letter_multiple['iv'] ='ⅳ'
#emoji_letter_multiple['vi'] ='ⅵ'
#emoji_letter_multiple['ⅶ'] ='ⅶ'
#emoji_letter_multiple['ix'] ='ⅸ'
#emoji_letter_multiple['xi'] ='ⅺ'
emoji_letter_multiple['sm'] ='℠'
emoji_letter_multiple['tm'] ='™️'
emoji_letter_multiple['!?'] ='⁉️'
emoji_letter_multiple['!!'] ='‼️'
emoji_letter_multiple['ab'] ='🆎,ab' # replace ab by ab = keep it to have some variety, the ab will then be processed like single letters
emoji_letter_multiple['ae'] ='ᴭ'
emoji_letter_multiple['fi'] ='fi,fi'
emoji_letter_multiple['fl'] ='fl,fl'
emoji_letter_multiple['cl'] ='🆑,cl'
emoji_letter_multiple['sos'] ='🆘,sos'
emoji_letter_multiple['vs'] ='🆚,vs'
emoji_letter_multiple['id'] ='🆔,id'
emoji_letter_multiple['ok'] ='🆗,ok'
emoji_letter_multiple['ng'] ='🆖,ng'
emoji_letter_multiple['abc'] ='🔤,abc'
emoji_letter_multiple['cool'] ='🆒,cool'
emoji_letter_multiple['free'] ='🆓,free'
emoji_letter_multiple['new'] ='🆕,new'
emoji_letter_multiple['atm'] ='🏧,atm'
emoji_letter_multiple['back'] ='🔙,back'
emoji_letter_multiple['end'] ='🔚,end'
emoji_letter_multiple['soon'] ='🔜,soon'
emoji_letter_multiple['top'] ='🔝,top'
emoji_letter_multiple['on'] ='🔛,on'
emoji_letter_multiple['tel'] ='℡,tel'
emoji_letter_multiple['ds'] ='𝄉,ds'
emoji_letter_multiple['dc'] ='𝄊,dc'
emoji_letter_multiple['tr'] ='𝆖,tr'
emoji_letter_multiple['aa'] ='⎂,aa'
emoji_letter_multiple['no'] ='№,no'
emoji_letter_multiple['rs'] ='₨,rs'
emoji_letter_multiple['ce'] ='₠,ce' # Œ
# booooring:
#emoji_letter_multiple['nm'] ='㎚'
#emoji_letter_multiple['mm'] ='㎜'
#emoji_letter_multiple['cm'] ='㎝'
#emoji_letter_multiple['km'] ='㎞' # ㏎
emoji_letter_multiple['ml'] ='㎖,ml'
emoji_letter_multiple['dl'] ='㎗,dl'
emoji_letter_multiple['kl'] ='㎘,kl'
#emoji_letter_multiple['cc'] ='㏄'
#emoji_letter_multiple['ps'] ='㎰'
#emoji_letter_multiple['ns'] ='㎱'
#emoji_letter_multiple['ms'] ='㎳'
#emoji_letter_multiple['mg'] ='㎎'
#emoji_letter_multiple['kg'] ='㎏'
#emoji_letter_multiple['kb'] ='㎅'
#emoji_letter_multiple['mb'] ='㎆' # ㏔
#emoji_letter_multiple['gb'] ='㎇'
#emoji_letter_multiple['hz'] ='㎐' # ㎑ ㎒ ㎓ shouldn't come up in normal words
emoji_letter_multiple['thz'] ='㎔'
#emoji_letter_multiple['pv'] ='㎴'
#emoji_letter_multiple['nv'] ='㎵'
#emoji_letter_multiple['mv'] ='㎷'
#emoji_letter_multiple['kv'] ='㎸'
#emoji_letter_multiple['mv'] ='㎹'
#emoji_letter_multiple['pw'] ='㎺'
#emoji_letter_multiple['nw'] ='㎻'
#emoji_letter_multiple['mw'] ='㎽' # ㎿
#emoji_letter_multiple['kw'] ='㎾'
#emoji_letter_multiple['pa'] ='㎀' # ㎩
#emoji_letter_multiple['na'] ='㎁'
#emoji_letter_multiple['ma'] ='㎃'
#emoji_letter_multiple['ka'] ='㎄'
emoji_letter_multiple['rad'] ='㎭'
emoji_letter_multiple['kpa'] ='㎪'
emoji_letter_multiple['mpa'] ='㎫'
emoji_letter_multiple['gpa'] ='㎬'
emoji_letter_multiple['cal'] ='㎈' # ㎉
#emoji_letter_multiple['dm'] ='dm'
emoji_letter_multiple['mil'] ='㏕'
#emoji_letter_multiple['fm'] ='㎙'
#emoji_letter_multiple['au'] ='㍳'
emoji_letter_multiple['db'] ='㏈'
#emoji_letter_multiple['ln'] ='㏑'
emoji_letter_multiple['log'] ='㏒'
emoji_letter_multiple['am'] ='㏂'
emoji_letter_multiple['pm'] ='㏘'
emoji_letter_multiple['hpa'] ='㍱'
#emoji_letter_multiple['da'] ='㍲'
emoji_letter_multiple['bar'] ='㍴'
#emoji_letter_multiple['ov'] ='㍵'
#emoji_letter_multiple['pc'] ='㍶'
#emoji_letter_multiple['IU'] ='㍺'
#emoji_letter_multiple['pf'] ='㎊'
#emoji_letter_multiple['nf'] ='㎋'
#emoji_letter_multiple['bq'] ='㏃'
#emoji_letter_multiple['cd'] ='㏅'
emoji_letter_multiple['co'] ='㏇'
#emoji_letter_multiple['gy'] ='㏉'
#emoji_letter_multiple['ha'] ='㏊'
emoji_letter_multiple['hp'] ='㏋'
emoji_letter_multiple['kk'] ='㏍'
#emoji_letter_multiple['kt'] ='㏏'
#emoji_letter_multiple['lm'] ='㏐'
#emoji_letter_multiple['lx'] ='㏓'
emoji_letter_multiple['mol'] ='㏖'
#emoji_letter_multiple['ph'] ='㏗'
#emoji_letter_multiple['pr'] ='㏚'
#emoji_letter_multiple['sr'] ='㏛'
#emoji_letter_multiple['sv'] ='㏜'
#emoji_letter_multiple['wb'] ='㏝'
emoji_letter_multiple['hu'] ='Ƕ'
#emoji_letter_multiple['dz'] ='DZ'
emoji_letter_multiple['oe'] ='œ'
emoji_letter_multiple['ts'] ='ʦ'
emoji_letter_multiple['dz'] ='ʥ'
emoji_letter_multiple['th'] ='ᵺ'
emoji_letter_multiple['ue'] ='ᵫ'
emoji_letter_multiple['ls'] ='ʪ'
emoji_letter_multiple['fn'] ='ʩ'
emoji_letter_multiple['lz'] ='ʫ'
emoji_letter_multiple['ww'] ='ʬ'
emoji_letter_multiple['le'] ='ᇉ' # korean
emoji_letter_multiple['lc'] ='ᇆ'
# too small: 𝆮 ?
############################################################
emoji_letter_xmas={}
emoji_letter_xmas['a'] ='🎄'
emoji_letter_xmas['b'] ='฿,𝔅,ᛒ,ℬ,ط'
emoji_letter_xmas['c'] ='¢,℃,𝄴'
emoji_letter_xmas['d'] ='🌛,ԃ,Đ'
emoji_letter_xmas['e'] ='€,∈,ℰ,モ'
emoji_letter_xmas['f'] ='℉,ƒ,₣,ᚩ'
emoji_letter_xmas['g'] ='Ⓖ,Ǥ,ﻮ,Ꮆ,₲'
emoji_letter_xmas['h'] ='ℏ,ዙ,ᚺ'
emoji_letter_xmas['i'] ='🕯️'
emoji_letter_xmas['j'] ='ɉ,ʝ,𝔧,ڸ'
emoji_letter_xmas['k'] ='Ⓚ,₭,㉿,ᛕ'
emoji_letter_xmas['l'] ='🕒,🛴,Ⱡ,ட'
emoji_letter_xmas['m'] ='ℳ,₥,𝔐,ற,ᛖ'
emoji_letter_xmas['n'] ='ℕ,И,🅽,ŋ,ᾗ,₦'
emoji_letter_xmas['o'] ='🍪,❄️ '
emoji_letter_xmas['p'] ='₱,₱,₽,𝔭,ᚹ'
emoji_letter_xmas['q'] ='Ǭ,Ɋ,𝔮'
emoji_letter_xmas['r'] ='Ȑ,Ɽ,ℜ,ℛ,ᚱ'
emoji_letter_xmas['s'] ='⑀,ى' # small 💵?
emoji_letter_xmas['t'] ='✝️'
emoji_letter_xmas['u'] ='ᶙ'
emoji_letter_xmas['v'] ='♈'
emoji_letter_xmas['w'] ='〰️,₩,௰' # not like w on some systems: 🔱
emoji_letter_xmas['x'] ='✖,⤫,𝔛,྾,ᚸ' # 🙅♀️ is bad because sometimes displayed as '🙅♀️♀️' in ubuntu (broken grapheme clustering?)
emoji_letter_xmas['y'] ='¥,Ŷ,⑂,ℽ,Ỿ,Ӳ'
emoji_letter_xmas['z'] ='Ƶ,ʑ,ɀ,💤,ᶽ'
############################################################
# Emoji animal alphabet, works in english and german
# include the disputed in a hard version someday
# if you find animal emoji for the missing letters, please tell me on github (see also emoji_animals_sorted.txt)
emoji_animal={}
emoji_animal['a'] ='🐜'
emoji_animal['b'] ='🐻'
#emoji_animal['c'] ='©️,☪️,¢,℃,🂬,𝄴,ᆮ'
emoji_animal['d'] ='🐬,🐉'
emoji_animal['e'] ='🐘'
emoji_animal['f'] ='🐟,🦊'
emoji_animal['g'] ='🦒'
emoji_animal['h'] ='🐹'
#emoji_animal['i'] ='ℹ️,🕕,𝔦,⌶,ï,༐'
#emoji_animal['j'] ='⤴️,🕙,ɉ,ʝ,🃛,𝔧,ڸ'
emoji_animal['k'] ='🦘 ,🐨'
emoji_animal['l'] ='🦁'
# recognizable?
#🐆 Leopard
#🦙 Llama, everybody would say alpaka I guess :)
emoji_animal['m'] ='🐁'
#emoji_animal['n'] ='♑,ℕ,И,🅽,ŋ,ᾗ,₦'
emoji_animal['o'] ='🐙'
emoji_animal['p'] ='🦜 ,🦚 ,🐧,🐩'
#emoji_animal['q'] ='Ǭ,Ɋ,🂭,𝔮'
emoji_animal['r'] ='🐀'
# rat is hard to distinguish from a mouse but the rhino is also hard in german because most people say nashorn
# 🦏 Rhinoceros
emoji_animal['s'] ='🦂,🐌,🐍,🕷️,🦢'
emoji_animal['t'] ='🐅,🦖'
# is the T-Rex recognizable? or just a "dino"?
#emoji_animal['u'] ='ᶙ,⛎'
#emoji_animal['v'] ='♈,✌'
emoji_animal['w'] ='🐋,🐺'
# 🐃 Water Buffalo, nobody would get this in german
#emoji_animal['x'] ='❌,❎,⚒,🛠,⚔️,✖,⤫,𝔛,྾,ᚸ' # 🙅♀️ is bad because sometimes displayed as '🙅♀️♀️' in ubuntu (broken grapheme clustering?)
#emoji_animal['y'] ='¥,💴,Ŷ,⑂,ℽ,Ỿ,Ӳ'
emoji_animal['z'] ='🦓'
number_words={}
# number words have to be in the right order and start with 0
number_words['de'] = ['null', 'eins','zwei','drei','vier','fünf','sechs','sieben','acht','neun','zehn', 'elf', 'zwölf']
number_words['en'] = ['zero', 'one','two','three','four','five','six','seven','eight','nine','ten', 'eleven', 'twelve']
symbol_words = {}
# .!?:-+$
symbol_words['de.'] = 'Punkt'
symbol_words['de!'] = 'Ausrufezeichen'
symbol_words['de?'] = 'Fragezeichen'
symbol_words['de:'] = 'Doppelpunkt'
symbol_words['de-'] = 'Minus'
symbol_words['de+'] = 'Plus'
symbol_words['de$'] = 'Dollar'
symbol_words['en.'] = 'dot'
symbol_words['en!'] = 'exclamation mark'
symbol_words['en?'] = 'question mark'
symbol_words['en:'] = 'colon'
symbol_words['en-'] = 'minus'
symbol_words['en+'] = 'plus'
symbol_words['en$'] = 'dollar'
animals = {}
animals['en'] = [
'ape',
'bird',
'lion',
'elephant',
'beaver',
'bunny',
'tiger',
'squirrel',
'stegosaurus',
'shark',
'carp',
'swallow',
'parrot',
'swan',
'snake',
'wasp',
'dolphin',
'leopard',
'hippo',
'raven',
'frog',
'butterfly',
]
animals['de'] = [
'affe',
'vogel',
'löwe',
'elefant',
'biber',
'hase',
'tiger',
'eichhörnchen',
'stegosaurus',
'hai',
'karpfen',
'schwalbe',
'papagei',
'schwan',
'kreuzotter',
'biene',
'delfin',
'leopard',
'nilpferd',
'rabe',
'frosch',
'schmetterling',
]
# todo: do the same with emoji (avoid emoji which might have 2+ fitting words)
alphabet_words = {}
alphabet_words['en'] = [
'antelop',
'bug',
'computer',
'dolphin',
'empire',
'fish',
'goose',
'hobbit',
'internet',
'jogger',
'kangaroo',
'lumber',
'mars',
'nose',
'orange',
'perfect',
'queen',
'ring',
'sabre',
'tunnel',
'under',
'vampire',
'wardrobe',
'xylophon',
'yellow',
'zebra',
]
alphabet_words['de'] = [
'ameise',
'blödelt',
'computer',
'der',
'ehrlich',
'fällt',
'gestern',
'hatschi',
'in',
'jetzt',
'kommt',
'laut',
'mindestens',
'nase',
'oder',
'perfekt',
'quatsch',
'reichlich',
'schön',
'toll',
'und',
'verspielt',
'weil',
'xylophon',
'yak',
'zaubert',
]
dotted_alphabet= "Ȧȧ Ḃḃ Ċċ Ḋḋ Ėė Ḟḟ Ġġ Ḣḣ Ịị Ⓙⓙ Ḳḳ Ḷḷ Ṁṁ Ṅṅ Ȯȯ Ṗṗ Ⓠⓠ Ṙṙ Ṡṡ Ṫṫ Ụụ Ṿṿ Ẇẇ Ẋẋ Ẏẏ Żż"
alphabet= list("abcdefghijklmnopqrstuvwxyz")
# alternate chars: Ạạ Ḅḅ Ḍḍ Ẹẹ Ḥḥ Ṃṃ Ṇṇ O͘o͘ Ọọ Ṛṛ Ṣṣ Ṭṭ Ẉẉ X̣x̣ Ỵỵ Ẓẓ
dotted_pairs = dotted_alphabet.split(' ')
dotted_char={}
for dotted_pair in dotted_pairs:
char = alphabet.pop(0)
upper = dotted_pair[0]
lower = dotted_pair[1]
# append a space after j and q because of wrong spacing (at least on the ubuntu terminal)
if char == 'j' or char == 'q':
append_space = ' '
else:
append_space = ''
dotted_char[char.upper()] = upper + append_space
dotted_char[char] = lower + append_space
def insert_noise(intext, language, grade=1, noise_type="", noise_chars=""):
# e.g. top secret => tRÖNFoRÖNFpRÖNFsRÖNFeRÖNFcRÖNFrRÖNFeRÖNFtRÖNF
outtext=""
hint=""
#if grade > 2:
# remove whitespace
#intext=intext.replace(' ', '')
for char in intext:
if char == ' ':
outtext = outtext + ' '
else:
outtext = outtext + char + get_noise(language, grade, noise_type, noise_chars)
return outtext, hint
def get_noise(language, grade, noise_type="", noise_chars=""):
noise=''
if noise_type == 'numberwords':
noise = number_words[language][random.randrange(len(number_words[language])-1)]
elif noise_type == 'numbers':
noise = str(random.randrange(99))
elif noise_type == 'specialchars':
choice=';:_-,.+*#!%&/()[]=|<>'
noise = choice[random.randrange(len(choice))]
elif noise_type == 'currency_symbols':
# chars which look very similar to normal chars
choice='$€¥₳₩₰₮₪฿£₱¢₣₲₭Ł₥₴'
noise = choice[random.randrange(len(choice))]
elif noise_type == 'animals':
noise = animals[language][random.randrange(len(animals[language])-1)]
elif noise_chars:
noise = noise_chars
else:
# if neither noise_type nor noise_chars is defined, pick something according to grade
if grade == 1:
noise = get_noise(language,grade, 'specialchars')
elif grade == 2:
noise="RÖNF"
elif grade == 3:
noise = get_noise(language,grade, 'numbers')
elif grade == 4 or grade == 5:
noise="rönf"
elif grade == 6:
noise = get_noise(language,grade, 'animals')
elif grade < 9:
# number words are harder because they're shorter
noise = get_noise(language,grade, 'numberwords')
elif grade < 11 :
# mix of animals and numbers
if random.randrange(2) == 1:
noise = get_noise(language,grade, 'numberwords')
else:
noise = get_noise(language,grade, 'animals')
else:
# mix of animals, numbers, ...
dice = random.randrange(3)
if dice == 0:
noise = get_noise(language,grade, 'numberwords')
elif dice == 1:
noise = get_noise(language,grade, 'animals')
else:
noise = get_noise(language,grade, 'currency_symbols')
return noise
def randomize_middle_of_words(intext, language, grade=1):
# top secret => top screet, top sercet, ...
outtext=""
hint=""
words=intext.split()
for word in words:
rword = randomize_middle_of_one_word(word, grade)
outtext = outtext + rword + ' '
return outtext.rstrip(' '), hint
def randomize_middle_of_one_word(word, grade):
rword=""
count=0
# don't start for words with 3 chars because it won't change
if len(word) > 3:
# repeat if rword by random chance equals word
# have a maximum of count iterations to avoid endless loops on words with equal chars in the middle like "tool" or "wooooot"
while (word == rword or not rword) and count < 10:
count += 1
chars=list(word)
rword=chars.pop(0)
# keep chars in beginning of word intact depending on word length and grade
if grade < 4:
rword += chars.pop(0)
if len(chars) > 7:
rword += chars.pop(0)
if len(chars) > 9:
rword += chars.pop(0)
if len(chars) > 11:
rword += chars.pop(0)
# for German and Finnish :)
if len(chars) > 12:
rword += chars.pop(0)
if grade < 8 and len(chars) > 8:
rword += chars.pop(0)
while len(chars) > 1:
rword += chars.pop(random.randrange(len(chars)-1))
rword = rword + chars[0]
return rword
else:
return word
def upside_down(text, language, grade, upside_down_rate=0):
# top secret => doʇ ʇǝɹɔǝs
# todo: keep punctuation marks in place? at the moment it's dOʇ ¡⊥ǝᴚɔƎs, would dOʇ ⊥ǝᴚɔƎs¡ be better/easier for lower grades? (code in shift_words)
if grade == 1:
upside_down_rate = 1
else:
upside_down_rate = 2
#print(grade, upside_down_rate)
# todo: fix upstream (but that might need some time, until it's in pypi)
# workaround for chars not properly displayed on QR reader of iOS 13.4.1 (works also fine on android 8.1.0 patchlevel april 2020)
text = text.replace('Ü', 'ü') # lowercase ü works (introduce orthographic errors!!! ;)
# Q => Ꝺ doesn't work on iOS but didn't find a good replacement yet
text = text.replace('Q', 'q') # lowercase q works (introduce orthographic errors!!! ;)
words=text.split()
count=0
outtext=""
hint=""
for word in words:
count += 1
if grade > 4:
word, hint = insert_noise(word, language, 1)
if count/upside_down_rate == int(count/upside_down_rate):
rword = upsidedown.transform(word)
else:
rword= word
outtext = outtext + rword + " "
#print(rword, end=" ")
# todo: fix upstream (but that might need some time, until it's in pypi)
# workaround for chars not properly displayed on QR reader of iOS 13.4.1
outtext = outtext.replace('ꞁ', '|') # l
outtext = outtext.replace('Ꞁ', '˥') # L
# nicer k
outtext = outtext.replace('⋊', 'ʞ') # k
outtext += " 🙃 "
return outtext, hint
def repl(x):
replacements.append(x.group(1))
return ''
def reichify(wort, grade):
wort_org=wort
# remove punctuation marks (and restore them later)
#replacements = []
wort_org = re.sub('([\.,:;])$', repl, wort_org)
# aber => aba
if len(wort_org) > 3:
wort = re.sub('er$', 'a', wort)
if 'tzt' in wort_org:
wort = wort.replace('tzt','ts')
elif 'tz' in wort_org:
wort = wort.replace('tz','ts')
# dehnungs-h raus
if 'hm' in wort_org and not 'chm' in wort_org:
wort = wort.replace('hm','m')
if 'hn' in wort_org and not 'chn' in wort_org:
wort = wort.replace('hn','n')
if 'hr' in wort_org and not 'chr' in wort_org:
wort = wort.replace('hr','r')
if 'hl' in wort_org and not 'chl' in wort_org:
wort = wort.replace('hl','l')
if 'ht' in wort_org and not 'cht' in wort_org:
wort = wort.replace('ht','t')
if grade > 2:
if 'sch' in wort_org:
wort = wort.replace('sch','ch')
elif 'ch' in wort_org:
wort = wort.replace('ch','sch')
if 'ie' in wort_org:
wort = wort.replace('ie','i')
if 'ei' in wort_org:
wort = wort.replace('ei','ai')
elif 'ai' in wort_org:
wort = wort.replace('ai','ei')
elif 'e' in wort_org:
wort = wort.replace('e','ä', 1)
if grade > 4:
if 'äu' in wort_org:
würfel=random.randint(1,6)
if würfel < 3:
wort = wort.replace('äu','oi')
elif würfel > 4:
wort = wort.replace('äu','eu')
else:
wort = wort.replace('äu','öj')
elif 'ä' in wort_org:
wort = wort.replace('ä','e')
if grade > 2:
# doppelte raus
wort = re.sub('(.)\\1', '\\1', wort)
if 'ck' in wort_org:
wort = wort.replace('ck','k')
if grade > 5:
if 'b' in wort_org:
wort = wort.replace('b','p')
elif 'p' in wort_org:
wort = wort.replace('p','b')
if grade > 3:
if 'st' in wort_org:
wort = wort.replace('st','schd')
elif 't' in wort_org:
wort = wort.replace('t','d')
# d in artikeln lassen
elif 'd' in wort_org and (len(wort_org) > 3 or re.search('d$', wort_org)):
wort = wort.replace('d','t', 1)
if grade > 2:
if 'g' in wort_org:
wort = wort.replace('g','k')
elif 'k' in wort_org:
wort = wort.replace('k','g')
if 'qu' in wort_org:
wort = wort.replace('qu','kw')
if 'v' in wort_org:
wort = wort.replace('v','f')
elif 'f' in wort_org:
wort = wort.replace('f','v')
if 'y' in wort_org:
wort = wort.replace('y','i')
wort = re.sub('x', 'ks', wort)
# fvb spezial
if wort_org == 'baby':
wort = 'bebi'
# großschreibung zufällig
if random.randint(1,6) == 1:
wort = wort.title()
if replacements:
wort = wort + replacements.pop()
return wort
def lässn_tursch_chraipen(intext, language, grade):
# special German encryption, ignore if you're not from Germany ;)
# streng geheim => schdränk Kehaim
# list for use in repl function in re.sub later
global replacements
replacements = []
wörter=intext.lower().split(' ')
outtext=""
hint=""
for wort in wörter:
reichen_wort = reichify(wort, grade)
outtext = outtext + reichen_wort + ' '
return outtext.rstrip(' '), hint
def leet(text, language, grade):
hint=""
text = text.replace('o','0')
text = text.replace('O','0')
text = text.replace('s','$')
text = text.replace('E','€')
text = text.replace('i','1')
if grade > 3:
text = text.replace('f','ph')
text = text.replace('a','@')
text = text.replace('e','3')
return text, hint
def wrong_whitespace(intext, language, grade):
# top secret => to pse cret
if grade > 5:
# make it harder by mirroring the words (at grade 1)
intext, hint = mirror_words(intext, language, 1)
words=intext.split()
outtext=""
hint=""
for word in words:
if grade == 1:
# uppercase original first char to make it easier
word=word.title()
if grade == 1:
# just remove spaces, don't insert wrong ones
# top secret => topsecret
outtext += word
else:
if len(word) == 1:
outtext += word
elif len(word) == 2:
outtext += word[0] + ' ' + word[1]
else:
cut = 1 + random.randrange(len(word)-1)
outtext += word[:cut]
outtext +=' '
if grade > 4:
# uppsercase wrong first chars of words for additional confusion
# top secret => to Pse Cret
outtext += word[cut:].title()
else:
outtext += word[cut:]
return outtext, hint
def mirror_words(intext, language, grade):
# top secret => pot terces
words=intext.split()
outtext=""
hint=""
for word in words:
outtext += word[::-1] + ' '
if grade > 5:
# insert noise with reduced grade
outtext, hint = insert_noise(outtext, language, grade -5)
return outtext.rstrip(' '), hint
def shift_words(intext, language, grade):
# top secret => pto ecrets
words=intext.split()
outtext=""
hint=""
# list for use in repl function in re.sub later
global replacements
replacements = []
for word in words:
# store punctuation marks in replacements to avoid also shifting them, will be appended in the end
word = re.sub('([\.,:;!?])$', repl, word)
if grade < 3:
outtext += word[1:] + word[0]
else:
outtext += word[2:] + word[0:2]
if replacements:
outtext += replacements.pop()
outtext += ' '
outtext = outtext.rstrip(' ')
# make harder
if grade > 4:
outtext, hint_dummy = camelcase(outtext, language, 1)
if grade > 7:
# insert noise with reduced grade
outtext, hint = insert_noise(outtext, language, grade -7 )
return outtext, hint
def camelcase(intext, language, grade):
# top secret => tOp sEcReT
outtext=""
hint=""
up=0
for char in intext:
if up == 1:
up=0
outtext += char.upper()
else:
up=1
outtext += char.lower()
return outtext.rstrip(' '), hint
def get_textfile(language):
if language == 'de':
# TODO: fix dirs for direct & lib from euli
textfile = 'data/unfug'
#textfile = 'crypto_puzzles/data/unfug'
elif language == 'en':
textfile = 'data/platitudes'
#textfile = 'crypto_puzzles/data/platitudes'
else:
print("sorry, other languages not supported yet in uppercase_chars_in_text")
sys.exit()
return textfile
def get_jokes(language):
textfile = get_textfile(language)
jokes = []
buffer=""
try:
with open(textfile, 'r') as file:
lines = file.read().splitlines()
except Exception as e:
print(f"unable to read textfile: {textfile} - error: {e} - language: {language}")
sys.exit()
for line in lines:
# regex is to avoid names under quotes because they're too hard to spot errors for misspelling_in_text()
if line and ( line[0] == '#' or re.search(r'\s\s-- ', line )):
pass
elif line == '%':
jokes.append(buffer)
buffer=""
else:
buffer += line + "\n"
return jokes
def next_char(intext_chars):
# all chars of intext done?
if not len(intext_chars):
done=True
char=''
else:
done=False
char = intext_chars.pop(0)
return char, intext_chars, done
def misspelling_in_text(intext, language, grade):
# only misspelled chars (the real chars which would be there without the error) in random text contain message:
# top secret => Xhe rfof was very jlain with frelh ...
# replace 1,2, ... with one, two, ...
intext = convert_num_to_number_words(intext, language)
intext = convert_symbols_to_words(intext, language)
jokes = []
jokes = get_jokes(language)
outtext=""
hint=""
up=0
# for the low grades replace with char which should mostly be easy to spot as an error.
if language == 'en':
replace_chars=list("qxvzwjpc")
elif language == 'de':
replace_chars=list("qxvzwjpcy")
else:
replace_chars=list("qxvzwjpc")
if grade >= 8:
replace_chars=list("abcdefghijklmnopqrstuvwxyz")
done=False
intext_chars = list(intext)
char, intext_chars, done = next_char(intext_chars)
while not done:
joke = random.choice(jokes)
if char in dotted_char:
while char not in joke:
joke = random.choice(jokes)
else:
outtext += char + '\n'
outtext += "------------------------------\n"
char, intext_chars, done = next_char(intext_chars)
continue
finish_this_one=False
keep_correct = 0
for joke_char in joke:
# avoid misspellings directly one after another, because that would be impossible to figure out, especially if randomly the same common word like e.g. and, or, the, ... would be in ciphertext and joke
if keep_correct:
outtext += joke_char
# countdown until 0
keep_correct -= 1
elif done or finish_this_one:
# all characters in, just append rest of joke
outtext += joke_char
elif joke_char == char:
replacement_char = ''
while len(replacement_char) != 1:
replacement_char = random.choice(replace_chars)
if grade < 10:
# avoid replacing a vowel with a vowel because the probability is to high to change to another existing word which then can't be spotted as an error, e.g. post => past
# grades 10+ could figure it out from the nonsense word in the context or just guess the missing char
if char in vowels and replacement_char in vowels:
replacement_char = ''
# if original char was uppercase then also uppercase replaced char
if char.upper() == char:
replacement_char = replacement_char.upper()
outtext += replacement_char
keep_correct = max_grade + 1 - grade
char, intext_chars, done = next_char(intext_chars)
if char not in dotted_char:
finish_this_one=True
else: