ciphers.rail_fence_cipher

https://en.wikipedia.org/wiki/Rail_fence_cipher

Functions

bruteforce(→ dict[int, str])

Uses decrypt function by guessing every key

decrypt(→ str)

Generates a template based on the key and fills it in with

encrypt(→ str)

Shuffles the character of a string by placing each of them

Module Contents

ciphers.rail_fence_cipher.bruteforce(input_string: str) dict[int, str]

Uses decrypt function by guessing every key

>>> bruteforce("HWe olordll")[4]
'Hello World'
ciphers.rail_fence_cipher.decrypt(input_string: str, key: int) str

Generates a template based on the key and fills it in with the characters of the input string and then reading it in a zigzag formation.

>>> decrypt("HWe olordll", 4)
'Hello World'
>>> decrypt("This is a message", -10)
Traceback (most recent call last):
    ...
ValueError: Height of grid can't be 0 or negative
>>> decrypt("My key is very big", 100)
'My key is very big'
ciphers.rail_fence_cipher.encrypt(input_string: str, key: int) str

Shuffles the character of a string by placing each of them in a grid (the height is dependent on the key) in a zigzag formation and reading it left to right.

>>> encrypt("Hello World", 4)
'HWe olordll'
>>> encrypt("This is a message", 0)
Traceback (most recent call last):
    ...
ValueError: Height of grid can't be 0 or negative
>>> encrypt(b"This is a byte string", 5)
Traceback (most recent call last):
    ...
TypeError: sequence item 0: expected str instance, int found