-
Notifications
You must be signed in to change notification settings - Fork 0
/
nsaEncoder1-algorithm.txt
394 lines (375 loc) · 11.1 KB
/
nsaEncoder1-algorithm.txt
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
@copyrighted 1999 Valerie Colber
Full Name and Student ID Number: Kevin Jaewoo Lee
Course and section: COMSC-110-1572
1. Objective (1 sentence brief description of what this will do):
The program will Encode the entered text so that each character is converted to the next character in the ASCII code.
2. Requirements (any and all requirements organized by input, processing, output, data):
INPUT (any data items to be input):
-r
-fN
-keepGoing
PROCESSING (list of significant parts of the objective that will become the list of code blocks in program):
1. data definitions
2. user introduction
3. read input file
4. encode the sentence
5. output result
OUTPUT (list of anything output: introduction, data items, labels, prompts) :
-user introduction: introduction of objective, author, user instructions/rules
-prompt "Please enter an input filename [i.e. : x.txt] : "
-label : " File was empty . "
-instruction : Then "encode" the entered text so that each character is converted to the next character in the ASCII code. That is, convert 'A' to 'B', '4' to '5', '*' to '+', etc. So the word "Hello" will appear as "Ifmmp" in encoded form. Remember a line of text contains multiple characters, and each character has an ASCII value, and by adding 1 to that ASCII value results in the next character in the ASCII table.
-prompt : "Enter a line of text:";
-label : " there are no line "
-label : " finish encoding the line!"
-prompt : "Do you want to keep going? [Y/N] : "
DATA (list of all data items: definition, data type, formatting, or any other specifications):
-string objective = "The program will be a template for C++ programs and to test code.\n"; //program objective
-string instructions = ""Encode the entered text so that each character is converted to the next character in the ASCII code. That is, convert 'A' to 'B', '4' to '5', '*' to '+', etc. So the word Hello will appear as Ifmmp in encoded form. Remember a line of text contains multiple characters, and each character has an ASCII value, and by adding 1 to that ASCII value results in the next character in the ASCII table.\n\n"; //user instructions
-int i //index loop
-string s // user selected sentence
-string fileName //file name
-ifstream fin //fin
-int count = 1 // determine whether file is empty
-int r //user wanted line
-ofstream fout //fout
-string first
-string second
-string third
-string forth
-string offsett = "offset.txt"; //output file
-int r
-int offset[SIZE] ={-5, 8, 12, 6, 1}
-index = (integer) // for index
-keepGoing = (character)
3. Algorithm instructions (recipe)
***data
10 set objective
20 set instructions
30 set i=0
40 set s
50 set fileName
51 set offsett = "offset.txt" //output file
52 set r
53 set offset[SIZE]
54 set index // for index
55 set keepGoing
60 set fin
65 set count=1
66 set r
67 set first
68 set second
69 set third
695 set forth
696 set secret = "secret.txt"
***user introduction
70 output introduction: objective, author, instructions/rules
***read input file
80 fileName = getFileName
*** subprogram get user specified filename
801 set getFileName as string
802 set fN
803 output prompt : "Please enter an input filename [i.e. : x.txt] : "
804 input fN
805 if fN's length is not bigger than 5 then skip to 1704
806 return value fN to getFileName
90 file input
*** subprogram for encode(string a, int* offset)
1000 if i is larger than and equal to a length then skip to instruction 1010
1001 index = i % SIZE
1002 output offset[index]
1003 add 1 to order of a letter
1005 i = i + 1
1006 output "Do you want to keep going? [Y/N] : "
1007 input keepGoing
1008 if keepGoing is 'n' or 'N' then skip to instruction 1010
1009 skip to instruction 1000
1010 return value a to encode function
***main function
110 output prompt "Enter a line of text:"
110 input r
120 if r is 1 then skip to instruction xxx
130 if r is 2 then skip to instruction xxx
140 if r is 3 then skip to instruction 190
150 forth = encode function
160 if forth is empty then count = 0
170 output forth
180 skip to instruction yyy
190 if third is empty then count = 0
330 if i is less than forth length then skip to instruction 300
3301 if r is larger than 4 then output "there are no text" and then add 1 to count and skip to instruction 400
350 if count is 0 then output " File was empty . " and skip to instruction 440
360 if r is equal to 1 then output first and skip to instruction 400
370 if r is equal to 2 then output second and skip to instruction 400
380 if r is equal to 3 then output third and skip to instruction 400
390 if r is equal to 4 then output forth and skip to instruction 400
400 file output first
410 file output second
420 file output third
430 file output forth
440 close output file
450 close input file
999 END
4. Test cases (list purpose of each test case, any input values, and expected results)
Test case #1:
purpose : general example
input : Hello World , B , A 1
expected result :
Please enter an input filename [i.e. : x.txt] : nsaEncode.txt
Enter a line of text:1
Ifmmp!Xpsme
***data
10 set objective
20 set instructions
30 set i
40 set s
50 set fileName
60 set fin
65 set count
66 set r
67 set first
68 set second
69 set third
695 set forth
696 set secret = "secret.txt"
***user introduction
70 output introduction: objective, author, instructions/rules
***read input file
80 fileName = getFileName
*** subprogram get user specified filename
801 set getFileName as string
802 set fN
803 output prompt : "Please enter an input filename [i.e. : x.txt] : "
804 input fN = nsaEncode.txt
805 false
806 return value fN to getFileName
90 file input s = Hello World
100 set i = 0
110 add 1 to order of i letter = I
120 add 1 to i =1
130 true then skip to instruction 100
100 set i = 1
110 add 1 to order of i letter = f
120 add 1 to i =2
130 true then skip to instruction 100
100 set i = 2
110 add 1 to order of i letter = m
120 add 1 to i =3
130 true then skip to instruction 100
100 set i = 3
110 add 1 to order of i letter = m
120 add 1 to i =4
130 true then skip to instruction 100
100 set i = 4
110 add 1 to order of i letter = p
120 add 1 to i =5
130 true then skip to instruction 100
100 set i = 5
110 add 1 to order of i letter = !
120 add 1 to i =6
130 true then skip to instruction 100
100 set i = 6
110 add 1 to order of i letter = X
120 add 1 to i =7
130 true then skip to instruction 100
100 set i = 7
110 add 1 to order of i letter = p
120 add 1 to i =8
130 true then skip to instruction 100
100 set i = 8
110 add 1 to order of i letter = s
120 add 1 to i =9
130 true then skip to instruction 100
100 set i = 9
110 add 1 to order of i letter = m
120 add 1 to i =10
130 true then skip to instruction 100
100 set i = 10
110 add 1 to order of i letter = e
120 add 1 to i =11
130 false
150 file input =second
160 set i = 0
170 add 1 to order of i letter =C
180 add 1 to i =1
195 add 1 to count =1
200 false
220 file input =third = A
230 set i = 0
240 add 1 to order of i letter =B
250 add 1 to i= 1
265 add 1 to count = 1
270 false
290 file input =fortht
330 false
3301 false
350 false
360 true output first and skip to instruction 400
400 file output first
410 file output second
420 file output third
430 file output forth
440 close output file
450 close input file
999 END
Test case #2:
purpose : when file has no data
input :
Please enter an input filename [i.e. : x.txt] : nsaEncode.txt
Enter a line of text:2
File was empty .
***data
10 set objective
20 set instructions
30 set i
40 set s
50 set fileName
60 set fin
65 set count
66 set r
67 set first
68 set second
69 set third
695 set forth
696 set secret = "secret.txt"
***user introduction
70 output introduction: objective, author, instructions/rules
***read input file
80 fileName = getFileName
*** subprogram get user specified filename
801 set getFileName as string
802 set fN
803 output prompt : "Please enter an input filename [i.e. : x.txt] : "
804 input fN = nsaEncode.txt
805 false
806 return value fN to getFileName
90 file input =
100 set i = 0
110 add 1 to order of i letter
120 add 1 to i
125 add 1 to count
130 false
150 file input =
160 set i = 0
170 add 1 to order of i letter
180 add 1 to i
195 add 1 to count
200 false
220 file input =
230 set i = 0
240 add 1 to order of i letter
250 add 1 to i
265 add 1 to count
270 false
290 file input =
300 set i = 0
310 add 1 to order of i letter
320 add 1 to i
325 add 1 to count
330 false
3301 false
350 true output " File was empty . " and skip to instruction 440
400 file output first
410 file output second
420 file output third
430 file output forth
440 close output file
450 close input file
999 END
Test case #3 :
purpose : when they put empty line
input : Hello World , B , A 7
expected result
Please enter an input filename [i.e. : x.txt] : nsaEncode.txt
Enter a line of text:8
there are no line
10 set objective
20 set instructions
30 set i
40 set s
50 set fileName
60 set fin
65 set count
66 set r
67 set first
68 set second
69 set third
695 set forth
696 set secret = "secret.txt"
***user introduction
70 output introduction: objective, author, instructions/rules
***read input file
80 fileName = getFileName
*** subprogram get user specified filename
801 set getFileName as string
802 set fN
803 output prompt : "Please enter an input filename [i.e. : x.txt] : "
804 input fN = nsaEncode.txt
805 false
806 return value fN to getFileName
90 file input s = Hello World
100 set i = 0
110 add 1 to order of i letter = I
120 add 1 to i =1
130 true then skip to instruction 100
100 set i = 1
110 add 1 to order of i letter = f
120 add 1 to i =2
130 true then skip to instruction 100
100 set i = 2
110 add 1 to order of i letter = m
120 add 1 to i =3
130 true then skip to instruction 100
100 set i = 3
110 add 1 to order of i letter = m
120 add 1 to i =4
130 true then skip to instruction 100
100 set i = 4
110 add 1 to order of i letter = p
120 add 1 to i =5
130 true then skip to instruction 100
100 set i = 5
110 add 1 to order of i letter = !
120 add 1 to i =6
130 true then skip to instruction 100
100 set i = 6
110 add 1 to order of i letter = X
120 add 1 to i =7
130 true then skip to instruction 100
100 set i = 7
110 add 1 to order of i letter = p
120 add 1 to i =8
130 true then skip to instruction 100
100 set i = 8
110 add 1 to order of i letter = s
120 add 1 to i =9
130 true then skip to instruction 100
100 set i = 9
110 add 1 to order of i letter = m
120 add 1 to i =10
130 true then skip to instruction 100
100 set i = 10
110 add 1 to order of i letter = e
120 add 1 to i =11
130 false
150 file input =second
160 set i = 0
170 add 1 to order of i letter =C
180 add 1 to i =1
195 add 1 to count =1
200 false
220 file input =third = A
230 set i = 0
240 add 1 to order of i letter =B
250 add 1 to i= 1
265 add 1 to count = 1
270 false
290 file input =fortht
330 false
3301 true then output "there are no text" and then add 1 to count and skip to instruction 400
400 file output first
410 file output second
420 file output third
430 file output forth
440 close output file
450 close input file