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.

Here is the C# code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WpfAppCryptography.ViewModel;
- namespace WpfAppCryptography.Algorithms.TechniqueBased.Transposition {
- public class SimpleColumnarMethodWithMultipleRounds: Algorithm {
- public new string AlgorithmName = "Simple Columnar Method With Multiple Rounds";
- public override string Decrypt(string ciphertext, string key) {
- string plaintext = null;
- char[] ctca = ciphertext.ToCharArray();
- char[] itca = new char[ctca.Length];
- char[, ] cells = new char[10, 5];
- int[][] rounds = new int[4][];
- rounds[0] = new int[] {
- 4,
- 1,
- 0,
- 3,
- 2
- };
- rounds[1] = new int[] {
- 0,
- 4,
- 3,
- 1,
- 2
- };
- rounds[2] = new int[] {
- 1,
- 4,
- 2,
- 3,
- 0
- };
- rounds[3] = new int[] {
- 2,
- 0,
- 3,
- 1,
- 4
- };
- itca = ctca;
- for (int i = 0; i < 4; i++) {
- cells = SetCharactersInCellsVertically(cells, itca.Length, itca, rounds[i]);
- itca = SetItcaFromCellsHorizontally(cells, itca);
- }
- for (int i = 0; i < itca.Length; i++) {
- plaintext += itca[i];
- }
- return plaintext;
- }
- public override string Encrypt(string plaintext, string key) {
- string ciphertext = null;
- char[] ptca = plaintext.ToCharArray();
- char[] itca = new char[ptca.Length];
- char[, ] cells = new char[10, 5];
- int[][] rounds = new int[4][];
- rounds[0] = new int[] {
- 2,
- 0,
- 3,
- 1,
- 4
- };
- rounds[1] = new int[] {
- 1,
- 4,
- 2,
- 3,
- 0
- };
- rounds[2] = new int[] {
- 0,
- 4,
- 3,
- 1,
- 2
- };
- rounds[3] = new int[] {
- 4,
- 1,
- 0,
- 3,
- 2
- };
- itca = ptca;
- for (int i = 0; i < 4; i++) {
- cells = SetCharactersInCellsHorizontally(cells, itca.Length, itca);
- itca = SetItcaFromCellsVertically(cells, itca, rounds[i]);
- }
- for (int i = 0; i < itca.Length; i++) {
- ciphertext += itca[i];
- }
- return ciphertext;
- }
- private char[, ] SetCharactersInCellsHorizontally(char[, ] cells, int length, char[] itca) {
- int x = 0, y = 0;
- for (int i = 0; i < itca.Length; i++) {
- cells[x, y++] = itca[i];
- if (y == 5) {
- y = 0;
- ++x;
- }
- }
- return cells;
- }
- private char[] SetItcaFromCellsVertically(char[, ] cells, char[] itca, int[] columnorder) {
- int k = 0;
- for (int x = 0; x < 5; x++) {
- int t = columnorder[x];
- for (int y = 0; cells[y, t] != '\0'; y++) {
- itca[k++] = cells[y, t];
- }
- }
- return itca;
- }
- private char[, ] SetCharactersInCellsVertically(char[, ] cells, int length, char[] itca, int[] columnorder) {
- int k = 0;
- for (int x = 0; x < 5; x++) {
- int t = columnorder[x];
- for (int i = 0;
- ((i * 5) + t) < length; i++) {
- cells[i, t] = itca[k++];
- }
- }
- return cells;
- }
- private char[] SetItcaFromCellsHorizontally(char[, ] cells, char[] itca) {
- int x = 0, y = 0;
- for (int i = 0; i < itca.Length; i++) {
- itca[i] = cells[x, y++];
- if (y == 5) {
- y = 0;
- ++x;
- }
- }
- return itca;
- }
- }
- }
That's the end of it. I hope you find my blogs useful. See you next time. Till then, keep coding.

Prasanna MuraliPosted Sep 6, 2016, 9:18 PM
Nice post...