Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can someone help me write a program that decrypts data using +26 ascii code and turn it into a file. and also let user only
can someone help me write a program that decrypts data using +26 ascii code and turn it into a file. and also let user only access when the key "5" is inserted --
encrypted file using -26 ascii code:
#include#include #include using namespace std; char encrypt(char c, int key) { if ('a' <= c && c <= 'z'){ if(c + key > 'z') { return c + (key - 26); } else { return c + key; } } if ('A' <= c && c <= 'Z'){ if(c + key > 'Z') { return c + (key - 26); } else { return c + key; } } return c; } int main() { string fileName; cout << "enter fileName: "; cin >> fileName; string out = "encrypted.txt"; ifstream inFile(fileName.c_str()); ofstream outFile(out.c_str()); int key; cout << "Enter key as a number from 0 to 25: "; cin >> key; char c; // read character by character from file while (inFile.get(c)) { // encode the character and output it to file c = encrypt(c, key); outFile << c; } cout << "Program completed successfully." << endl; inFile.close(); outFile.close(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started