11def encrypt_scytale_cipher (message : str , key : int ) -> str :
22 """
33 Encrypts a message using the Scytale Cipher.
4-
4+
55 :param message: Text to encrypt.
66 :param key: Number of rows (key).
77 :return: Encrypted message.
88 """
99 message = message .replace (" " , "" ) # Optional: remove spaces
10- ciphertext = ['' ] * key
10+ ciphertext = ["" ] * key
1111
1212 # Distribute characters across rows based on the key
1313 for i in range (len (message )):
1414 ciphertext [i % key ] += message [i ]
1515
16- return '' .join (ciphertext )
16+ return "" .join (ciphertext )
1717
1818
1919def decrypt_scytale_cipher (ciphertext : str , key : int ) -> str :
2020 """
2121 Decrypts a message encrypted with the Scytale Cipher.
22-
22+
2323 :param ciphertext: Encrypted text.
2424 :param key: Number of rows (key).
2525 :return: Decrypted message.
@@ -28,7 +28,7 @@ def decrypt_scytale_cipher(ciphertext: str, key: int) -> str:
2828 num_rows = key
2929 num_shaded_boxes = (num_cols * num_rows ) - len (ciphertext ) # Extra unused boxes
3030
31- plaintext = ['' ] * num_cols
31+ plaintext = ["" ] * num_cols
3232 col = 0
3333 row = 0
3434
@@ -37,11 +37,13 @@ def decrypt_scytale_cipher(ciphertext: str, key: int) -> str:
3737 plaintext [col ] += char
3838 col += 1
3939 # 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+ ):
4143 col = 0
4244 row += 1
4345
44- return '' .join (plaintext )
46+ return "" .join (plaintext )
4547
4648
4749# Example usage
0 commit comments