transposicion module implements a columnar transposition cipher that encrypts messages by writing them in rows and reading them in columns.
cifrar
Encrypts a message using columnar transposition by arranging characters into a grid and reading column-by-column.The message to encrypt. Spaces are automatically removed before encryption.
The number of columns to use in the transposition grid (the encryption key).
The encrypted message. If the message length is not divisible by the key, asterisks (*) are added as padding.
The function automatically pads the message with asterisks (*) if its length is not a multiple of the key value. This ensures a complete rectangular grid.
How it works
The encryption process:- Removes all spaces from the message
- Calculates the number of rows needed based on the key (columns)
- Pads the message with asterisks if needed to complete the grid
- Arranges the message in a grid row-by-row
- Reads the grid column-by-column to create the ciphertext
Example
Real-world usage
descifrar
Decrypts a message that was encrypted using columnar transposition.The encrypted message to decrypt. Spaces are automatically removed.
The number of columns used during encryption (must match the encryption key).
The decrypted message with padding asterisks removed from the end.
The key used for decryption must match the key used for encryption, otherwise the output will be gibberish.
How it works
The decryption process:- Removes all spaces from the encrypted message
- Calculates the number of rows in the original grid
- Reads the encrypted message column-by-column
- Reconstructs the original message row-by-row
- Removes trailing asterisk padding characters
Example
Real-world usage
Complete encryption workflow
Here’s a complete example demonstrating encryption and decryption:Key selection guidelines
Choosing the right key:
- Smaller keys (2-3): Less secure but faster
- Medium keys (4-8): Good balance of security and usability
- Larger keys (9+): More secure but requires longer messages for effectiveness
- The key should be smaller than the message length for meaningful encryption