-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrevanion_cipher.py
More file actions
34 lines (25 loc) · 1.52 KB
/
trevanion_cipher.py
File metadata and controls
34 lines (25 loc) · 1.52 KB
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
"""A module for decrypting punctuation-based null ciphers."""
import string
def decrypt_message(message: str, key: int) -> str:
"""Decrypt a null cipher by extracting the nth character after punctuation."""
message = message.replace(" ", "")
punc = string.punctuation
secret_message = ""
for i, char in enumerate(message):
if (
char in punc
and (i + key) < len(message)
and not any(c in punc for c in message[i + 1 : i + key])
):
secret_message += message[i + key]
return secret_message
def main():
"""Run a test decryption of the Trevanion Cipher."""
print(
decrypt_message(
"""Worthie Sir John: Hope, that is the beste comfort of the afflicted, cannot much, I fear me, help you now. That I would saye to you, is this only: if ever I may be able to requite that I do owe you, stand not upon asking me. 'Tis not much I can do: but what I can do, bee you verie sure I wille. I knowe that, if deathe comes, if ordinary men fear it, it frights not you, accounting for it for a high honour, to have such a rewarde of your loyalty. Pray yet that you may be spared this soe bitter, cup. I fear not that you will grudge any sufferings; onlie if bie submission you can turn them away, 'tis the part of a wise man. Tell me, an if you can, to do for you anythinge that you wolde have done. The general goes back on Wednesday. Restinge your servant to command. R.T.""",
key=3,
)
)
if __name__ == "__main__":
main()