Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a project that was suppose to be requesting a user to enter a string that would encrypt, decrypt, and do a rot13 encryption.

I have a project that was suppose to be requesting a user to enter a string that would encrypt, decrypt, and do a rot13 encryption. I had help and followed off other post, and I believe it is pulling the functions from a file. I'm honestly not sure what it's doing, and how to it to take a user implemented string. Spoiler(Click to Hide) #include using namespace std;

int length(const char input[]); void encrypt(const char original[], char encrypted[]); void decrypt(const char original[], char encrypted[]); void rot13(char input[]);

int main(int argc, char * argv[]){ if (argc <= 1){ cout << "Usage: " << argv[0] << " " << endl; return 1; } char * original = argv[1]; char encrypted[100];

encrypt(original, encrypted); cout << "Original: " << original<< endl; cout << "Encrypted: " << encrypted << endl; rot13(encrypted); cout << "Final: " << encrypted << endl;

char decrypted[100]; rot13(encrypted); decrypt(encrypted, decrypted); cout << "Decryption Original: " << encrypted << endl; cout << "Decrypted: " << decrypted << endl; return 0; }

int length(const char input[]){ int i = 0; while (true){ if (input[i] == '\x00') break; i += 1; } return i; }

void encrypt(const char original[], char encrypted[]){ int encrypted_char_len = 0; int original_char_len = length(original); if (!original_char_len) return;

int i = 0; while (original_char_len > encrypted_char_len){ encrypted[encrypted_char_len] = original[original_char_len-i-1]; encrypted_char_len++; if (encrypted_char_len + 1 <= original_char_len){ encrypted[encrypted_char_len] = original[i]; encrypted_char_len++; i++; } else{ break; } } encrypted[encrypted_char_len] = '\x00'; }

void decrypt(const char original[], char encrypted[]){ int decrypted_char_len = 0; int original_char_len = length(original); if (!original_char_len) return;

int i = 0; int j = 0; while(original_char_len > decrypted_char_len){ encrypted[original_char_len-i-1] = original[decrypted_char_len]; decrypted_char_len++; i++; if (decrypted_char_len + 1 <= original_char_len){ encrypted[j] = original[decrypted_char_len]; decrypted_char_len++; j++; } else { break; } } }

void rot13(char string[]){ for (int i = 0; string[i]; i++){ if ((string[i] >= 'a' && string[i] <= 'm') || (string[i] >= 'A' && string[i] <= 'M')) { string[i] += 13; continue; } else if((string[i] >= 'n' && string[i] <= 'z') || (string[i] >= 'M' && string[i] <= 'Z')){ string[i] -= 13; continue; } } }

I'm needing help with getting the code to prompt a user to enter a string, and then run the string through the functions.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Students also viewed these Databases questions

Question

What does Regulation S-X cover? What is included in Regulation S-K?

Answered: 1 week ago

Question

=+ 46-2 Discuss how an infant's brain begins processing memories.

Answered: 1 week ago

Question

What are the determinants of cash cycle ? Explain

Answered: 1 week ago