Question

ior new tr k%2005%281 %29, You are just hired by Google as a senior software developer and your supervisor assigns you the following task: You are responsible for the development of a program that encrypts and decrypts text messages using the Caesar shift, which is one of the oldest and widely known forms of encryption Caesar shift is a type of substitution encryption method in which each letter in the text is shifted a fixed mumber of positions down the alphabet. For example, a shift of 3 would change the letter A to D, B to E, and so on. Z would shift back around to C. The method is named after Julius Caesar, who used it to communicate with his generals Your program should prompt the user to enter a message, it will then encode the message by shifting it4 characters over, and decode it again. A sample run of your program should look like this: Enter a message: this is a test! THIS IS A TEST! THIS IS A TEST! Requirements: The program will prompt the user to enter a message . You must declare two functions, one to encode and the other to decode the message .You can store the message m an array of characters, C-String, os string You are free to choose any of the three . The message must be converted to upper case o You are only expected to encode and decode letters, not numbers or symbols. . Name the source file for your program program5.cpp

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

#include<stdio.h>
#include<string.h>
#include <ctype.h>
#include <iostream>
#include<string>
using namespace std;
void encode(string& arr,int n);
void decode(string& arr,int n);


int main()
{
string arr;int shift=4,i;
printf("Enter a message : ");
std::getline (std::cin,arr);//accept string
for(i=0;i<arr.size();i++)//convert to uppercase
{
arr[i]=toupper(arr[i]);
}
cout<<arr<<endl;//print uppercase
encode(arr,arr.size());//encode message
cout<<arr<<endl;
decode(arr,arr.size());//decode message
cout<<arr<<endl;
return 0;
}
void encode(string& arr,int n)
{int i=0;
for(i=0;i<n;i++)
if(isalpha(arr[i]))//if alphabet then shift 4
{arr[i]=(arr[i]-'A'+4)%26+'A';}
}
void decode(string& arr,int n)
{int i=0;
for(i=0;i<n;i++)
if(isalpha(arr[i]))//if alphabet then shift -4
{arr[i]=(arr[i]-'A'-4)%26+'A';}
}

四ウ勇 緊自49 all 10:37 AM hitesh 1-0N> status x someone com X @lor New Tr K%2 @replit-Thosec x c++-why is st X % Passing by refe

Add a comment
Know the answer?
Add Answer to:
ior new tr k%2005%281 %29, You are just hired by Google as a senior software developer...
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 will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • Can someone please help me for this assignment? Cryptography — the science of secret writing —...

    Can someone please help me for this assignment? Cryptography — the science of secret writing — is an old science; the first recorded use was well before 1900 B.C. An Egyptian writer used previously unknown hieroglyphs in an inscription. We will use a simple substitution cypher called rot13 to encode and decode our secret messages. ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in...

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

  • JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information...

    JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information being exposed, it is becoming more and more important to find ways to protect our sensitive data. In this program we will develop a simple tool that helps users generate strong passwords, encrypt and decrypt data using some cyphering techniques. You will need to create two classes. The first class is your driver for the application and contains the main method. Name this class...

  • In C please : The tasks in this exam review exercise are structured in levels. You...

    In C please : The tasks in this exam review exercise are structured in levels. You can see the point distribution for the levels at the end. It is strongly recommended that you ensure you have passed all test cases of lower levels before moving up to a higher level. For example, ensure you have completed all Level 0 and 1 tasks before even looking at Level 2 Tasks. MESSAGE ENCODER LEVEL 0: (test cases - 50 points) Start by...

  • cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having...

    cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having heard you are taking CS 55, your boss has come to ask for your help with a task. Students often come to ask her whether their GPA is good enough to transfer to some college to study some major and she has to look up the GPA requirements for a school and its majors in a spreadsheet to answer their question. She would like...

  • 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...

  • 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...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

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