Question

10- Coding Style 15 - Compilation 10 - Makefile with default, clean, and run rules 05 - Code is warning free 75- Implementati

i want to implement a caesae cypher program in C given input.txt to be cyphered.

for example. assume the file input.txt contains

'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG'

when i run $./cypher input.txt 3 on terminal

we get out put of

'WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ'

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
   static int a[26];
   int i=0,j,m,key;
   char mes[100],res[100];
   char ch;
   FILE *fp;
   key=atoi(argv[2]);
   fp=fopen(argv[1],"r");
   i=0;
   while ( 1 )
   {
       ch = fgetc ( fp ) ;
       if ( ch == EOF )
           break ;
       mes[i]=ch;
       i++;
   }
   //printf("%s",mes);
   fclose(fp);
   for(i=0;mes[i]!='\0';i++)
   {
       ch=mes[i];      
       if(ch>='a' && ch<='z')
       {
           ch=ch+key;
           if(ch>'z')
           {
               ch=ch-'z'+'a'-1;
           }
       }  
       else if(ch>='A' && ch<='Z')
       {
           ch=ch+key;
           if(ch>'Z')
           {
               ch=ch-'Z'+'A'-1;
           }
       }
       res[i]=ch;
   }
   printf("\n%s\n",res);

   return 0;
}

Activities Terminal ▼ Sun 12:58 PM Open- A cipher.c cipher.c output.txt #include«string.h> #include<stdlib.h> int nain(int ar

Add a comment
Know the answer?
Add Answer to:
I want to implement a caesae cypher program in C given input.txt to be cyphered. for example. ass...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You're to write a C++ program that analyzes the contents of an external file called data.txt....

    You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT