1
1
"""
2
2
Python program for the Fractionated Morse Cipher.
3
3
4
- The Fractionated Morse cipher first converts the plaintext to morse code,
5
- then enciphers fixed-size blocks of morse code back to letters.
4
+ The Fractionated Morse cipher first converts the plaintext to Morse code,
5
+ then enciphers fixed-size blocks of Morse code back to letters.
6
6
This procedure means plaintext letters are mixed into the ciphertext letters,
7
7
making it more secure than substitution ciphers.
8
8
9
9
http://practicalcryptography.com/ciphers/fractionated-morse-cipher/
10
-
11
10
"""
12
-
13
-
14
11
import string
15
12
16
- # Define Morse code dictionary
17
13
MORSE_CODE_DICT = {
18
14
"A" : ".-" ,
19
15
"B" : "-..." ,
@@ -86,7 +82,7 @@ def encode_to_morse(plaintext: str) -> str:
86
82
plaintext: The plaintext message to encode.
87
83
88
84
Returns:
89
- str: The Morse code representation of the plaintext message.
85
+ The Morse code representation of the plaintext message.
90
86
91
87
Example:
92
88
>>> encode_to_morse("defend the east")
@@ -99,11 +95,11 @@ def encrypt_fractionated_morse(plaintext: str, key: str) -> str:
99
95
"""Encrypt a plaintext message using Fractionated Morse Cipher.
100
96
101
97
Args:
102
- plaintext (str) : The plaintext message to encrypt.
103
- key (str) : The encryption key.
98
+ plaintext: The plaintext message to encrypt.
99
+ key: The encryption key.
104
100
105
101
Returns:
106
- str: The encrypted ciphertext.
102
+ The encrypted ciphertext.
107
103
108
104
Example:
109
105
>>> encrypt_fractionated_morse("defend the east","Roundtable")
@@ -133,11 +129,11 @@ def decrypt_fractionated_morse(ciphertext: str, key: str) -> str:
133
129
"""Decrypt a ciphertext message encrypted with Fractionated Morse Cipher.
134
130
135
131
Args:
136
- ciphertext (str) : The ciphertext message to decrypt.
137
- key (str) : The decryption key.
132
+ ciphertext: The ciphertext message to decrypt.
133
+ key: The decryption key.
138
134
139
135
Returns:
140
- str: The decrypted plaintext message.
136
+ The decrypted plaintext message.
141
137
142
138
Example:
143
139
>>> decrypt_fractionated_morse("ESOAVVLJRSSTRX","Roundtable")
0 commit comments