Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
87 views

Simple Text Encryptor Decryptor

This C++ program allows a user to encrypt or decrypt text using a simple cipher. The program prompts the user to choose encryption or decryption. It then gets the text and encryption key from the user. For encryption, it shifts each character by the key value. For decryption, it shifts each character back by the key value. The encrypted or decrypted text can optionally be saved to a file. The program clears the console screen between runs using Windows API functions.

Uploaded by

Harsh Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

Simple Text Encryptor Decryptor

This C++ program allows a user to encrypt or decrypt text using a simple cipher. The program prompts the user to choose encryption or decryption. It then gets the text and encryption key from the user. For encryption, it shifts each character by the key value. For decryption, it shifts each character back by the key value. The encrypted or decrypted text can optionally be saved to a file. The program clears the console screen between runs using Windows API functions.

Uploaded by

Harsh Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

//Programmer: Harsh Gupta //Program: Text Encryptor/Decryptor //Email: Harshgupta.11dec@gmail.com #include <iostream> #include <fstream> #include <windows.

h> using namespace std; void encryptor(); void decryptor(); void clear_screen(); int main(void) { char back = 'y'; while(back == 'y' || back == 'Y'){ int choice; clear_screen(); cout << "Welcome to Harsh Text Encryptor/Decryptor\n" << "1) Text Encryptor\n" << "2) Text Decryptor\n" << "Type the number of what you want to use: "; cin >> choice; switch(choice) { case 1: encryptor(); break; case 2: decryptor(); break; default: cout << "\nSorry not in choice."; break; } cout << "\nWant to re-run the program(y/n)? "; cin >> back; } } void encryptor()

{ ofstream a("encrypted.txt"); int size, key; char save; char ky[4]; cout << "\nEnter the size of your text: "; cin >> size; char text[size]; cout << "\nEnter the text for encryption: "; cin >> text; cout << "\nEnter your key: "; // Key decides encrypted text cin >> ky; key = ky[0] + ky[1] + ky[2] + ky[3]; while(key>10) { key = key - 10; } cout << "\nThe encrypted text is: "; for (int i = 0;i<size;i++){ // For displaying encrypted text text[i]+=key; cout << text[i]; } cout << "\nDo you want to save the encrypted text & key to your pc(y/n)? "; cin >> save; if (save == 'y' || save == 'Y'){ a << "Encrypted Text: "; for (int i = 0;i<size;i++){ a << text[i]; } a << "\nKey: " << ky[0] << ky[1] << ky[2] << ky[3]; } } void decryptor() { ofstream a("deccrypted.txt"); int size, key; char save; char ky[4]; cout << "\nEnter the size of your text: "; cin >> size; char text[size]; cout << "\nEnter the text for decryption: ";

cin >> text; cout << "\nEnter your key: "; cin >> ky; key = ky[0] + ky[1] + ky[2] + ky[3]; while(key>10) { key = key - 10; }

// Key decides decrypted text

cout << "\nThe decrypted text is: "; for (int i = 0;i<size;i++){ // For displaying decrypted text text[i]-=key; cout << text[i]; } cout << "\nDo you want to save the decrypted text file to your pc(y/n)? "; cin >> save; if (save == 'y' || save == 'Y'){ a << "Decrypted Text: "; for (int i = 0;i<size;i++){ a << text[i]; }} } void clear_screen() { HANDLE output_handle = GetStdHandle(STD_OUTPUT_HANDLE); DWORD bytes_write, size; COORD coord = {0, 0}; CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(output_handle, &csbi); size = csbi.dwSize.X * csbi.dwSize.Y; FillConsoleOutputCharacter(output_handle, ' ', size, coord, &bytes_write); SetConsoleCursorPosition(output_handle, coord); }

You might also like