Monday, December 26, 2016

Simple Rail Fence - Encryption using C program.

Rail fence Simple - Encryption implementation using C program.

#include<stdio.h>
int main()
{
  char str[20]="HelloStudent", str1[10]="", str2[10]="";
  int i, cnt1=0, cnt2=0;
  printf("Rail Fence - Encryption\n\n");
  printf("Plain Text: HelloStudent\n\n");

  for(i=0; i<strlen(str); i++)
  {
    if( i%2 == 0)
    {
      str1[cnt1++]=str[i];
    }
    else
  str2[cnt2++]=str[i];
  }
  printf("Cipher Text: %s%s",str1,str2);
  return 0;
}

Output of the program:

Rail Fence - Encryption

Plain Text: HelloStudent

Cipher Text: HlotdnelSuet


* * * * *
* * * * *

2 comments:

  1. What is the cnt1 and cnt 2 line 13 and line 16??

    ReplyDelete
    Replies
    1. cnt1 and cnt2 are counter variables used to track characters stored at odd and even number of positions in string respectively.

      Let me know if you have any further query in this regards.

      With best wishes...

      Delete