1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
rjkz [21]
3 years ago
8

Write a program that encrypts and decrypts a string of characters. Use a char array for this, not the string class. The maximum

length of a string input to the program will be 200 characters. The input may contain blanks and other whitespace. Your program must request a c-string from the user and encrypt it as described below. If the user enters a single asterisk as the only thing on a line, the program should stop. Otherwise, encrypt the string, then display the encrypted version. Decrypt it using the inverse of the algorithm below and display the result. This should be the original string. Then go back and request another string.
Computers and Technology
1 answer:
dem82 [27]3 years ago
3 0

Answer:

C++ code for encryption is given below

Explanation:

#include <iostream>

using namespace std;

//functions to encrypt and decrypt

void encrypt(char str[]);

void decrypt(char str[]);

int main(){

char str[200];

bool done = false;

while(!done){

cout << "Enter a string (enter * to stop): ";

cin.getline(str, 200);

if(str[0] == '*' && str[1] == '\0')

done = true;

else{

encrypt(str);

cout << "Encrypted: " << str << endl;

decrypt(str);

cout << "Decrypted: " << str << endl;

}

cout << endl;

}

}

void encrypt(char str[]){

int i = 1;

for(int j = 0; str[j] != '\0'; j++){

str[j] += i;

i++;

if(i == 11)

i = 1;

}

}

void decrypt(char str[]){

int i = 1;

for(int j = 0; str[j] != '\0'; j++){

str[j] -= i;

i++;

if(i == 11)

i = 1;

}

}

You might be interested in
Write multiple if statements. if caryear is 1969 or earlier, print "probably has few safety features." if 1970 or higher, print
aliina [53]
If( caryear >= 2000 ):
    print "probably has air bags.\n"
elif( caryear >= 1990 ):
    print "probably has anti-lock brakes.\n"
elif( caryear >= 1970 ):
    print "probably has seat belts.\n"
else:
    print "probably has few safety features.\n"

4 0
2 years ago
Write an algorithm that receives a number from the user (you can store the number in a variable called N). Then the algorithm sh
lbvjy [14]

Answer:

Algorithm:

1. Declare an integer variable N.

2. Read the value N from user.

3.While(N):

 3.1 find r=N%10;

 3.2 print r in new line.

 3.3 Update N as N=N/10.

4.end program.

Implementation in C++.

// header

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variable

int N;

cout<<"Enter an Integer:";

   cin>>N;

// find the digits of number

   while(N)

   {

       // last digit

       int r=N%10;

       // print last digit

       cout<<r<<endl;

       // update the number

       N=N/10;

}

return 0;

}

Output:

Enter an Integer:329                                        

9                                                          

2                                                          

3

7 0
3 years ago
Suppose you are using a Mac to read your e-mail messages, and you receive an
Gekata [30.6K]

Answer:

D

Explanation:

4 0
3 years ago
Read 2 more answers
What is the correct name for the words Home, Insert, Design, Layout, References, etc. in the ribbon in Word 2016?
KIM [24]

Answer:

Option (B) i.e.,Tabs is the correct option.

Explanation:

Because the followings are the tabs in the ribbon of Ms Word 2016, with the help of the tabs we can edit, update, modify, design, change or insert layout and also we can insert themes, etc in our document. These tabs are important to create our document attractive and provide good designs in the document. We also create business cards, invitation card and other important things with the help of tabs.

7 0
2 years ago
Read 2 more answers
This is a legitimate question if you have a problem then just ignore it. What is the difference between CRVM and SAPX in a progr
g100num [7]

Answer: SAPX is used with Java

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • Suppose an array with six rows and eight columns is stored in row major order starting at address 20 (base 10). If each entry in
    8·1 answer
  • AMSCO networks plans to conduct a poll of viewers during the SuperBowl. They will conduct analysis to determine which area of th
    6·2 answers
  • According to your textbook, which of the following is a consequence of the quick development of new technologies in the digital
    8·1 answer
  • Which information is necessary to determine an object's speed?
    13·1 answer
  • Which view is used to allow a publisher to view facing pages of a publication at the same time? Normal Master Page Two-Page Spre
    5·1 answer
  • Write a method called sum with a while loop that adds up all numbers between two numbers a and b. The values for a and b can be
    11·2 answers
  • How can I make [ print(3 * x) ] into a functional python code?
    8·1 answer
  • Greg wants to check the amount of requests his website receives. What test can he use?
    6·1 answer
  • Predict the output
    7·1 answer
  • Business use a fax cover sheet is to
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!