Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <stdlib.h>
- #include <windows.h>
- #include <map>
- #include <cmath>
- #include <string>
- #include <conio.h>
- #include <sstream>
- using namespace std;
- string text = "u fat lol";
- string encryptedText;
- string text2;
- int spaces = 0;
- int offset;
- int multipliers = 2;
- char getOption()
- {
- system("cls");
- char option;
- cout << "Enter 'e' to encrypt text..." << setw(42) << "Enter 'd' to decrypt text..." << setw(35) << "Enter 'x' to exit..." << endl;
- cin >> option;
- return option;
- }
- string encrypt(string &text, int offset)
- {
- NewOrSetLine:char NewOrSet;
- cout << "\n\nDo you want to use new text or text set in code?\nn : New text";
- if (text.length() != 0){
- cout << "\nc : Text in code (text: '"<<text<<"')\n";}else{
- cout << "\n - There is no text set in code." << endl;}
- cin >> NewOrSet;
- if (NewOrSet == 'n' || NewOrSet == 'N') {
- cout << "\nEnter text to encrypt without spaces: " << endl; cin >> text; }
- else if (NewOrSet == 'c' || NewOrSet == 'C'){
- text = text;}else{goto NewOrSetLine;}
- if (offset == 0){
- cout << "\nEnter offset number(int)( some offsets might not work! ): " << endl; cin >> offset;
- }
- string result = "";
- for (int i = 0; i<text.length(); i++)
- {
- if (isupper(text[i])){
- for (int j = 0; j<2; j++){
- result += char(int(text[i] + offset + j));
- result += char(int(text[i] = 72));
- result += char(int(text[i] + (offset + j) + multipliers));
- result += char(int(text[i] = 81));
- }
- }
- else if (int(text[i] == 32)){
- result += char(int(51));
- spaces++;
- }
- else {
- for (int k = 0; k<2; k++){
- result += char(int(text[i] + offset + k));
- result += char(int(text[i] = 88));
- result += char(int(text[i] + (offset + k) + multipliers));
- result += char(int(text[i] = 34));
- }
- }
- }
- cout << endl;
- cout << "Number of spaces in text: " << spaces << endl;
- text2 = text;
- return result;
- }
- string decrypt(string encryptedText, int offset)
- {
- string result = "";
- cout << "Enter Encrypted Text: ";
- cin >> encryptedText;
- cout << endl;
- cout << "Enter offset: ";
- cin >> offset;
- int n = 0;
- cout << endl;
- cout << "encry text: " << encryptedText << endl;
- for (int i=0; i<50000; i++){
- if (encryptedText.length() > n+1) {
- if (int(encryptedText[0 + n] == 51)){
- result += char(int(32));
- n += 1; }
- if (encryptedText.length() > n+1) {
- result += char(int(encryptedText[0 + n] - offset));
- n += 8; }
- }else{
- break;
- }
- }
- return result;
- }
- int main()
- {
- getoptions:
- char TheOption = getOption();
- if (TheOption == 'e' || TheOption == 'E'){
- cout << "Encrypted Text: " << encrypt(text, offset);
- cout << endl;
- cout << "Press any key to continue..." << endl;
- getch();
- goto getoptions;
- }
- else if (TheOption == 'd' || TheOption == 'D'){
- cout << "Decrypted Text: " << decrypt(encryptedText, offset);
- cout << endl;
- cout << "Press any key to continue..." << endl;
- getch();
- goto getoptions;
- }
- else if (TheOption == 'x' || TheOption == 'X'){
- return 0;
- }
- else {
- goto getoptions;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement