Simple column transposition

Keyword


The first 10 lines of the grid are shown

python transpostion.py --encrypt --message 'Hello this is a test. Please enter your text here' --key 'Cipher' --alphabet '' --case-sensitive    
Select a theme:
Fontsize:
length:

Background

In cryptography, transposition is a cipher where the order of the letters is changed instead of replacing the letters with other symbols as in the substitution cipher.


Description and operations

Column transposition uses a rectangular arrangement (also called a matrix or grid), consisting of several rows (as many as are necessary to enter the plain text). The number of columns is given by the length of the key (also called keyword). The plaintext is then entered into the grid line by line. Afterwards 2 header lines are added: The first one contains the keyword, the second one consists of the numbers, which are obtained by arranging the characters in the keyword alphabetically (permutation). Then the columns are read in the order of the numbers of the permutation. In this implementation the permutation from the keyword is determined as follows: All characters are identified by their ASCII value. Thus, a distinction is made between upper and lower case letters. All printable characters [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ÄÖÜäööü .,:;!?()-+*/[]{}@_><#~=\"&%$§] are possible as the alphabet for the keyword. A character can also occur several times (the first of these same characters is taken first, then the next and so on). Here are a few examples how the permutation is calculated:

Example: Key          Permutation
         AB           12
         aB           21
         SCHELL       613245
         SCHell       312456
         ellSCH       456312

As an example we encrypt the message "Hello this is an example" with the keyword 'Cipher'.

1. Create the grid
Due to the keyword, the result is a grid with 6 columns.

2. Fill the grid
example
The plain text message is entered into the grid line by line. This way you get the grid specified on the left. The plaintext had a length of 24. As you can see, we have six complete columns of length 4 (if the message length isn't dividable by the keyword length, we also get incomplete columns).

3. Enter table headers and permutation
Under the letters of the keyword their position is noted in alphabetical order (permutation).

4. Read out by column
The six columns are then read out in the order given by the permutation. So here starting with the column, which is overwritten by 'C': The ciphertext starts with 'Htsx'. Then the column with the headline 'e' is read from top to bottom and so on. So you get the ciphertext 'Htsxo llsnpeh aliam iee'.


Security

Since a transposition does not influence the frequency of the individual symbols, can be easily identified by a frequency analysis whether this encryption method is used: So if the encrypted text has a frequency distribution that is very similar to normal plaintext it is most likely a transposition. This identifies the cipher type detection, but not yet the key (permutation). For multiple consecutive transpositions with long random keys, the cryptoanalysis is not easy even with today's methods.



References

● Transposition cipher: https://en.wikipedia.org/wiki/Transposition_cipher

About the code

In this plugin you can control the encryption process in two ways:

  • via the GUI
  • via the command line arguments for the Python program

The Python code is executed purely locally in your browser without the need to install a Python development environment, but also without, that the Python code must be executed somewhere in the cloud. The following parameters can be changed via the GUI:

  • the text to be entered
  • whether to encrypt or decrypt the entered text
  • the key
  • the alphabet used for the message and the passphrase
  • whether the output text should be output in blocks of five
  • whether spaces should be filtered out
  • whether spaces should be replaced with another character

These GUI parameters are passed to the script on the command line. Changes in the GUI change the respective command-line parameters.

The code is an implementation of the simple transposition encryption in Python. Depending on whether the input is decrypted or encrypted the corresponding function is executed. In case of the encryption, the characters are distributed to columns. Then the key is sorted alphabetically and each character in the key is assigned a number. This number corresponds to the alphabetical order. At the end you add the columns based on of their order together. In the case of decryption, first the Number of rows and the difference calculated. This difference corresponds to the placeholders in the last line. After that an empty Matrix created. The number of columns in the matrix corresponds to the length of the key. As in the encryption, the key sorted alphabetically. The matrix is filled based on the alphabetical order of the key. For each row in the matrix, the key is replaced by iterates each column. At every iteration characters from a series. Thus one receives the decrypted message.


About the editor

The editor available on this page was implemented with CodeMirror [1]. CodeMirror is a versatile text editor that is implemented in JavaScript for the Browser was implemented. CodeMirror has a number of add-ons for different of programming languages. Pyodide [2] is used to execute the Python code.

Pyodide brings the Python runtime environment via WebAssembly into the browser, together with NumPy, Pandas, Matplotlib, parts of SciPy and NetworkX. In the editor there is now an interpreter for Python 3.x . You can see which exact Python version is used by Pyodide – by adding the following statement to the code: print(sys.version).



References

[1] Codemirror: https://codemirror.net/

Print