ceasar Cipher with a txt C++

so i need to encrypt a txt document using ceasar encryption. however i don't know how to open a txt and shift the keys into a new txt. the program has to ask the user for the number it should shift.

what do you guys recommend using arrays, if else. i also need to make a menu so i am using switch.

For the menu, use a switch statement, than inside of the switch, use a function to perform whatever it is the user wants to do (encrypt, decrypt, etc...)

Inorder to open a text file and shift the values, you must first read in the values and than manipulate them as needed.

You could use stringstream, string, char, vector, or any character reading data type you really want. I would suggest using a string and getline(in_file, my_string) to get each line independently and than just read through the line until it is full encrypted and write it to the new file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
this is what i have so far, now i am trying to figure out how can the user cin an integer so i can shift the keys by the "i"

#include<iostream>
#include<fstream>

using namespace std;

void showMenu();
void showFile();
void copyFile();
void encryptCeasar ();

int main() {
    showMenu();
  
  system("pause");  
return 0;
}

void showMenu() {
     
  int option;
     
     
     cout<< "Choose an option from this menu"<<endl;
     cout <<"[1] Encrypt using Caesar cipher"<<endl;
     cout<< "[2] Encrypt using RSA"<<endl;
     cout<< "[3] Decrypt using Caesar cipher"<<endl;
     cout<< "[4] Decrypt using RSA"<<endl;
     cout<< "[5] Quit"<<endl;
     
     cin>>option;
  switch (option) {
         case 1:
              showFile();
              
              copyFile();
              break;
  }
  
}




void showFile(){
     
     
     ifstream inFile;
     char ch;
     
     inFile.open("Caesar_plain.txt");
     inFile.unsetf(ios_base::skipws);
     
     while (inFile >> ch){
      cout << ch;
      }
     cout<<endl;
     inFile.close();
     
}

void copyFile() {
     
     ifstream orginFile;
     ofstream outFile;
     char ch;
     
     orginFile.open("Caesar_plain.txt");
     orginFile.unsetf(ios_base::skipws);
     
     
     outFile.open("Caesar_cipher.txt");
     outFile.unsetf(ios_base::skipws);
     
     while (orginFile >> ch){
     outFile << ch;
     }
     orginFile.close();
     outFile.close();
}     
void encryptCeasar (){
     
     int i=0;
     
     
     
     
     
     
     
     
     





Last edited on
can some please help about how to include the asII table. i think i need to use an array a set the parameters to the letters 65-90. but how to use it?
closed account (3qX21hU5)
Please edit your previous post so that it uses codetags (Highlight all your code and press the <> off to the right) this will make the code much easier to read and then more people will be willing to look it over and help with suggestions.
Topic archived. No new replies allowed.