Introduction To Mono Alphabetic Cipher Algorithm

Hello everyone. In my last blog on Cryptography, I demonstrated Caesar Cipher. In this blog, I will be describing Mono Alphabetic Cipher algorithm. Mono Alphabetic Cipher is another substitution technique, where each character of the plain text is substituted with another different character. There is no mathematical relation between the original character and the substituted character. Whenever a specific character is encountered, it will be always replaced by the character, which is defined in the substitution table. For example, whenever 'a' is encountered in the plain text, it will always be replaced by 'q' in the Cipher text. The relation between 'a' and 'q' is random.

The substitution table, I have defined here is as follows-

Original Characters - a b c d e f g h i j k l m n o p q r s t u v w x y z
Substituted Characters - q w e r t y u i o p a s d f g h j k l z x c v b n m

Hence, if I write,

Plain Text - h e l l o
Cipher Text - i t s s g

I have done it for only lower case alphabets. If you want, you can do it for upper case alphabets as well as digits.

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.   
  8. namespace WpfAppCryptography.Algorithms.TechniqueBased.Substitution  
  9. {  
  10.     public class MonoAlphabeticCipher : Algorithm  
  11.     {  
  12.         public new string AlgorithmName = "Mono Alphabetic Cipher";  
  13.   
  14.         private char[] o = new char[] { 'a''b''c''d''e''f''g''h''i''j''k''l''m''n''o''p''q''r''s''t''u''v''w''x''y''z' };  
  15.         private char[] m = new char[] { 'q''w''e''r''t''y''u''i''o''p''a''s''d''f''g''h''j''k''l''z''x''c''v''b''n''m' };  
  16.   
  17.         private int GetIndex(char ch, char[] ca)  
  18.         {  
  19.             int i, result = 0;  
  20.             for (i = 0; i < 26; ++i)  
  21.             {  
  22.                 if (ca[i] == ch)  
  23.                 {  
  24.                     result = i;  
  25.                     break;  
  26.                 }  
  27.             }  
  28.             return result;  
  29.         }  
  30.   
  31.         public override string Decrypt(string ciphertext, string key)  
  32.         {  
  33.             int i, j;  
  34.             string plaintext = null;  
  35.             char[] ctca = ciphertext.ToCharArray();  
  36.             char[] cc = new char[500];  
  37.   
  38.             for (i = 0; i < ctca.Length; ++i)  
  39.             {  
  40.                 if (ctca[i] == ' ')  
  41.                 {  
  42.                     cc[i] = ctca[i];  
  43.                 }  
  44.                 else  
  45.                 {  
  46.                     j = GetIndex(ctca[i], m);  
  47.                     cc[i] = o[j];  
  48.                 }  
  49.                 plaintext += cc[i];  
  50.             }  
  51.   
  52.             return plaintext;  
  53.         }  
  54.   
  55.         public override string Encrypt(string plaintext, string key)  
  56.         {  
  57.             int i, j;  
  58.             string ciphertext = null;  
  59.             char[] ptca = plaintext.ToCharArray();  
  60.             char[] cc = new char[500];  
  61.   
  62.             for (i = 0; i < ptca.Length; ++i)  
  63.             {  
  64.                 if (ptca[i] == ' ')  
  65.                 {  
  66.                     cc[i] = ptca[i];  
  67.                 }  
  68.                 else  
  69.                 {  
  70.                     j = GetIndex(ptca[i],o);  
  71.                     cc[i] = m[j];  
  72.                 }  
  73.                 ciphertext += cc[i];  
  74.             }  
  75.   
  76.             return ciphertext;  
  77.         }  
  78.     }  
  79. }  
Here, is the link to the video.

I hope, you find it useful. Keep coding.

http://cryptobysourav.blogspot.in/2016/06/mono-alphabetic-cipher.html
Next Recommended Reading Introduction To Blockchain