The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Sunday, November 11, 2012

implement Transposition cipher encryption and decryption technique

#include<stdio.h>
#include<conio.h>
#include<string.h>

char mssg[100],a[50],b[50],dmssg[100];
 
void get_mssg()
{
   printf("\n Enter the Plaintext : ");
   gets(mssg);
}

void en_mssg()
{
  int i=0,k=0,j;
 
  if(strlen(mssg)%2 == 0)
    j = strlen(mssg)/2;
  else
    j = strlen(mssg)/2+1;   
   
  while(i<strlen(mssg))
  {
   dmssg[k++] = mssg[i++];     

   if(mssg[i] == '\0')
    dmssg[j++] = '\0';        
   else
    dmssg[j++] = mssg[i++];  
  }  
  dmssg[i] = '\0';   
 
  printf("\n The Ciphertext is : ");
  puts(dmssg);
}

void de_mssg()
{
  int i=0,j,k=-1;
 
  if(strlen(dmssg)%2 == 0)
    j = strlen(dmssg)/2;
  else
    j = strlen(dmssg)/2+1; 
 
  int l = j;
  while(i < l && j < strlen(dmssg))
  {
    mssg[++k] = dmssg[i];   ++i;   mssg[++k] = dmssg[j];    ++j;         
  } 

  if(i<l)
   mssg[++k] = dmssg[i];
 
  printf("\n The Decrypted Plaintext is : ");
  puts(mssg);
}

int main()
{
  get_mssg();  en_mssg();  de_mssg(); 
  return 0; 
}

No comments:

Post a Comment