Simple Columnar Method With Multiple Rounds In Cryptography

Hello everyone.

This blog introduces you to another transposition technique - Simple Columnar Method with Multiple Rounds.

It is a very efficient and useful transposition algorithm. There are two forms of this algorithm. One is "Simple Columnar Method With One Round" or simply "Simple Columnar Method", and the other one is "Simple Columnar Method with Multiple Rounds". Here, we are going to discuss the latter.

In this algorithm, we write the plain text message row-by-row in a 2D array of any size (Let’s say 10x5, according to the example given below). Then, read the message in column-by-column.

However, it is not necessary to read the message in the order of Column 1, Column 2, Column 3, and so on. It can be any random order, like 2, 0, 3, 1, 4 (according to the example). Thus, the message obtained is the cipher text of round 1. This cipher text functions as input as plain text to round 2.
 
This process keeps on going until the last round. You can keep the column order either same or different for every round. Here, I have used different column order for every round. This example involves four rounds. That's why it is called Simple Columnar Method With Multiple Rounds.
 
The final message that we obtain after the last round is the cipher text that is sent to the receiver. The receiver reverses the algorithm to decrypt the cipher text. On the receiver side, the last round of the sender side becomes the first round of the receiver side and so. We write the cipher text column-by-column in the specified column order by the corresponding round. Then, we read row-by-row to get the original message.

message

Here is the C# code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using WpfAppCryptography.ViewModel;  
  7. namespace WpfAppCryptography.Algorithms.TechniqueBased.Transposition {  
  8.     public class SimpleColumnarMethodWithMultipleRounds: Algorithm {  
  9.         public new string AlgorithmName = "Simple Columnar Method With Multiple Rounds";  
  10.         public override string Decrypt(string ciphertext, string key) {  
  11.             string plaintext = null;  
  12.             char[] ctca = ciphertext.ToCharArray();  
  13.             char[] itca = new char[ctca.Length];  
  14.             char[, ] cells = new char[10, 5];  
  15.             int[][] rounds = new int[4][];  
  16.             rounds[0] = new int[] {  
  17.                 4,  
  18.                 1,  
  19.                 0,  
  20.                 3,  
  21.                 2  
  22.             };  
  23.             rounds[1] = new int[] {  
  24.                 0,  
  25.                 4,  
  26.                 3,  
  27.                 1,  
  28.                 2  
  29.             };  
  30.             rounds[2] = new int[] {  
  31.                 1,  
  32.                 4,  
  33.                 2,  
  34.                 3,  
  35.                 0  
  36.             };  
  37.             rounds[3] = new int[] {  
  38.                 2,  
  39.                 0,  
  40.                 3,  
  41.                 1,  
  42.                 4  
  43.             };  
  44.             itca = ctca;  
  45.             for (int i = 0; i < 4; i++) {  
  46.                 cells = SetCharactersInCellsVertically(cells, itca.Length, itca, rounds[i]);  
  47.                 itca = SetItcaFromCellsHorizontally(cells, itca);  
  48.             }  
  49.             for (int i = 0; i < itca.Length; i++) {  
  50.                 plaintext += itca[i];  
  51.             }  
  52.             return plaintext;  
  53.         }  
  54.         public override string Encrypt(string plaintext, string key) {  
  55.             string ciphertext = null;  
  56.             char[] ptca = plaintext.ToCharArray();  
  57.             char[] itca = new char[ptca.Length];  
  58.             char[, ] cells = new char[10, 5];  
  59.             int[][] rounds = new int[4][];  
  60.             rounds[0] = new int[] {  
  61.                 2,  
  62.                 0,  
  63.                 3,  
  64.                 1,  
  65.                 4  
  66.             };  
  67.             rounds[1] = new int[] {  
  68.                 1,  
  69.                 4,  
  70.                 2,  
  71.                 3,  
  72.                 0  
  73.             };  
  74.             rounds[2] = new int[] {  
  75.                 0,  
  76.                 4,  
  77.                 3,  
  78.                 1,  
  79.                 2  
  80.             };  
  81.             rounds[3] = new int[] {  
  82.                 4,  
  83.                 1,  
  84.                 0,  
  85.                 3,  
  86.                 2  
  87.             };  
  88.             itca = ptca;  
  89.             for (int i = 0; i < 4; i++) {  
  90.                 cells = SetCharactersInCellsHorizontally(cells, itca.Length, itca);  
  91.                 itca = SetItcaFromCellsVertically(cells, itca, rounds[i]);  
  92.             }  
  93.             for (int i = 0; i < itca.Length; i++) {  
  94.                 ciphertext += itca[i];  
  95.             }  
  96.             return ciphertext;  
  97.         }  
  98.         private char[, ] SetCharactersInCellsHorizontally(char[, ] cells, int length, char[] itca) {  
  99.             int x = 0, y = 0;  
  100.             for (int i = 0; i < itca.Length; i++) {  
  101.                 cells[x, y++] = itca[i];  
  102.                 if (y == 5) {  
  103.                     y = 0;  
  104.                     ++x;  
  105.                 }  
  106.             }  
  107.             return cells;  
  108.         }  
  109.         private char[] SetItcaFromCellsVertically(char[, ] cells, char[] itca, int[] columnorder) {  
  110.             int k = 0;  
  111.             for (int x = 0; x < 5; x++) {  
  112.                 int t = columnorder[x];  
  113.                 for (int y = 0; cells[y, t] != '\0'; y++) {  
  114.                     itca[k++] = cells[y, t];  
  115.                 }  
  116.             }  
  117.             return itca;  
  118.         }  
  119.         private char[, ] SetCharactersInCellsVertically(char[, ] cells, int length, char[] itca, int[] columnorder) {  
  120.             int k = 0;  
  121.             for (int x = 0; x < 5; x++) {  
  122.                 int t = columnorder[x];  
  123.                 for (int i = 0;  
  124.                     ((i * 5) + t) < length; i++) {  
  125.                     cells[i, t] = itca[k++];  
  126.                 }  
  127.             }  
  128.             return cells;  
  129.         }  
  130.         private char[] SetItcaFromCellsHorizontally(char[, ] cells, char[] itca) {  
  131.             int x = 0, y = 0;  
  132.             for (int i = 0; i < itca.Length; i++) {  
  133.                 itca[i] = cells[x, y++];  
  134.                 if (y == 5) {  
  135.                     y = 0;  
  136.                     ++x;  
  137.                 }  
  138.             }  
  139.             return itca;  
  140.         }  
  141.     }  
  142. }  
Here is the video.

That's the end of it. I hope you find my blogs useful. See you next time. Till then, keep coding.

Up Next
    Ebook Download
    View all
    Learn
    View all