(Simple Encryption) Some information on the Internet may be encrypted with a simple al- gorithm known as “rot13,” which rotates each character by 13 positions in the alphabet. Thus, 'a' corresponds to 'n', and 'x' corresponds to 'k'. rot13 is an example of symmetric key encryption. With symmetric key encryption, both the encrypter and decrypter use the same key.

a) Write a program that encrypts a message using rot13.
b) Write a program that decrypts the scrambled message using 13 as the key.
c) After writing the programs of part (a) and part (b), briefly answer the following question: If you did not know the key for part (b), how difficult do you think it would be to break the code? What if you had access to substantial computing power (e.g., supercomputers)? In Exercise 18.25 we ask you to write a program to accomplish this.


```
// When solving Part B of this exercise, you might find it more
// convenient to only use uppercase letters for your input.
#include
#include
using namespace std;

int main()
{
string m; // to store input
int key = 13; // Our key for encryption

cout << "Enter a string: ";
getline( cin, m );

string::iterator mi = m.begin(); // using function begin

// loop through the string
while ( mi != m.end() )
{
*mi += key;
mi++;
} // end while

cout << "\nEncrypted string is: " << m << endl;
} // end main
```
Enter a string: JAMES BOND IS 007
Encrypted string is: WNZR`-O\[Q-V`-==D
```
#include
#include
using namespace std;

int main()
{
string m; // to store input
int key = 13; // Our key for decryption

cout << "Enter encrypted string: ";
getline( cin, m );

// define an iterator
string::iterator mi = m.begin();

// loop through the string
while ( mi != m.end() )
{
*mi -= key;
mi++;
} // end while

cout << "\nDecrypted string is: " << m << endl;
} // end main
```
Enter encrypted string: WNZR`-O\[Q-V`-==D
Decrypted string is: JAMES BOND IS 007

Computer Science & Information Technology

You might also like to view...

Clicking a cell and then right-clicking in the formula bar displays the insertion point in the formula bar

Indicate whether the statement is true or false

Computer Science & Information Technology

The results of PricePerRoom: [ListPrice]/([Beds]+[Baths]+3 ) will appear in a column with the heading ________

A) PricePerRoom B) Beds C) ListPrice D) Baths

Computer Science & Information Technology

A ____ report alerts you to areas that you may need to fix, such as unused or conflicting style rules.

A. CSS B. Style Errors C. Conflict D. Site

Computer Science & Information Technology

What remote access tunneling protocol encapsulates data within HTTP packets for transit across the Internet?

A. SSTP B. L2TP C. PPTP D. IPSec

Computer Science & Information Technology