Contact Learn C
Copy

Program 216:Rail Fence Cipher using C

Program 216: What is Rail Fence Code
 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
 int i,j,len,rails,count,code[100][1000];
    char str[1000];
    printf("Enter a Secret Message\n");
    gets(str);
    len=strlen(str);
 printf("Enter number of rails\n");
 scanf("%d",&rails);
 for(i=0;i<rails;i++)
 {
  for(j=0;j<len;j++)
  {
   code[i][j]=0;
  }
 }
count=0;
j=0;
while(j<len)
{
if(count%2==0)
{
 for(i=0;i<rails;i++)
 {
  //strcpy(code[i][j],str[j]);
  code[i][j]=(int)str[j]; 
  j++;
 }
 
}
else
{

 for(i=rails-2;i>0;i--)
 {
  code[i][j]=(int)str[j];
 j++;
 }  
} 

count++;
}

for(i=0;i<rails;i++)
{
 for(j=0;j<len;j++)
 {
  if(code[i][j]!=0)
  printf("%c",code[i][j]);
 }
 
}
printf("\n");
}

Explanation:
for rails of 3
Pre explanation of logic:-






//Coming Soon

Output: Should consider even Spaces

Rail Fence Cipher



 

4 comments:

  1. can you share code for decryption??

    ReplyDelete
  2. please also provide decryption code also.

    ReplyDelete
  3. Watch and Download world's famous drama series Kurulus Osman in English on link below
    👇
    Kurulus Osman in English

    📢Get high quality backlinks for your
    Website with BacklinksIndexer
    BacklinksIndexer

    Crypto trading online course
    Join on link below
    Crypto quantum leap

    📒 Read Home doctor book online
    Then you will be a doctor for your family
    Home Doctor Book

    Join online YouTube course
    And be a professional YouTuber
    Tube Mastery and Monetization by matt

    🦷Steel Bite Pro
    Best product for
    Teeth pain, cavities,teeth whitening and other oral health issues with money back guarantee
    Steel Bite Pro

    ReplyDelete
  4. If you are thinking about installing fencing around your new home there are a few things to think about before you do so. 937 My Fence

    ReplyDelete

Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide