Day_10

Comment:  This homework took me a few hours to finish, I had David helped me with getting the code to work. He mentioned using the ASCii table and using that, we can increase the array by two because, every character has an hex or decimal integer associated with it.


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void encrypt(char arr[])
{
 int i;
 for(i=0;i<strlen(arr);i++)
 {
   char ch;
 
   ch=arr[i];
 
   if(ch == 'y')
   {
   ch = 97 ;
   arr[i] = ch;
   }
   else if(ch == 'z' )
 
   {
    ch =98;
    arr[i] = ch;
   }
   else
   {
   arr[i] = ch+2;
   }
 }
}
void decrypt(char arr[])
{
 int i;
 for(i=0;i<strlen(arr);i++)
 {
   char ch;
  ch=arr[i];

  if(ch=='a')
  {
  ch=79;
  arr[i] = ch;
  }
  else if(ch =='b')
  {
  ch=78;
  arr[i]=ch;
  }
  else
  {
  arr[i] = ch-2;
  }
 }
}
int main()
{

 char msg[100];
 printf("Enter your message:");
 gets(msg);
 printf("Encrypted Version:\n");
 encrypt(msg);
  printf("%s",msg);
 printf("\nDecrypted Version:\n");
 decrypt(msg);
 printf("%s",msg);
 return 0;
}


Comments

Popular posts from this blog

Day_13

Day 18 WH