MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / generate_valid_block_size

Function generate_valid_block_size

ciphers/permutation_cipher.py:14–34  ·  view source on GitHub ↗

Generate a valid block size that is a factor of the message length. Args: message_length (int): The length of the message. Returns: int: A valid block size. Example: >>> random.seed(1) >>> generate_valid_block_size(12) 3

(message_length: int)

Source from the content-addressed store, hash-verified

12
13
14def generate_valid_block_size(message_length: int) -> int:
15 """
16 Generate a valid block size that is a factor of the message length.
17
18 Args:
19 message_length (int): The length of the message.
20
21 Returns:
22 int: A valid block size.
23
24 Example:
25 >>> random.seed(1)
26 >>> generate_valid_block_size(12)
27 3
28 """
29 block_sizes = [
30 block_size
31 for block_size in range(2, message_length + 1)
32 if message_length % block_size == 0
33 ]
34 return random.choice(block_sizes)
35
36
37def generate_permutation_key(block_size: int) -> list[int]:

Callers 1

encryptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected