1
1
def encrypt_scytale_cipher (message : str , key : int ) -> str :
2
2
"""
3
3
Encrypts a message using the Scytale Cipher.
4
-
4
+
5
5
:param message: Text to encrypt.
6
6
:param key: Number of rows (key).
7
7
:return: Encrypted message.
8
8
"""
9
9
message = message .replace (" " , "" ) # Optional: remove spaces
10
- ciphertext = ['' ] * key
10
+ ciphertext = ["" ] * key
11
11
12
12
# Distribute characters across rows based on the key
13
13
for i in range (len (message )):
14
14
ciphertext [i % key ] += message [i ]
15
15
16
- return '' .join (ciphertext )
16
+ return "" .join (ciphertext )
17
17
18
18
19
19
def decrypt_scytale_cipher (ciphertext : str , key : int ) -> str :
20
20
"""
21
21
Decrypts a message encrypted with the Scytale Cipher.
22
-
22
+
23
23
:param ciphertext: Encrypted text.
24
24
:param key: Number of rows (key).
25
25
:return: Decrypted message.
@@ -28,7 +28,7 @@ def decrypt_scytale_cipher(ciphertext: str, key: int) -> str:
28
28
num_rows = key
29
29
num_shaded_boxes = (num_cols * num_rows ) - len (ciphertext ) # Extra unused boxes
30
30
31
- plaintext = ['' ] * num_cols
31
+ plaintext = ["" ] * num_cols
32
32
col = 0
33
33
row = 0
34
34
@@ -37,11 +37,13 @@ def decrypt_scytale_cipher(ciphertext: str, key: int) -> str:
37
37
plaintext [col ] += char
38
38
col += 1
39
39
# Reset column and move to next row if end of column is reached
40
- if (col == num_cols ) or (col == num_cols - 1 and row >= num_rows - num_shaded_boxes ):
40
+ if (col == num_cols ) or (
41
+ col == num_cols - 1 and row >= num_rows - num_shaded_boxes
42
+ ):
41
43
col = 0
42
44
row += 1
43
45
44
- return '' .join (plaintext )
46
+ return "" .join (plaintext )
45
47
46
48
47
49
# Example usage
0 commit comments