File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44from .bacon import *
55from .barbie import *
66from .citrix import *
7+ from .polybius import *
78from .railfence import *
89from .rot import *
910from .scytale import *
Original file line number Diff line number Diff line change 1+ # -*- coding: UTF-8 -*-
2+ """Polybius Square Codec - polybius-square content encoding.
3+
4+ The Polybius square is a method for fractionating plaintext characters so that
5+ they can be represented by a smaller set of symbols. Each letter is represented
6+ by its coordinates (row, column) in the 5×5 grid.
7+
8+ This codec:
9+ - en/decodes strings from str to str
10+ - en/decodes strings from bytes to bytes
11+ - decodes file content to str (read)
12+ - encodes file content from str to bytes (write)
13+
14+ Reference: https://en.wikipedia.org/wiki/Polybius_square
15+ """
16+ from ..__common__ import *
17+
18+
19+ __examples__ = {
20+ 'enc(polybius|polybius-square|polybius_square)' : {
21+ 'this is a test' : "44232443 2443 11 44154344" ,
22+ 'jack' : "24111325" ,
23+ },
24+ 'dec(polybius)' : {
25+ '44232443 2443 11 44154344' : "THIS IS A TEST" ,
26+ },
27+ }
28+ __guess__ = ["polybius-square" ]
29+
30+
31+ # Standard 5×5 Polybius square (I and J share the same cell):
32+ # 1 2 3 4 5
33+ # 1 A B C D E
34+ # 2 F G H I K
35+ # 3 L M N O P
36+ # 4 Q R S T U
37+ # 5 V W X Y Z
38+ _ALPHABET = "ABCDEFGHIKLMNOPQRSTUVWXYZ"
39+ ENCMAP = {_ALPHABET [i ]: str (i // 5 + 1 ) + str (i % 5 + 1 ) for i in range (25 )}
40+ ENCMAP ['J' ] = ENCMAP ['I' ]
41+ ENCMAP [' ' ] = ' '
42+
43+
44+ add_map ("polybius-square" , ENCMAP , ignore_case = "both" ,
45+ pattern = r"^(?:polybius(?:[-_]square)?)$" , printables_rate = 1. ,
46+ expansion_factor = (1.85 , .15 ))
You can’t perform that action at this time.
0 commit comments