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 ;)

Wednesday, November 14, 2012

Implement Ceaser Substitution Cipher encryption and decryption technique

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

char mssg[100];
int k;
 
void get_mssg()
{
   printf("\n Enter the Plaintext (in caps): ");
   gets(mssg);
   printf("\n Enter the key (less than 26): ");
   scanf("%d",&k);
}

void en_mssg()
{
  int i = 0;
  while(mssg[i] != '\0')
  { 
    if(mssg[i] >= 65 && mssg[i] <= 90)          
     mssg[i] = ((mssg[i] - 65 + k) % 26)+65;
    i++;

  } 
  printf("\n The Ciphertext is : ");
  puts(mssg);
}

void de_mssg()
{
  int i = 0;
  while(mssg[i] != '\0')
  { 
    if(mssg[i] >= 65 && mssg[i] <= 90)    
    {    
      if((mssg[i]-65) >= k)
       mssg[i] = mssg[i] - k;
      else
       mssg[i] = 90-(k-(mssg[i]-65))+1;
    }     
    i++;
  } 
  printf("\n The Decrypted Plaintext is : ");
  puts(mssg);
}


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

No comments:

Post a Comment