help with an encryption/decryption program.

i keep getting the errors

.\encrypt.cpp(5): error C2447: '{': missing function header (old-style formal list?)
.\encrypt.cpp(118): error C2447: '{': missing function header (old-style formal list?)
.\encrypt.cpp(237): error C2065: 'results': undeclared identifier
.\encrypt.cpp(245): error C2065: 'results': undeclared identifier
.\encrypt.cpp(250): error C2065: 'results': undeclared identifier
.\encrypt.cpp(252): error C2065: 'results': undeclared identifier

this is my code
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
  #include "encrypt.h"
#include <iostream>

string encrypt( string input );
{
  string results = "";
  for ( int i=0; i<input.length(); i++ )
  {
    if ( input[i] == 'a' )
    {
      results = results + "z";
    }
    else if ( input[i] == 'b' )
    {
        results = results + "y";
    }
    else if ( input[i] == 'c' )
    {
        results = results + "x";
    }
    else if ( input[i] == 'd' )
    {
        results = results + "w";
    }
    else if ( input[i] == 'e' )
    {
        results = results + "v";
    }
    else if ( input[i] == 'f' )
    {
        results = results + "u";
    }
    else if ( input[i] == 'g' )
    {
        results = results + "t";
    }
    else if ( input[i] == 'h' )
    {
        results = results + "s";
    }
    else if ( input[i] == 'i' )
    {
        results = results + "r";
    }
    else if ( input[i] == 'j' )
    {
        results = results + "q";
    }
    else if ( input[i] == 'k' )
    {
        results = results + "p";
    }
    else if ( input[i] == 'l' )
    {
        results = results + "o";
    }
    else if ( input[i] == 'm' )
    {
        results = results + "n";
    }
    else if ( input[i] == 'n' )
    {
        results = results + "m";
    }
    else if ( input[i] == 'o' )
    {
        results = results + "l";
    }
    else if ( input[i] == 'p' )
    {
        results = results + "k";
    }
    else if ( input[i] == 'q' )
    {
        results = results + "j";
    }
    else if ( input[i] == 'r' )
    {
        results = results + "i";
    }
    else if ( input[i] == 's' )
    {
        results = results + "h";
    }
    else if ( input[i] == 't' )
    {
        results = results + "g";
    }
    else if ( input[i] == 'u' )
    {
        results = results + "f";
    }
    else if ( input[i] == 'v' )
    {
        results = results + "e";
    }
    else if ( input[i] == 'w' )
    {
        results = results + "d";
    }
    else if ( input[i] == 'x' )
    {
        results = results + "c";
    }
    else if ( input[i] == 'y' )
    {
        results = results + "b";
    }
    else if ( input[i] == 'z' )
    {
        results = results + "a";
    }
    return (results);
  }
}

string decrypt( string input );
{
  string results = "";
  for ( int i=0; i<input.length(); i++ )
  {
    if ( input[i] == 'a' )
    {
      results = results + "z";
    }
    else if ( input[i] == 'b' )
    {
        results = results + "y";
    }
    else if ( input[i] == 'c' )
    {
        results = results + "x";
    }
    else if ( input[i] == 'd' )
    {
        results = results + "w";
    }
    else if ( input[i] == 'e' )
    {
        results = results + "v";
    }
    else if ( input[i] == 'f' )
    {
        results = results + "u";
    }
    else if ( input[i] == 'g' )
    {
        results = results + "t";
    }
    else if ( input[i] == 'h' )
    {
        results = results + "s";
    }
    else if ( input[i] == 'i' )
    {
        results = results + "r";
    }
    else if ( input[i] == 'j' )
    {
        results = results + "q";
    }
    else if ( input[i] == 'k' )
    {
        results = results + "p";
    }
    else if ( input[i] == 'l' )
    {
        results = results + "o";
    }
    else if ( input[i] == 'm' )
    {
        results = results + "n";
    }
    else if ( input[i] == 'n' )
    {
        results = results + "m";
    }
    else if ( input[i] == 'o' )
    {
        results = results + "l";
    }
    else if ( input[i] == 'p' )
    {
        results = results + "k";
    }
    else if ( input[i] == 'q' )
    {
        results = results + "j";
    }
    else if ( input[i] == 'r' )
    {
        results = results + "i";
    }
    else if ( input[i] == 's' )
    {
        results = results + "h";
    }
    else if ( input[i] == 't' )
    {
        results = results + "g";
    }
    else if ( input[i] == 'u' )
    {
        results = results + "f";
    }
    else if ( input[i] == 'v' )
    {
        results = results + "e";
    }
    else if ( input[i] == 'w' )
    {
        results = results + "d";
    }
    else if ( input[i] == 'x' )
    {
        results = results + "c";
    }
    else if ( input[i] == 'y' )
    {
        results = results + "b";
    }
    else if ( input[i] == 'z' )
    {
        results = results + "a";
    }
    return (results);
  }
}

void encryptDecrypt( string input, string output )
{
  ifstream in( input );
  ofstream out( output );

  string command;

  in >> results;
  in >> command;

  while ( !in.fail() )
  {
    if ( command == "encrypt" )
    {
      encrypt( input );
      out << "encrypted: " << results << endl;
    }
    else if ( command == "decrypt")
    {
      decrypt( input );
      out << "decrypted: " << results << endl;
    }
    in >> results;
    in >> command;
  }
}

and this is the header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

using std::string;
using std::ifstream;
using std::ofstream;
using std::endl;

void encryptDecrypt( string inputfile, string outputfile );
string encrypt( string input );
string decrypt( string input );

Could someone please advise on how to correct these errors.
take the ; off of the function body def. It does not go there.

for example
string decrypt( string input ); <-------- this is your problem, remove it.
Last edited on
I have corrected the errors but I am not getting any output.
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#include "encrypt.h"

string encrypt( string input )
{
  string results = "";
  for ( int i=0; i<input.length(); i++ )
  {
    if ( input[i] == 'a' )
    {
      results = results + "z";
    }
    else if ( input[i] == 'b' )
    {
        results = results + "y";
    }
    else if ( input[i] == 'c' )
    {
        results = results + "x";
    }
    else if ( input[i] == 'd' )
    {
        results = results + "w";
    }
    else if ( input[i] == 'e' )
    {
        results = results + "v";
    }
    else if ( input[i] == 'f' )
    {
        results = results + "u";
    }
    else if ( input[i] == 'g' )
    {
        results = results + "t";
    }
    else if ( input[i] == 'h' )
    {
        results = results + "s";
    }
    else if ( input[i] == 'i' )
    {
        results = results + "r";
    }
    else if ( input[i] == 'j' )
    {
        results = results + "q";
    }
    else if ( input[i] == 'k' )
    {
        results = results + "p";
    }
    else if ( input[i] == 'l' )
    {
        results = results + "o";
    }
    else if ( input[i] == 'm' )
    {
        results = results + "n";
    }
    else if ( input[i] == 'n' )
    {
        results = results + "m";
    }
    else if ( input[i] == 'o' )
    {
        results = results + "l";
    }
    else if ( input[i] == 'p' )
    {
        results = results + "k";
    }
    else if ( input[i] == 'q' )
    {
        results = results + "j";
    }
    else if ( input[i] == 'r' )
    {
        results = results + "i";
    }
    else if ( input[i] == 's' )
    {
        results = results + "h";
    }
    else if ( input[i] == 't' )
    {
        results = results + "g";
    }
    else if ( input[i] == 'u' )
    {
        results = results + "f";
    }
    else if ( input[i] == 'v' )
    {
        results = results + "e";
    }
    else if ( input[i] == 'w' )
    {
        results = results + "d";
    }
    else if ( input[i] == 'x' )
    {
        results = results + "c";
    }
    else if ( input[i] == 'y' )
    {
        results = results + "b";
    }
    else if ( input[i] == 'z' )
    {
        results = results + "a";
    }
    return (results);
  }
}

string decrypt( string input )
{
  string results = "";
  for ( int i=0; i<input.length(); i++ )
  {
    if ( input[i] == 'a' )
    {
      results = results + "z";
    }
    else if ( input[i] == 'b' )
    {
        results = results + "y";
    }
    else if ( input[i] == 'c' )
    {
        results = results + "x";
    }
    else if ( input[i] == 'd' )
    {
        results = results + "w";
    }
    else if ( input[i] == 'e' )
    {
        results = results + "v";
    }
    else if ( input[i] == 'f' )
    {
        results = results + "u";
    }
    else if ( input[i] == 'g' )
    {
        results = results + "t";
    }
    else if ( input[i] == 'h' )
    {
        results = results + "s";
    }
    else if ( input[i] == 'i' )
    {
        results = results + "r";
    }
    else if ( input[i] == 'j' )
    {
        results = results + "q";
    }
    else if ( input[i] == 'k' )
    {
        results = results + "p";
    }
    else if ( input[i] == 'l' )
    {
        results = results + "o";
    }
    else if ( input[i] == 'm' )
    {
        results = results + "n";
    }
    else if ( input[i] == 'n' )
    {
        results = results + "m";
    }
    else if ( input[i] == 'o' )
    {
        results = results + "l";
    }
    else if ( input[i] == 'p' )
    {
        results = results + "k";
    }
    else if ( input[i] == 'q' )
    {
        results = results + "j";
    }
    else if ( input[i] == 'r' )
    {
        results = results + "i";
    }
    else if ( input[i] == 's' )
    {
        results = results + "h";
    }
    else if ( input[i] == 't' )
    {
        results = results + "g";
    }
    else if ( input[i] == 'u' )
    {
        results = results + "f";
    }
    else if ( input[i] == 'v' )
    {
        results = results + "e";
    }
    else if ( input[i] == 'w' )
    {
        results = results + "d";
    }
    else if ( input[i] == 'x' )
    {
        results = results + "c";
    }
    else if ( input[i] == 'y' )
    {
        results = results + "b";
    }
    else if ( input[i] == 'z' )
    {
        results = results + "a";
    }
    return (results);
  }
}

void encryptDecrypt( string input, string output )
{
  ifstream in( input );
  ofstream out( output );

  string results;
  string command;

  in >> results;
  in >> command;
  while ( !in.fail() )
  {
    if ( command == "encrypt" )
    {
      string results = encrypt( input );
      out << "encrypted: " << results << endl;
    }
    else if ( command == "decrypt")
    {
      string results = decrypt( input );
      out << "decrypted: " << results << endl;
    }
  in >> results;
  in >> command;
  }
}


This is my new code.

Topic archived. No new replies allowed.