Question

C Program Type a program in C to encode the message with Caesar's cipher. Your program...

C Program
Type a program in C to encode the message with Caesar's cipher. Your program will receive a text message, and the key value will then generate an encryption text for the given message. 
example:
Enter a message to encrypt: axzd
Enter key: 4
Encrypted message: ebdh

**Make sure your program can check that the given message is not empty AND Your program must include a helper function that accepts the input message and checks that it contains only characters before generating the ciphertext

Homework Answers

Answer #1

#include<iostream>  

using namespace std;

int main()

{

char message[100], ch;

int i, key, check=0;

printf("Enter a message to encrypt: ");

do{

gets(message);

check=helper_fun(message);

} while (check== 0 || message.empty());

printf("Enter key: ");

scanf("%d", &key);

for(i = 0; message[i] != '\0'; ++i){

ch = message[i];

if(ch >= 'a' && ch <= 'z'){

ch = ch + key;

if(ch > 'z'){

ch = ch - 'z' + 'a' - 1;

}

message[i] = ch;

}

else if(ch >= 'A' && ch <= 'Z'){

ch = ch + key;

if(ch > 'Z'){

ch = ch - 'Z' + 'A' - 1;

}

message[i] = ch;

}

}

printf("Encrypted message: %s", message);

return 0;

}

int helper_fun(char s[100] )

{

int i,F=0;

For(i=0;i<s.length();i++)

{

If(isalpha(s[i])!=0)

F=1;

}

If(F==0)

return 1;

else {

cout<<”contains characters other than alplabets or letters”;

return 0;

}

}

Please make changes according to your ide.

Know the answer?
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
Similar Questions
For the following question figure out what cipher was used to encode the following encrypted message....
For the following question figure out what cipher was used to encode the following encrypted message. The text has been encrypted using one of the following ciphers (Caesar, Rail Fence, Vigenere, or Playfair): Fc risdzwche mrw gcne. Fvm xyxfi-xoeboc dcelqztaqcbizq. The key is also encoded: wsgmephmpiqqe (C+4) The key is : The message is: The key was encrypted using a cipher, which is a simple substitution cipher. The message was encoded using a cipher.
Vigenère Cipher. In the Vigenère Cipher, we use a special keyword to encrypt a message. We...
Vigenère Cipher. In the Vigenère Cipher, we use a special keyword to encrypt a message. We represent each letter of the alphabet as a number from 0-25. In order, we add each letter from the keyword to the message and mod by 26. If the keyword is shorter than the message, we simply repeat the keyword. For example, lets say that the message is HOWSTUFFWORKS and the keyword is CIPHER. The following table shows how we can find the final...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
NWS620S Tutorial 1: Symmetric Encryption - DES Encryption is the translation of data into a secret...
NWS620S Tutorial 1: Symmetric Encryption - DES Encryption is the translation of data into a secret code so that only authorised entities can read it. Encrypting data is considered a very effective way of achieving data security. To access encrypted data, you must have access to a secret key that enables you to decrypt it. Unencrypted data is called plain text; encrypted data is referred to as cipher text. There are two types of encryption: • Symmetric encryption • Asymmetric...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....
In c++ format please Bank Charges A bank charges $10 per month plus the following check...
In c++ format please Bank Charges A bank charges $10 per month plus the following check fees for a commercial checking account: $.10 each for fewer than 20 checks $.08 each for 20–39 checks $.06 each for 40–59 checks $.04 each for 60 or more checks The bank also charges an extra $15 if the balance of the account falls below $400 (before any check fees are applied). Write a program that asks for the beginning balance and the number...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT