|
31 | 31 | 'dec(gronsfeld-cipher-31415)': {'DUXBHNBXEFZO': 'ATTACKATDAWN'}, |
32 | 32 | 'enc-dec(gronsfeld-0|gronsfeld-12345|gronsfeld-9)': ['hello world', 'ATTACK AT DAWN', 'Test 1234!'], |
33 | 33 | } |
| 34 | +__examples6__ = { |
| 35 | + 'enc(porta)': None, |
| 36 | + 'enc(porta-fortification)': {'DEFENDTHEEASTWALLOFTHECASTLE': 'SYNNJSCVRNRLAHUTUKUCVRYRLANY'}, |
| 37 | + 'dec(porta_cipher-fortification)': {'SYNNJSCVRNRLAHUTUKUCVRYRLANY': 'DEFENDTHEEASTWALLOFTHECASTLE'}, |
| 38 | + 'enc(porta-key)': {'Hello World': 'Ztxqm Kjcxv'}, |
| 39 | + 'enc-dec(porta-secret)': ['hello world', 'ATTACK AT DAWN', 'Test 1234!'], |
| 40 | +} |
34 | 41 | __examples3__ = { |
35 | 42 | 'enc(trithemius-cipher)': {'this is a test': "tikv mx g ambd"}, |
36 | 43 | 'enc(trithemius)': {'HELLO': "HFNOS", '12345!@#$': "12345!@#$"}, |
|
46 | 53 | __guess1__ = ["autoclave-key", "autoclave-password", "autoclave-secret"] |
47 | 54 | __guess2__ = ["beaufort-key", "beaufort-password", "beaufort-secret"] |
48 | 55 | __guess3__ = ["trithemius"] |
| 56 | +__guess6__ = ["porta-key", "porta-password", "porta-secret"] |
49 | 57 | __guess5__ = ["gronsfeld-1234", "gronsfeld-12345", "gronsfeld-123456"] |
50 | 58 | __guess4__ = ["vigenere-key", "vigenere-password", "vigenere-secret"] |
51 | 59 |
|
|
56 | 64 | [1, -1][d] * (ord(k[i % len(k)]) - ord('a'))) % 26] |
57 | 65 |
|
58 | 66 |
|
| 67 | +def pchar(c, k, i, d=False): |
| 68 | + """ Porta: the key letters pairs (AB, CD, ..., YZ) select one of 13 reciprocal alphabets swapping the halves A-M |
| 69 | + and N-Z ; hence, decoding is the same as encoding. """ |
| 70 | + alph, s, x = LC if c in LC else UC, (ord(k[i % len(k)]) - ord('a')) // 2, ord(c.lower()) - ord('a') |
| 71 | + return alph[13 + (x + s) % 13 if x < 13 else (x - 13 - s) % 13] |
| 72 | + |
| 73 | + |
59 | 74 | def __make(enc, char_func, key_stream=False, key_desc="alphabetic"): |
60 | 75 | def _code(decode=False): |
61 | 76 | def _wrapper(key): |
@@ -100,6 +115,9 @@ def _wrapper(key=None): |
100 | 115 | add("gronsfeld", *map(__gronsfeld, __make("gronsfeld", vchar, key_desc="numeric")), |
101 | 116 | r"gronsfeld(?:[-_]cipher)?(?:[-_]([0-9]+))?$", examples=__examples5__, guess=__guess5__, penalty=.1) |
102 | 117 |
|
| 118 | +add("porta", *__make("porta", pchar), r"porta(?:[-_]cipher)?(?:[-_]([a-zA-Z]+))?$", |
| 119 | + examples=__examples6__, guess=__guess6__, penalty=.1) |
| 120 | + |
103 | 121 | add("trithemius", enc(k := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), dec(k), r"trithemius(?:[-_]cipher)?$", |
104 | 122 | examples=__examples3__, guess=__guess3__, penalty=.1) |
105 | 123 |
|
|
0 commit comments