Skip to content

Added ciphers/permutation_cipher.py. #9163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added doctest in functions
  • Loading branch information
aryan1165 committed Oct 1, 2023
commit c51a20ebb0ebf4d2e3446a45d6aad7c99dab0b6d
15 changes: 11 additions & 4 deletions ciphers/permutation_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def generate_valid_block_size(message_length: int) -> int:
int: A valid block size.

Example:
generate_valid_block_size(12)
3
>>> generate_valid_block_size(2)
2
"""
while True:
block_size = random.randint(2, message_length)
Expand All @@ -41,8 +41,8 @@ def generate_permutation_key(block_size: int) -> list:
list[int]: A list containing a random permutation of digits.

Example:
generate_permutation_key(4)
[3, 4, 1, 2]
>>> generate_permutation_key(1)
[1]
"""
digits = list(range(1, block_size + 1))
random.shuffle(digits)
Expand Down Expand Up @@ -118,6 +118,13 @@ def decrypt(encrypted_message: str, key: list) -> str:


def main() -> None:
"""
Driver function to pass message to get encrypted, then decrypted.

Example:
>>> main()
Decrypted message: HELLO WORLD
"""
message = "HELLO WORLD"
encrypted_message, key = encrypt(message)

Expand Down