MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / decrypt_message

Function decrypt_message

ciphers/transposition_cipher.py:39–61  ·  view source on GitHub ↗

>>> decrypt_message(6, 'Hlia rDsahrij') 'Harshil Darji'

(key: int, message: str)

Source from the content-addressed store, hash-verified

37
38
39def decrypt_message(key: int, message: str) -> str:
40 """
41 >>> decrypt_message(6, 'Hlia rDsahrij')
42 'Harshil Darji'
43 """
44 num_cols = math.ceil(len(message) / key)
45 num_rows = key
46 num_shaded_boxes = (num_cols * num_rows) - len(message)
47 plain_text = [""] * num_cols
48 col = 0
49 row = 0
50
51 for symbol in message:
52 plain_text[col] += symbol
53 col += 1
54
55 if (col == num_cols) or (
56 (col == num_cols - 1) and (row >= num_rows - num_shaded_boxes)
57 ):
58 col = 0
59 row += 1
60
61 return "".join(plain_text)
62
63
64if __name__ == "__main__":

Callers 1

mainFunction · 0.70

Calls 1

ceilMethod · 0.80

Tested by

no test coverage detected