<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7649821627578320923</id><updated>2024-10-24T19:31:28.883-07:00</updated><title type='text'>Noob2Pro</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://noob2professional.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7649821627578320923/posts/default'/><link rel='alternate' type='text/html' href='https://noob2professional.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/17215868470569714724</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7649821627578320923.post-760398485386244685</id><published>2019-03-07T20:32:00.002-08:00</published><updated>2019-03-07T20:33:26.661-08:00</updated><title type='text'>hello</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
hello&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://noob2professional.blogspot.com/feeds/760398485386244685/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://noob2professional.blogspot.com/2019/03/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7649821627578320923/posts/default/760398485386244685'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7649821627578320923/posts/default/760398485386244685'/><link rel='alternate' type='text/html' href='https://noob2professional.blogspot.com/2019/03/blog-post.html' title='hello'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/17215868470569714724</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7649821627578320923.post-2928344623956903928</id><published>2018-08-03T10:27:00.001-07:00</published><updated>2018-08-03T10:27:45.054-07:00</updated><title type='text'>Hill Cipher program in c</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;Introduction to Hill Cipher&lt;/h3&gt;
In classical cryptography, &lt;b&gt;the Hill cipher is a polygraphic substitution cipher based on linear algebra.&lt;/b&gt; Invented by Lester S. Hill in 1929, it was the first polygraphic cipher in which it was practical (though barely) to operate on more than three symbols at once. &lt;b&gt;The following discussion assumes an elementary knowledge of matrices&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
This technique encrypt plaintext in matrix form of 2x2 or 3x3.when plaintext in 2x2 then key value also in 2x2 matrix and 3x3 use then 3x3 matrix key.Using matrix we can &lt;b&gt;encrypt 4 or 9 plaintext letters at once.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Hill Cipher Theory&lt;/h3&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
First of all need key in matrix form of 2x2 or 3x3 depends of requirement.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Here, we have formula to find Cipher text&amp;nbsp; (&lt;b&gt;Encryption&lt;/b&gt;)&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;b&gt;CT = K*PT mod 26&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;Where, CT = CipherText ,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; K = Key ,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PT = PlainText.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;We have also formula to find Plain text from Cipher text (&lt;b&gt;Decryption&lt;/b&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;PT = K&lt;sup&gt;-1&lt;/sup&gt;*CT mod 26&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Where, CT = CipherText ,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;K&lt;sup&gt;-1&lt;/sup&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; = Inverse of key , &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PT = PlainText.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;Example:&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Plain text is &quot;computer&quot; and Key is in matrix 4 9 3 7. Apply Encryption and Decryption using Hill Cipher 2x2 matrix.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzAElyXOOm5Irbx-RJ0dHHcn77vJ1iKvqtQLp_Enj0mGwFTFlCL8iDaih7XGXYU4Z3v5dP-_HXCFkfoKowNb6kBmwEowHfqmNPV_UlfQ5gb7tSoNOWVEvDQzJmeFhfDP5h1hJWWs89uA/s1600/1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;561&quot; data-original-width=&quot;1600&quot; height=&quot;224&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzAElyXOOm5Irbx-RJ0dHHcn77vJ1iKvqtQLp_Enj0mGwFTFlCL8iDaih7XGXYU4Z3v5dP-_HXCFkfoKowNb6kBmwEowHfqmNPV_UlfQ5gb7tSoNOWVEvDQzJmeFhfDP5h1hJWWs89uA/s640/1.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;First perform Encryption:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In this we made 4-4 part of letters&amp;nbsp; because we use 2x2 matrix.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Also convert plain text using below format,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;a,b,c,d,........,x,y,z ==&amp;gt; 0,1,2,3,......,23,24,25.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Here over plain text is &quot;computer&quot; ==&amp;gt; &quot;2 14 12 15 20 19 4 17&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In first part &quot;comp&quot; is encrypted for this &quot;2 14 12 15&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAQXlBkG-S14QOWtjjVp2NIyYBp2_5IP2qEnp3m4oHktGw_ZZI5hG-7SKEvVmXH8foU1dhw59JaKYdYJEhV18zTUMWUWpVs0xJo2H7dlWRHTs4cpcwkIjoggNpba1hCC6jiPgIyRSNWA/s1600/en.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1600&quot; data-original-width=&quot;1400&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAQXlBkG-S14QOWtjjVp2NIyYBp2_5IP2qEnp3m4oHktGw_ZZI5hG-7SKEvVmXH8foU1dhw59JaKYdYJEhV18zTUMWUWpVs0xJo2H7dlWRHTs4cpcwkIjoggNpba1hCC6jiPgIyRSNWA/s640/en.jpg&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Answer of CT is &quot;12 9 12 17&quot; convert it into letters &quot;mjmr&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;second part of text is &quot;uter&quot; ==&amp;gt;&quot;20 19 4 17&quot; using formula cipher text is &quot;12 21 10 20&quot; convert into letters &quot;mvku&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&quot;computer&quot; ==&amp;gt;&quot;mjmrmvku&quot; is our cipher text.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;Decryption:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;We perform inverse process of encryption.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;First 4-4 parts of cipher text and find value of it like...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&quot;mjmr mvku&quot; ==&amp;gt;&quot;12 9 12 17&amp;nbsp;&amp;nbsp; 12 21 10 20&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Use first 4 for decryption see in below image&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi74TenHUw7o8RyIAfymvN1_Gs_0lEfqEbYg5e60m7TEVLyq3Gik48vAvOXmhSO817En4Mzb-Eff3lmevxTa8yVLYSBTd2pfUED5Jdf3HCsckUr2MMR0ksVbEzz9mGaPp7Ca9IMRA61ng/s1600/de.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1600&quot; data-original-width=&quot;1348&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi74TenHUw7o8RyIAfymvN1_Gs_0lEfqEbYg5e60m7TEVLyq3Gik48vAvOXmhSO817En4Mzb-Eff3lmevxTa8yVLYSBTd2pfUED5Jdf3HCsckUr2MMR0ksVbEzz9mGaPp7Ca9IMRA61ng/s640/de.jpg&quot; width=&quot;538&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In this find inverse of key and multiple matrix with first 4 cipher text letters.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;(how to find inverse and multiplication &lt;a href=&quot;https://www.mathsisfun.com/algebra/matrix-inverse.html&quot;&gt;click here&lt;/a&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;You can see in picture we get the plain text from cipher text.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;Now we see Hill Cipher Program in c&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;First we see variable information:&lt;/b&gt;&lt;/span&gt;
&lt;/h4&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;  int key[2][2]={&#39;\0&#39;},p[50]={&#39;\0&#39;};  
  char pt[50]={&#39;\0&#39;};  
  int len=0,n=0,i=0,j=0,m=0;  
  clrscr();  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Key is 2x2 matrix use for get key value from user.&lt;br /&gt;
Pt is character array that is use for store plain text.&lt;br /&gt;
p in this array store plain text numeric value (a,b,c...==&amp;gt;0,1,2...) .&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Get Plaintext and key from user:&lt;/b&gt;&amp;nbsp;&lt;/h4&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; printf(&quot;\n Enter PlainText:&quot;);  
  gets(pt);  
  printf(&quot;\n Enter key:&quot;);  
  for(i=0;i&amp;lt;2;i++)  
  {  
   for(j=0;j&amp;lt;2;j++)  
   scanf(&quot;%d&quot;,&amp;amp;key[i][j]);  
  }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
using gets() we get plain text and use for loop for get value of key.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Add Filler&lt;/b&gt;&lt;/h4&gt;
In this part we add filler to our plain text for better out put.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;why need filler?&lt;/b&gt;&lt;br /&gt;
Filler is use when 4 equal parts is not possible like..&lt;br /&gt;
In &quot;hello&quot; part is &quot;hell&quot; and &quot;o&quot; that time our program&#39;s first part is run completely but in second part we have only one letter there for error is occur or program miss behave.&lt;br /&gt;
&lt;br /&gt;
Therefore we use filler &#39;x&#39; in program &quot;hello&quot; ==&amp;gt; &quot;hell oxxx&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; len=strlen(pt);  
  if(len % 4 == 1)  
  {  
   n=3;  
  }else if(len % 4 == 2)  
  {  
  n=2;  
  }else if(len % 4 == 3)  
  {  
  n=1;  
  }else  
  {  
  n=0;  
  }  
  if(n != 0)  
  {  
  for(i=0;i&amp;lt;n;i++)  
  {  
   pt[len]=&#39;x&#39;;  
   len++;  
  }  
  }  
  printf(&quot;\n new plaintext:&quot;);  
  puts(pt);  
  n=0;  
  printf(&quot;\n Your Key is:&quot;);  
  printf(&quot;\n&quot;);  
  for(i=0;i&amp;lt;2;i++)  
  {  
    for(j=0;j&amp;lt;2;j++)  
    {  
    printf(&quot;\t %d \t&quot;,key[i][j]);  
    }  
    printf(&quot;\n \n&quot;);  
  }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Output of this:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRdNcmk4SgmWEfO0i4MKEkDIuhhfEobYSFa6y0mHIdKjPl-fNaBV3NKmWFhkPas2yK8SHga-TYesWVdkffqgxbNOpDr8a4pCiS7qXGHbdNXNn45shCbrw3ejOpXOoRGx7lcgBz2cJNXw/s1600/1jpg.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;423&quot; data-original-width=&quot;702&quot; height=&quot;240&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRdNcmk4SgmWEfO0i4MKEkDIuhhfEobYSFa6y0mHIdKjPl-fNaBV3NKmWFhkPas2yK8SHga-TYesWVdkffqgxbNOpDr8a4pCiS7qXGHbdNXNn45shCbrw3ejOpXOoRGx7lcgBz2cJNXw/s400/1jpg.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Store plain text numeric value:&lt;/b&gt;&lt;/h4&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;  for(i=0;i&amp;lt;strlen(pt);i++)  
  {  
   p[m]=pt[i]-97;  
   m++;  
  }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
here substitute 97 from each letter it will give numeric value of letters and store in array p.&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Send values to function:&lt;/b&gt;&amp;nbsp;&lt;/h4&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; hill(p,m,key);  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
here send array p in this all numeric value of plaintext that is use in encryption,&lt;br /&gt;
m it is index of p (in c language difficult to find length of integer array)&lt;br /&gt;
key it is most important for encryption and decryption.&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Function of Hill Cipher:&lt;/b&gt;&lt;/h4&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; void hill(int [50],int ,int [2][2]);  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
First add this function deceleration above of main function.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;Variables use in function:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;  int i=0,sum=0,j=0,k=0,n=0,count=0,ic=0;  
  int ipt[2][2]={&#39;\0&#39;},cy[2][2]={&#39;\0&#39;},c[50]={&#39;\0&#39;};  
  char fcy[50]={&#39;\0&#39;},fpt[50]={&#39;\0&#39;};  
  float ikey[2][2]={&#39;\0&#39;},det=0,psum=0,pt[2][2]={&#39;\0&#39;};  
  int tpt[2][2]={&#39;\0&#39;};  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
ipt is store 4 value of plain text that is use in matrix multiplication.&lt;br /&gt;
cy is cipher text value before of mod with 26.&lt;br /&gt;
fcy is final array of cipher text.&lt;br /&gt;
ikey in this store inverse of key.&lt;br /&gt;
pt is store value before of mod with 26.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Encryption:&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; for(n=0;n&amp;lt;m;n++)  
  {  
   for(i=0;i&amp;lt;2;i++)  
   {  
   for(j=0;j&amp;lt;2;j++)  
   {  
    ipt[i][j]=p[count];  
    count++;  
   }  
   }  
  for(i=0;i&amp;lt;2;i++)  
  {  
  for(j=0;j&amp;lt;2;j++)  
  {  
  sum=0;  
   for(k=0;k&amp;lt;2;k++)  
   {  
    sum=sum+key[i][k]*ipt[k][j];  
   }  
   cy[i][j]=sum;  
  }  
  }  
  printf(&quot;\n cipher text is:&quot;);  
  sum=0;  
  for(i=0;i&amp;lt;2;i++)  
  {  
  for(j=0;j&amp;lt;2;j++)  
  {  
   fcy[sum]=(cy[i][j]%26)+97;  
   c[ic]=cy[i][j]%26;  
   ic++;  
   printf(&quot;%c \t&quot;,fcy[sum]);  
   sum++;  
  }  
  }  
  n=n+3;  
  printf(&quot;\n&quot;);  
  }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
In above code first for loop use for length of plaintext using index &#39;m&#39;.&lt;br /&gt;
Below Two for loop is use for 4-4 partition and store in ipt.&lt;br /&gt;
&lt;br /&gt;
then do matrix multiplication for 2x2 matrix and store in cy array.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;b&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;fcy[sum]=(cy[i][j]%26)+97; //also present in above image&lt;/code&gt;&lt;/b&gt;&lt;/pre&gt;
&lt;br /&gt;
this is use for mod with 26 and add 97 for get cipher text.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;c[ic]=cy[i][j]%26; &lt;/code&gt;&lt;b&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;//also present in above image&lt;/code&gt;&lt;/b&gt;&lt;/pre&gt;
&lt;br /&gt;
And this store numeric value of cipher text that is use for Decryption.&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Decryption:&lt;/h4&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;  count=0;  
  for(n=0;n&amp;lt;m;n++)  
  {  
   for(i=0;i&amp;lt;2;i++)  
   {  
   for(j=0;j&amp;lt;2;j++)  
   {  
    ipt[i][j]=c[count];  
    count++;  
   }  
   }  
  det=((key[0][0]*key[1][1])-(key[0][1]*key[1][0]));  
  if(det !=0)  
  {  
  for(i=0;i&amp;lt;2;i++)  
  {  
  for(j=0;j&amp;lt;2;j++)  
  {  
   if(i==0 &amp;amp;&amp;amp; j==0)  
   {  
   ikey[i][j]=key[1][1];  
   }  
   if(i==1 &amp;amp;&amp;amp; j==1)  
   {  
   ikey[i][j]=key[0][0];  
   }  
   if(i != j)  
   {  
   ikey[i][j]=-key[i][j];  
   }  
  }  
  }  
  for(i=0;i&amp;lt;2;i++)  
  {  
  for(j=0;j&amp;lt;2;j++)  
  {  
  psum=0;  
   for(k=0;k&amp;lt;2;k++)  
   {  
    psum=psum+ikey[i][k]*ipt[k][j];  
   }  
   pt[i][j]=psum;  
   while(pt[i][j] &amp;lt; 0)  
   {  
   pt[i][j]=pt[i][j]+26;  
   }  
   tpt[i][j]=pt[i][j];  
  }  
  }  
  printf(&quot;\n plain text is:&quot;);  
  psum=0;  
  for(i=0;i&amp;lt;2;i++)  
  {  
  for(j=0;j&amp;lt;2;j++)  
  {  
   fpt[psum]=(tpt[i][j]%26)+97;  
   printf(&quot;%c \t&quot;,fpt[psum]);  
   psum++;  
  }  
  }  
 }  
 else  
 printf(&quot;\n Invers not possible!!!...try with diff value of key..&quot;);  
 n=n+3;  
 printf(&quot;\n&quot;);  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
All process same as encryption.like do 4-4 partition.&lt;br /&gt;
&lt;br /&gt;
then find determinate&amp;nbsp; of array and check it is 0 or not.Whenever det=0 then decryption is not possible because inverse is infinite.&lt;br /&gt;
&lt;br /&gt;
then find inverse.here use simple if statements for better understand.&lt;br /&gt;
Matrix multiplication with cipher text&#39;s numeric value and inverse of key.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;pt[i][j]=psum;  
   while(pt[i][j] &amp;lt; 0)  
   {  
   pt[i][j]=pt[i][j]+26;  
   }  
   tpt[i][j]=pt[i][j];  &lt;/code&gt;&lt;b&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;//also present in above image&lt;/code&gt;&lt;/b&gt;&lt;/pre&gt;
&lt;br /&gt;
In this for loop store value of multiplication,but our value is also in negative therefore add value 26 till positive value not occur and store in temporary integer array &#39;tpt&#39; .&lt;br /&gt;
&lt;b&gt;why use while loop? &lt;/b&gt;&lt;br /&gt;
This while loop is for only negative value of pt because in next step we have to mod with 26.&lt;br /&gt;
We know that mod of negative is add value of 26 whenever positive value is not occur.&lt;br /&gt;
&lt;br /&gt;
like -10 mod 256 is equal to -10+256=&lt;b&gt;246&lt;/b&gt;.It is value of negative mod.&lt;br /&gt;
-275 mod 250 then -275+250 = - 25.still negative then add one more time -25+250=225.then&lt;b&gt; -275 mod 250=225&lt;/b&gt;.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;fpt[psum]=(tpt[i][j]%26)+97;  &lt;/code&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;/code&gt;&lt;b&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;//also present in above image&lt;/code&gt;&lt;/b&gt;&lt;/pre&gt;
&lt;br /&gt;
in this step we store final plain text value.here add 97 into mod value.&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Output of Full Program:&lt;/h4&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuoTQLWmKNlnPrLN8bYcwyX2pipIWjITCKVanz8AfNzldhbkBMi_dYqxxdN0r0zrhQ4m1I7AsOh4mHbaHYpxK00t3Q_1UGcVLWLVggNbeIv94hk9zv8ujjst_-v9UfEa98UCmR3Y_kcw/s1600/f.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;899&quot; data-original-width=&quot;971&quot; height=&quot;592&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuoTQLWmKNlnPrLN8bYcwyX2pipIWjITCKVanz8AfNzldhbkBMi_dYqxxdN0r0zrhQ4m1I7AsOh4mHbaHYpxK00t3Q_1UGcVLWLVggNbeIv94hk9zv8ujjst_-v9UfEa98UCmR3Y_kcw/s640/f.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h4&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;Use Download button for Code&lt;/span&gt;&lt;/h4&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;https://drive.google.com/file/d/1j-9PFVb5HPHoLUiM-7BVUnsnXyrpHCjq/view?usp=sharing&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;Download&quot; /&gt;&lt;/a&gt;&lt;/h4&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;Thank You!! &lt;/span&gt;&lt;/h4&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://noob2professional.blogspot.com/feeds/2928344623956903928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://noob2professional.blogspot.com/2018/08/hill-cipher-program-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7649821627578320923/posts/default/2928344623956903928'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7649821627578320923/posts/default/2928344623956903928'/><link rel='alternate' type='text/html' href='https://noob2professional.blogspot.com/2018/08/hill-cipher-program-in-c.html' title='Hill Cipher program in c'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/17215868470569714724</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzAElyXOOm5Irbx-RJ0dHHcn77vJ1iKvqtQLp_Enj0mGwFTFlCL8iDaih7XGXYU4Z3v5dP-_HXCFkfoKowNb6kBmwEowHfqmNPV_UlfQ5gb7tSoNOWVEvDQzJmeFhfDP5h1hJWWs89uA/s72-c/1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7649821627578320923.post-967218740914019438</id><published>2018-07-24T14:23:00.000-07:00</published><updated>2018-07-24T14:23:38.747-07:00</updated><title type='text'>Playfair Cipher program in c</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Introduction to Playfair&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The &lt;b&gt;Playfair cipher&lt;/b&gt; or &lt;b&gt;Playfair square&lt;/b&gt; or &lt;b&gt;Wheatstone-Playfair cipher&lt;/b&gt; is a manual symmetric encryption technique(&lt;b&gt;Use same key&lt;/b&gt; for encryption of plaintext and decryption of ciphertext) and was the first literal digram substitution cipher. The scheme was invented in 1854 by Charles Wheatstone, but bears the name of Lord Playfair for promoting its use.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;This technique encrypts &lt;b&gt;pairs of letters&lt;/b&gt; (bigrams or digrams), instead of single letters as in the simple substitution cipher and rather more complex cipher systems then in use.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;History of playfair&lt;/b&gt;&lt;/h3&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
It was however later used for tactical purposes by British forces in the Second Boer War and in World War I and for the same purpose by the British and Australians during World War II.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
This was because Playfair is reasonably fast to use and requires no special equipment - just a pencil and some paper.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
A typical scenario for Playfair use was to protect important but non-critical secrets during actual combat e.g. the fact that an artillery barrage of smoke shells would commence within 30 minutes to cover soldiers&#39; advance towards the next objective. By the time enemy cryptanalysts could decode such messages hours later, such information would be useless to them because it was no longer relevant. &lt;b&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Playfair Program in c&lt;/b&gt;&lt;/h3&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 1:Variables we use in program: &lt;/h4&gt;
First of all we see deceleration of variables.&lt;br /&gt;
Here basic deceleration which is use full in further code...&lt;br /&gt;
&amp;nbsp;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; #include&amp;lt;stdio.h&amp;gt;  
 #include&amp;lt;conio.h&amp;gt;  
 #include&amp;lt;time.h&amp;gt;  

 void main()  
 {  
  char key[50]={&#39;\0&#39;};  
  char o[25]={&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;,&#39;g&#39;,&#39;h&#39;,&#39;i&#39;,&#39;k&#39;,&#39;l&#39;,&#39;m&#39;,&#39;n&#39;,&#39;o&#39;,&#39;p&#39;,&#39;q&#39;,&#39;r&#39;,&#39;s&#39;,&#39;t&#39;,&#39;u&#39;,&#39;v&#39;,&#39;w&#39;,&#39;x&#39;,&#39;y&#39;,&#39;z&#39;};  
  char k[25]={&#39;\0&#39;};  
  char m[5][5]={&#39;\0&#39;};  
  char pt[50]={&#39;\0&#39;},tp[50]={&#39;\0&#39;};  
  //variable for time complexity  
  clock_t start,end;  
  double time_used;  
  int i=0,j=0,flag=0,a=0,len=0;  
  clrscr();  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Explain variable:&lt;br /&gt;
here use &lt;b&gt;time.h &lt;/b&gt;for calculate time complexity of code.&lt;br /&gt;
key : char. array it is use for enter cipher key for encryption.&lt;br /&gt;
o : this is temp. array for add alpha bates&lt;br /&gt;
k : use for Add matrix&#39;s value in 1D(one dimension) array.&lt;br /&gt;
m :It is our 5x5 matrix.&lt;br /&gt;
pt and tp:pt is use for Plain Text and tp is temporary array.&lt;br /&gt;
&lt;br /&gt;
Not understand variable don&#39;t panic...&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 2:Enter key into 1D array:&lt;/h4&gt;
In key we use only unique character so first of all remove space from key.In matrix which is 5x5 means 25 character store but we have 26 character therefore use i=j that mean whenever j come in key it will replace by i.you will see in below code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;  start=clock();  
  printf(&quot;\n\t\t||||||||||   PLAYFAIR CIPHER   ||||||||||\n&quot;);  
  printf(&quot;\n\n&quot;);  
  printf(&quot;\nEnter key:&quot;);  
  gets(key);  
  for(i=0;i&amp;lt;strlen(key);i++)  
  {  
  if(key[i]==&#39;j&#39;)  
  {  
   key[i]=&#39;i&#39;;  
  }  
  for(j=0;j&amp;lt;strlen(k);j++)  
  {  
   if(k[j]==key[i])  
   {  
   flag=1;  
   break;  
   }  
  }  
  if(flag != 1)  
  {  
   k[a]=key[i];  
   a++;  
  }  
  flag=0;  
  }  //remove same char from key and add into k  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
In above code start clock for time.using gets() retrieve value of key.First for loop is go for length of key in this check &#39;j&#39; is present in key whenever find &#39;j&#39; replace with &#39;i&#39;.&lt;br /&gt;
In second for loop check character in 1D array k[25] because unique value is require.Here use of &#39;flag&#39; , when flag=1 then skip character because it is present already in array k[25] .if flag !=1 then add this character and change flag=0.&lt;br /&gt;
&lt;br /&gt;
E.g :&quot;computer&quot; is our key here duplicate not present therefore in k enter &#39;computer&#39;&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 3:Enter extra character into 1D array:&lt;/h4&gt;
First enter key value then we also add remaining character in array.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; for(i=0;i&amp;lt;=strlen(o);i++)  
  {  
  for(j=0;j&amp;lt;strlen(k);j++)  
  {  
   if(k[j]==o[i])  
   {  
   flag=1;  
   break;  
   }  
  }  
  if(flag != 1)  
  {  
   k[a]=o[i];  
   a++;  
  }  
  flag=0;  
  }  //add extra character  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
using Two for loop, one for length of alpha bates and second for 1D array.simply check character is present in k[25] or not.Not present then add character when present then skip.&lt;br /&gt;
&lt;br /&gt;
E.g : our key is already enter in k[25] which is &quot;computer&quot; then remaining character &quot;a b c d f g h i k l n q s v w x y z&quot; is enter in key here &#39;i/j&#39; enter in one place.&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 4:One Dimension array to Two Dimension:&lt;/h4&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; a=0;  
  printf(&quot;Matrix of 5x5 is:\n&quot;);  
  for(i=0;i&amp;lt;5;i++)  
  {  
  for(j=0;j&amp;lt;5;j++)  
  {  
   m[i][j]=k[a];  
   if(m[i][j]==&#39;i&#39;)  
   {  
   printf(&quot;\t i/j&quot;);  
   }else  
   {  
   printf(&quot;\t %c&quot;,m[i][j]);  
   }  
   a++;  
  }  
  printf(&quot;\n&quot;);  
  } &lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Here &#39;a&#39; is use for index of 1D array.using this for loop we store 1D array value into 2D array and also print that value.&lt;br /&gt;
&lt;br /&gt;
Below picture of output for step 1 to 4.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS7i6ADIaIrVAlUtcX1nH1CCqPq7KMrVh_fps_tox_jIFxr95GxoqVM53WSU1_hi0G3IFJ4p6b3r_zaDaOQVWkKl27C8H0pp0TuBJLOioYSnhqy87f4Qp0zGc_1HOayETre6OK-cfipA/s1600/matrix.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;output of 5x5 matrix&quot; border=&quot;0&quot; data-original-height=&quot;478&quot; data-original-width=&quot;1573&quot; height=&quot;193&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS7i6ADIaIrVAlUtcX1nH1CCqPq7KMrVh_fps_tox_jIFxr95GxoqVM53WSU1_hi0G3IFJ4p6b3r_zaDaOQVWkKl27C8H0pp0TuBJLOioYSnhqy87f4Qp0zGc_1HOayETre6OK-cfipA/s640/matrix.jpg&quot; title=&quot;Output&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
In above output we see that character of key enter first then sequence wise entered in non repeated form.&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 5: Enter plain text and remove space&lt;/h4&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;  printf(&quot;\n&quot;);  
  printf(&quot;\n Enter PlainText:&quot;);  
  gets(pt);  
  a=0;  
  for(i=0;i&amp;lt;strlen(pt);i++)  
  {  
  if(pt[i]!=&#39; &#39;)  
  {  
   tp[a]=pt[i];  
   a++;  
  }  
  } //remove space  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Here when space is occur then skip it.And store new string in temporary variable &#39;tp&#39;.&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 6:Divide into pair of two&lt;/h4&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Playfair is work on pair of character.Here divide into two pair and check pair characters are same when character are same then add x after first character. Understand ?? &lt;b&gt;No It&#39;s Ok...&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
E.g: Our Plan Text is &quot;information&quot;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
First divide into two of pair&amp;nbsp; &quot;in fo rm at io n&quot; but we need two pair here &#39;n&#39; is alone therefore we enter &#39;x&#39; after &#39;n&#39; so new plaintext is &quot;in fo rm at io nx&quot;.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
second example: our plain text is &quot;hello&quot; then&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&quot;he ll o&quot; is divide in pair but &#39;ll&#39; is same character in pair therefore add &#39;x&#39; after &#39;l&#39;.then new plaintext pair is &quot;he lx lo&quot;. &lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_T86vUf1WYVe8b4sJnf2GvJ2yFNppf0R-GDH4ALzTr4TFEEw60VH1kvMYH7jEMrbpijqxN_C82xGPc5aXPtjMR0ai0edXZXh8DqKDko4GFaX3vJm-XdzQE5a4WBrNh74-EZ8YVWrEOg/s1600/hello.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;175&quot; data-original-width=&quot;736&quot; height=&quot;95&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_T86vUf1WYVe8b4sJnf2GvJ2yFNppf0R-GDH4ALzTr4TFEEw60VH1kvMYH7jEMrbpijqxN_C82xGPc5aXPtjMR0ai0edXZXh8DqKDko4GFaX3vJm-XdzQE5a4WBrNh74-EZ8YVWrEOg/s400/hello.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; len=strlen(tp);  
  a=0;  
  for(i=0;i&amp;lt;len;i++)  
  {  
  if(tp[i]==tp[i+1])  
  {  
   pt[a]=tp[i];  
   pt[a+1]=&#39;x&#39;;  &lt;/code&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;//add x when two same character &lt;/code&gt;
   a=a+2;  
  }else  
  {  
   pt[a]=tp[i];  
   pt[a+1]=tp[i+1];  
   i=i+1;  
   a=a+2;  
  }  
  }  
  if(strlen(pt)%2 !=0)  
  {  
  pt[a-1]=&#39;x&#39;;  
  }  // add x when last character is alone
  printf(&quot;\n New PlainText:&quot;);  
  puts(pt);  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 7:Call Playfair function:&lt;/h4&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
First add function &lt;b&gt;above main&lt;/b&gt; function:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; void playfair(char [50],char [5][5]);  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
then write below code in main:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; playfair(pt,m);  
  end=clock();  
  time_used=((double)(end-start))/CLOCKS_PER_SEC;  
  printf(&quot;\n time taken=%f sec&quot;,time_used);  
  getch();  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
In function we send plain text which is &#39;pt&#39; and 2D array &#39;m&#39;.&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 8:Playfair Function:&lt;/h4&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;/h4&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; void playfair(char pt[50],char m[5][5])  
 {  
  int i=0,j=0,k=0,a=0;  
  char cy[50]={&#39;\0&#39;};  
  int x1=0,y1=0,x2=0,y2=0;  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
First of all see variable that is use in this function&lt;br /&gt;
cy: it is character array for ciphertext.&lt;br /&gt;
&lt;br /&gt;
Here &lt;b&gt;Three Rule&lt;/b&gt; of cipher text:&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;Same Column&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Same Row&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Rectangle&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
Take one pair and check in 5x5 matrix for this rule.&lt;br /&gt;
&lt;b&gt; &lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitDTSfKbi-9E3CMOYYlob5mpeLHdNSRpjsTUFAnW1H0Gfc3yY6r1D5OzA61kK7hZWPhemErxePR2OMTLoKx_NdrB4DqaW7zwHhn41GhecTIPxBivC40FXbrMGwJOrptTPvsKx4eEy8iQ/s1600/cy1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1200&quot; data-original-width=&quot;1600&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitDTSfKbi-9E3CMOYYlob5mpeLHdNSRpjsTUFAnW1H0Gfc3yY6r1D5OzA61kK7hZWPhemErxePR2OMTLoKx_NdrB4DqaW7zwHhn41GhecTIPxBivC40FXbrMGwJOrptTPvsKx4eEy8iQ/s640/cy1.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt; &lt;/b&gt;&lt;br /&gt;
&lt;b&gt;1) Same Column: &lt;/b&gt;When pair characters are in same column then use down character for cipher text.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGl0Z4jdZrpD_clCoREqUljIHfV8JNOv8fK8D27trcIdCTdlvUbKsg1HbSrCDfQs4IeICLfMlqahh9waziFmd3ZX8_uBo1Dc3_5RNgfNgjTWki-EP7XS1WY36N7WqFr0gmrvUZN8rCcw/s1600/cy2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1200&quot; data-original-width=&quot;1600&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGl0Z4jdZrpD_clCoREqUljIHfV8JNOv8fK8D27trcIdCTdlvUbKsg1HbSrCDfQs4IeICLfMlqahh9waziFmd3ZX8_uBo1Dc3_5RNgfNgjTWki-EP7XS1WY36N7WqFr0gmrvUZN8rCcw/s640/cy2.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;2) Same Row: &lt;/b&gt;When pair in same row then use next character for cipher text.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMDP0VvrnqrtlpER4E16aP1cE4MYNDu_MQwpMbVjCNqo1Ahtp2GooBoe1LF0nPfgNjfZJJ5foBwD5QwN7sk7wAfReb4WV6Sdy5gTxrjmzK-rAOVBAflrphdQIJx-7GkRIMtfDO3TrMOQ/s1600/cy3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1200&quot; data-original-width=&quot;1600&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMDP0VvrnqrtlpER4E16aP1cE4MYNDu_MQwpMbVjCNqo1Ahtp2GooBoe1LF0nPfgNjfZJJ5foBwD5QwN7sk7wAfReb4WV6Sdy5gTxrjmzK-rAOVBAflrphdQIJx-7GkRIMtfDO3TrMOQ/s640/cy3.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;3) Rectangle: &lt;/b&gt;When pair make rectangle then use corner of character match in matrix.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOc55JhV6sRXPWguwKcrgnqiWwu3IFbSd7l8ck_IP-dUPoHei4K6Sn0dKpbMLT3XbCjbYwSXI46u3ZHfRwj_SEDzsxcs1i9Ey6ecXwqIn238ryx1CHtp8HJqxKIQjiKsFxymw-ImILyA/s1600/cy4.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1200&quot; data-original-width=&quot;1600&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOc55JhV6sRXPWguwKcrgnqiWwu3IFbSd7l8ck_IP-dUPoHei4K6Sn0dKpbMLT3XbCjbYwSXI46u3ZHfRwj_SEDzsxcs1i9Ey6ecXwqIn238ryx1CHtp8HJqxKIQjiKsFxymw-ImILyA/s640/cy4.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;code for this rule:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&lt;/b&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; for(k=0;k&amp;lt;strlen(pt);k++)  
  {  
   for(i=0;i&amp;lt;5;i++)  
   {  
   for(j=0;j&amp;lt;5;j++)  
   {  
    if(m[i][j]==pt[k])  
    {  
      x1=i;  
      y1=j;  
    }  
    if(m[i][j]==pt[k+1])  
    {  
     x2=i;  
     y2=j;  
    }  
   }  
   }  
       if(y1==y2) //.............same column rule:1  
       {  
            x1++;  
            x2++;  
           if(x1&amp;gt;4)  
           {  
                x1=0;  
           }  
           if(x2&amp;gt;4)  
           {  
                 x2=0;  
           }  
            cy[a]=m[x1][y1];  
            a++;  
            cy[a]=m[x2][y2];  
            a++;  
       }     //.............rule:1 done  
      else if(x1==x2) //..............................rule:2 same row  
      {  
            y1++;  
            y2++;  
            if(y1&amp;gt;4)  
            {  
                 y1=0;  
            }  
            if(y2&amp;gt;4)  
            {  
                 y2=0;  
            }  
            cy[a]=m[x1][y1];  
            a++;  
            cy[a]=m[x2][y2];  
            a++;  
      }else if(x1!=x2 &amp;amp;&amp;amp; y1!=y2) //..........rule:3  
      {  
       cy[a]=m[x1][y2];  
       a++;  
       cy[a]=m[x2][y1];  
       a++;  
      } //.........................rule:3 done  
   k=k+1;  
  }  
  printf(&quot;\n Cipher text is:&quot;);  
  puts(cy);  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
here we have ciphertext: &quot;in fo rm at io nx&quot; ==&amp;gt; &quot;gs le gr be fu xm&quot;&lt;br /&gt;
&lt;br /&gt;
Here encryption is done...&lt;br /&gt;
But also we have convert ciphertext into plaintext at receiving side therefore use Decryption.&lt;br /&gt;
&lt;br /&gt;
&quot;Decryption is inverse process of encryption&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 9: Decryption&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&lt;/b&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; a=0;  
  for(k=0;k&amp;lt;strlen(cy);k++)  
  {  
      for(i=0;i&amp;lt;5;i++)  
      {  
           for(j=0;j&amp;lt;5;j++)  
           {  
            if(m[i][j]==cy[k])  
            {  
             x1=i;  
             y1=j;  
            }  
            if(m[i][j]==cy[k+1])  
            {  
             x2=i;  
             y2=j;  
            }  
           }  
      }  
      if(y1==y2) //.........rule:1  
      {  
           if(x1==0)  
           {  
            x1=4;  
           }else  
           {  
            x1--;  
           }  
           if(x2==0)  
           {  
            x2=4;  
           }else  
           {  
            x2--;  
           }  
           pt[a]=m[x1][y1];  
           a++;  
           pt[a]=m[x2][y2];  
           a++;  
      }else if(x1==x2) //..........rule:2  
      {  
           if(y1==0)  
           {  
            y1=4;  
           }else  
           {  
            y1--;  
           }  
           if(y2==0)  
           {  
            y2=4;  
           }else  
           {  
            y2--;  
           }  
           pt[a]=m[x1][y1];  
           a++;  
           pt[a]=m[x2][y2];  
           a++;  
      }else if(x1!=x2 &amp;amp;&amp;amp; y1!=y2)  //............rule:3  
      {  
       pt[a]=m[x1][y2];  
       a++;  
       pt[a]=m[x2][y1];  
       a++;  
      }  
      k=k+1;  
  }  
  printf(&quot;\n Plain Text:&quot;);  
  puts(pt);  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Using cipher text &#39;cy&#39; and inverse of encryption we can generate plaintext.&lt;br /&gt;
&lt;br /&gt;
Here &lt;b&gt;Main Output&lt;/b&gt; of code :&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCfLbLRU4TuiTCxp-c_NsjGx8cj9ZJv8tmZEGlrb4xuXiXqizz44ligX5MncrQVYu8Jsq51pgcI8qs_ygBh6cd10ZWpAn7G44IPpWsN77pee1Wlth8ssk56oPLSS1IkvIUAddXZQ26Fg/s1600/main.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;900&quot; data-original-width=&quot;1600&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCfLbLRU4TuiTCxp-c_NsjGx8cj9ZJv8tmZEGlrb4xuXiXqizz44ligX5MncrQVYu8Jsq51pgcI8qs_ygBh6cd10ZWpAn7G44IPpWsN77pee1Wlth8ssk56oPLSS1IkvIUAddXZQ26Fg/s640/main.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Below You Can download code in .txt file:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://drive.google.com/file/d/1vMPCi2HbRiyUSxy6BdcE3JgH8DA4BlD2/view?usp=sharing&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;Download&quot; /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Thank you!! &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://noob2professional.blogspot.com/feeds/967218740914019438/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://noob2professional.blogspot.com/2018/07/playfair-cipher-program-in-c.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/7649821627578320923/posts/default/967218740914019438'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/7649821627578320923/posts/default/967218740914019438'/><link rel='alternate' type='text/html' href='https://noob2professional.blogspot.com/2018/07/playfair-cipher-program-in-c.html' title='Playfair Cipher program in c'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/17215868470569714724</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS7i6ADIaIrVAlUtcX1nH1CCqPq7KMrVh_fps_tox_jIFxr95GxoqVM53WSU1_hi0G3IFJ4p6b3r_zaDaOQVWkKl27C8H0pp0TuBJLOioYSnhqy87f4Qp0zGc_1HOayETre6OK-cfipA/s72-c/matrix.jpg" height="72" width="72"/><thr:total>3</thr:total></entry></feed>