Question

Kindly follow the instructions provided carefully.

C programming  

Project 6, Program Design One way to encrypt a message is to use a date’s 6 digits to shift the letters. For example, if a da

1) Name your program date_encrypt.c 2) The output file name should be the same name but an added extension of .ecp. Assume th

The function expects message to point to a string containing the message to be encrypted; date represents an integer array of

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

date_encrpyt.c:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void encrypt(char* message,int date[],int n)
{
int i=0;
for(i=0;i<n;i++)
{
char ch=message[i];
if( ch>='a' && ch<='z' ) //if it is lower
       {
           int cip=(int)ch+date[i%6]; //adding shift
           if(cip>=123) //wrapping aroud
               cip=cip%122 +96;
message[i]=(char)cip;
       }
       if (ch>='A' && ch<='Z') //f it is upper case
{
           int cip=(int)ch+date[i%6]; //adding shift
           if(cip>=91) //wrapping around
               cip=cip%90 +64;
message[i]=(char)cip;
}
}
  
}
int main()
{
   char *msg; //character pointer
char message[10000]; //message array to store line of the file
   FILE *fptr,*fptrout; //pointer to open and write to files
   char inp_filename[100];
   char out_filename[100];
   char dateArr[6];
   int date[6];
   int i;
   //reading input file
   printf("Enter the file name: ");
   scanf("%s",inp_filename);
   if ((fptr = fopen(inp_filename, "r")) == NULL) {
printf("Error! opening file");
exit(1);
}
   //reading date
   printf("Enter date in 6 digit format: ");
   scanf("%s",dateArr);
   for(i=0;i<6;i++)
       date[i]=dateArr[i]-'0';
  

// opening output file for writing message
   fptrout=fopen(strcat(inp_filename,".ecp"),"w");
   if(fptrout == NULL)
{
printf("Unable to create file.\n");
exit(1);
}

  
  
   //encrypting line by line and writing into output file
while (fgets(message,150, fptr)) { //reads a line in one iteration
       msg=message;
       encrypt(msg,date,strlen(message)); //calling encrypt method
       fputs(msg, fptrout); //writing to output file
}
   printf("Output file name: %s\n",strcat(inp_filename,".ecp"));
   fclose(fptr);
   fclose(fptrout);      

return 0;
}

OUTPUT:

En * M 0) 6:42 AM kalyantvk@kalyantvk-Lenovo-G50-80:-/HomeworkLib/HomeworkLib kalyantvkakalyantvk-Lenovo-G50-80:-/HomeworkLib/HomeworkLib$ gcc date_ePlease rate my answer if you liked it.

Add a comment
Know the answer?
Add Answer to:
Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt...
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
  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • Security is an important feature of information systems. Often, text is encrypted before being sent, and...

    Security is an important feature of information systems. Often, text is encrypted before being sent, and then decrypted upon receipt. We want to build a class (or several classes) encapsulating the concept of encryption. You will need to test that class with a client program where the main method is located. For this project, encrypting consists of translating each character into another character. For instance, if we consider the English alphabet, including characters a through z, each character is randomly...

  • USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is...

    USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...

  • I need help programming this program in C. 1.) Write a program that reads a message,...

    I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...

  • Python program Use the provided shift function to create a caesar cipher program. Your program s...

    python program Use the provided shift function to create a caesar cipher program. Your program should have a menu to offer the following options: Read a file as current message Save current message Type in a new message Display current message "Encrypt" message Change the shift value For more details, see the comments in the provided code. NO GLOBAL VARIABLES! Complete the program found in assignment.py. You may not change any provided code. You may only complete the sections labeled:#YOUR...

  • WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you...

    WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode that takes two parameters: key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext. a...

  • ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of...

    ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...

  • Write the programming C please, not C++. The main function should be to find the offset...

    Write the programming C please, not C++. The main function should be to find the offset value of the ciper text "wPL2KLK9PWWZ7K3ST24KZYKfPMKJ4SKLYOKRP4KFKP842LK0ZTY43 " and decrypt it. In cryptography, a Caesar Cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be...

  • 1) Echo the input: First, you should make sure you can write a program and have...

    1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...

  • Programming in C. Name this program schwifty.c - This program reads a text file and makes...

    Programming in C. Name this program schwifty.c - This program reads a text file and makes it schwifty, but the user determines the schwiftiness. The user supplies the filename to schwift and a string containing a sequence of the following characters to determine the schwiftiness via command line arguments: L - Left shift each character in a word: hello --> elloh R - Right shift each character in a word: elloh --> hello I - Shift the letters' and digits'...

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