· 7 years ago · Mar 13, 2018, 03:00 PM
1#include <iostream>
2#include <iomanip>
3#include <string>
4
5using namespace std;
6
7int main()
8{
9 cout << "Good Morning User \n\n";
10 cout << "What do you like to do today ?\n";
11 cout << "If you want to cipher a message press 1 or if you want to decipher a message press 2\n\nEnter your choice : ";
12 int choice;
13 int cipherNum;
14 cin >> choice;
15 if (choice == 1)
16 {
17
18 cout << "\nWhat is the type of the cipher you want ?\n";
19 cout << "\t1. Affine Cipher\n\t2. Caesar Cipher\n\t3. Atbash Cipher\n\t4. ROT13 Cipher\n\t5.Baconian Cipher\n\t6. Simple Substitution Cipher\n\t7. Polybius Square Cipher\n\t8. Morse Code\n\t9. XOR Cipher\n\t10. Rail-fence Cipher\n ";
20 cin >> cipherNum;
21 cout << endl;
22
23 if (cipherNum == 1)
24 {
25 float x ,old_or_new;
26 int m,y ,a ,b,c;
27 string word;
28 cout<< "enter the keys.3 int a, b and c and should (a*c)%26=1 is true\n";
29 cout<<"a =>";
30 cin>>a;
31 cout<<"\nb=>";
32 cin>>b;
33 cout<<"\nc=>";
34 cin>>c;
35 if((a*c)%26!=1){
36 while(true)
37 {
38 cout<< "invalid\nenter the keys.3 int a, b and c and should (a*c)%26=1 is true\n";
39 cout<<"a =>";
40 cin>>a;
41 cout<<"\nb=>";
42 cin>>b;
43 cout<<"\nc=>";
44 cin>>c;
45 if((a*c)%26==1){break;}
46 }
47 }
48 cout<<"enter your letter\n=>";
49 cin.ignore();
50 getline(cin,word);
51 for (int i=0 ;i<word.size();i++)
52 {
53 word[i] = char(tolower(word[i]));
54 word[i]+'0';
55 if (word[i]>122|| 97>word[i]){continue;}
56 m=word[i]-97;
57 m=(a*m+b)%26;
58 word[i]=97+m;
59 }
60 cout<<"=>"<<word;
61 }
62 if (cipherNum == 2)
63 {
64 int shifts, y;
65 string text, ciphertext;
66 char x[27];
67 x[0] = 'A', x[1] = 'B', x[2] = 'C', x[3] = 'D', x[4] = 'E', x[5] = 'F', x[6] = 'G', x[7] = 'H', x[8] = 'I', x[9] = 'J', x[10] = 'K', x[11] = 'L';
68 x[12] = 'M', x[13] = 'N', x[14] = 'O', x[15] = 'P', x[16] = 'Q', x[17] = 'R', x[18] = 'S', x[19] = 'T', x[20] = 'U', x[21] = 'V', x[22] = 'W', x[23] = 'X', x[24] = 'Y', x[25] = 'Z';
69 cout << "enter the plain text : ";
70 cin.ignore();
71 getline(cin, text);
72 cout << endl;
73 cout << "enter the number of shifts : ";
74 cin >> shifts;
75 cout << endl;
76 for (int i = 0; i < text.size(); i++)
77 {
78 if (text[i] == ' ') {
79 cout << " ";
80 continue;
81 }
82 text[i] = char(toupper(text[i]));
83 for (int j = 0; j < 26; j++)
84 {
85 if (text[i] == x[j] && j + shifts <= 25)
86 {
87 ciphertext += x[j + shifts];
88 }
89 else if (text[i] == x[j] && j + shifts > 25)
90 {
91 y = (shifts - (26 - j));
92 ciphertext += x[y];
93 }
94 }
95
96 }
97 cout << "the cipher text : " << ciphertext;
98 }
99
100 if (cipherNum == 3)
101 {
102 string ciphertext, text;
103 char x[26], y[26];
104 x[0] = 'A', x[1] = 'B', x[2] = 'C', x[3] = 'D', x[4] = 'E', x[5] = 'F', x[6] = 'G', x[7] = 'H', x[8] = 'I', x[9] = 'J', x[10] = 'K', x[11] = 'L';
105 x[12] = 'M', x[13] = 'N', x[14] = 'O', x[15] = 'P', x[16] = 'Q', x[17] = 'R', x[18] = 'S', x[19] = 'T', x[20] = 'U', x[21] = 'V', x[22] = 'W', x[23] = 'X', x[24] = 'Y', x[25] = 'Z';
106
107 y[25] = 'A', y[24] = 'B', y[23] = 'C', y[22] = 'D', y[21] = 'E', y[20] = 'F', y[19] = 'G', y[18] = 'H', y[17] = 'I', y[16] = 'J', y[15] = 'K', y[14] = 'L';
108 y[13] = 'M', y[12] = 'N', y[11] = 'O', y[10] = 'P', y[9] = 'Q', y[8] = 'R', y[7] = 'S', y[6] = 'T', y[5] = 'U', y[4] = 'V', y[3] = 'W', y[2] = 'X', y[1] = 'Y', y[0] = 'Z';
109 cout << "enter the plain text : ";
110 cin.ignore();
111 getline(cin, text);
112 cout << endl;
113 for (int j = 0; j < text.size(); j++)
114 {
115 text[j] = char(toupper(text[j]));
116 for (int i = 0; i < 26; i++)
117 {
118 if (text[j] == x[i])
119 {
120 ciphertext += y[i];
121 }
122 }
123 if (text[j] == ' ')
124 {
125 ciphertext += ' ';
126 }
127 }
128 cout << "The ciphered text is : " << ciphertext;
129 }
130
131 if (cipherNum == 4)
132 {
133 char letters[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
134 char ciphers[26] = { 'n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m' };
135 string sentence;
136 cout << "Enter the Message to Cipher : ";
137 cin.ignore();
138 getline(cin, sentence);
139 cout << "\n The Ciphered Message is : ";
140 for (int i = 0; i < sentence.size(); i++)
141 {
142 sentence[i] = char(tolower(sentence[i]));
143 if (sentence[i] > 122 || sentence[i] < 97)
144 {
145 cout << sentence[i];
146 continue;
147 }
148 if (sentence[i] == '1' || sentence[i] == '2' || sentence[i] == '3' || sentence[i] == '4' || sentence[i] == '5' || sentence[i] == '6' || sentence[i] == '7' || sentence[i] == '8' || sentence[i] == '9' || sentence[i] == '0')
149 cout << sentence[i];
150 else if (sentence[i] == ' ')
151 cout << ' ';
152 else
153 {
154 for (int k = 0; k < 26; k++)
155 {
156 if (sentence[i] == letters[k])
157 {
158 cout << ciphers[k];
159 break;
160 }
161 }
162 }
163
164 }
165 }
166
167 if (cipherNum == 5)
168 {
169 char letters[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
170 string ciphers[26] = { "aaaaa","aaaab","aaaba","aaabb","aabaa","aabab",
171 "aabba","aabbb","abaaa","abaab","ababa","ababb","abbaa",
172 "abbab","abbba","abbbb","baaaa","baaab","baaba","baabb",
173 "babaa","babab","babba","babbb","bbaaa","bbaab" };
174 string sentence;
175 cout << "Enter the Message to Cipher : ";
176 cin.ignore();
177 getline(cin, sentence);
178 cout << "\n The Ciphered Message is : ";
179 for (int i = 0; i < sentence.size(); i++)
180 {
181 sentence[i] = char(tolower(sentence[i]));
182 if (sentence[i] == ' ') {
183 cout << " ";
184 continue;
185 }
186 for (int k = 0; k < 27; k++)
187 {
188 if (sentence[i] == letters[k])
189 cout << ciphers[k] << " ";
190 else
191 continue;
192 }
193 }
194 }
195
196 if (cipherNum == 6)
197 {
198 int x;
199 string key, word, askii = "abcdefghijklmnopqrstuvwzyz";
200 cout << "enter the Keys of cipher\n=> ";
201 cin >> key;
202 cin.ignore();
203 cout << "enter the letter \n=> ";
204 getline(cin, word);
205 for (int i = 0; i < word.size(); i++)
206 {
207 word[i] = char(tolower(word[i]));
208 word[i] + '0';
209 if (word[i] > 122 || word[i] < 97) { continue; }
210 x = word[i] - 97;
211 word[i] = key[x];
212 }
213 cout << "=> " << word << endl;
214 }
215
216 if (cipherNum == 7)
217 {
218 int a, b, y, m;
219 string change, word;
220 char new_key[5][5] = {
221 { 'a','b','c','d','e' },
222 { 'f','g','h','i','j' },
223 { 'k','l','m','n','o' },
224 { 'p','q','r','s','t' },
225 { 'u','v','x','y','z' } };
226 char key[5][5] = {
227 { 'a','b','c','d','e' },
228 { 'f','g','h','i','j' },
229 { 'k','l','m','n','o' },
230 { 'p','q','r','s','t' },
231 { 'u','v','x','y','z' } };
232 cout << "enter the key\n=>";
233 cin >> change;
234
235 for (int i = 0; i < 5; i++)
236 {
237 for (int j = 0; j < 5; j++)
238 {
239 m = (change[i] - '0') - 1;
240 new_key[m][j] = key[i][j];
241 }
242 }
243
244 for (int i = 0; i < 5; i++)
245 {
246 for (int j = 0; j < 5; j++)
247 {
248 m = (change[j] - '0') - 1;
249 key[i][m] = new_key[i][j];
250
251 }
252 }
253 cout << "enter your letter\n=>";
254 cin.ignore();
255 getline(cin, word);
256 for (int i = 0; i < word.size(); i++)
257 {
258 word[i] = char(tolower(word[i]));
259 word[i] + '0';
260 if (word[i] > 122 || 97 > word[i]) { cout << word[i]; continue; }
261 if (word[i] == 'w') { cout << ","; continue; }
262 for (int a = 0; a < 5; a++)
263 {
264 for (int b = 0; b < 5; b++)
265 {
266 if (word[i] == key[a][b])
267 {
268 cout << a + 1 << b + 1;
269 break;
270 }
271
272 }
273 }
274 }
275 }
276
277 if (cipherNum == 8)
278 {
279 char letters[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
280 string ciphers[] = { ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.." };
281 string sentence;
282 cout << "Enter the Message to Cipher : ";
283 cin.ignore();
284 getline(cin, sentence);
285 cout << "\n The Ciphered Message is : ";
286 for (int i = 0; i < sentence.size(); i++)
287 {
288 sentence[i] = char(tolower(sentence[i]));
289 if (sentence[i] == ' ') {
290 cout << " ";
291 continue;
292 }
293 for (int k = 0; k < 27; k++)
294 {
295 if (sentence[i] == letters[k]) {
296 cout << ciphers[k] << " ";
297 }
298 }
299 }
300 cout << endl;
301 }
302
303 if (cipherNum == 9)
304 {
305 string text, ciphertext;
306 char key;
307 cout << "enter the plain text : ";
308 cin.ignore();
309 getline(cin, text);
310 cout << endl;
311 cout << "enter the secret key : ";
312 cin >> key;
313 cout << endl;
314 cout << "HEXA Representation :";
315 for (int i = 0; i < text.size(); i++)
316 {
317 ciphertext += int(text[i]) ^ (int(key)) % (int(sizeof(text)));
318 cout << hex << int(ciphertext[i]);
319
320 }
321 cout << "\n" << "Cipher text : " << ciphertext << "\n";
322 }
323
324 if (cipherNum == 10)
325 {
326 int key;
327 cout << "\nchoose num bigger than 1 ==>>";
328 cin >> key;
329 string w;
330 cout << "\n enter the word which you would cipher ==>>";
331 cin.ignore();
332 getline(cin, w);
333 if (key == 1)
334 {
335 cout << w;
336 }
337 else if (key <= 0)
338 {
339 cout << "error >.< e5tar rakam tany ya zaky";
340 }
341 else if (key > 2 * (w.size() - 1))
342 {
343 cout << "this number is too longer pleas try again ^.^ ";
344 }
345 else
346 {
347 char c[key][28] = {};
348 for (int i = 0; i < key; i++)
349 for (int j = 0; j < 28; j++)
350 c[i][j] = '.';
351 int j = 0;
352 int i = 0;
353 int line = 0;
354 while (i < w.length())
355 {
356 while (line < key)
357 {
358 c[line][j] = w[i];
359 line++;
360 j++;
361 i++;
362 if (i >= w.length())
363 break;
364 }
365 line -= 2;
366 while (line >= 0)
367 {
368 c[line][j] = w[i];
369 line--;
370 j++;
371 i++;
372 if (i >= w.length())
373 break;
374 }
375 line += 2;
376 }
377
378 string word;
379 for (int i = 0; i < key; i++)
380 {
381 for (int j = 0; j < 28; j++)
382 {
383 if (c[i][j] != '.')
384 word += c[i][j];
385 }
386 }
387 cout << word << endl;
388 }
389 }
390 }
391
392 if (choice == 2)
393 {
394 cout << "\nWhat is the type of the ciphered message ?\n";
395 cout << "\t1. Affine Cipher\n\t2. Caesar Cipher\n\t3. Atbash Cipher\n\t4. ROT13 Cipher\n\t5.Baconian Cipher\n\t6. Simple Substitution Cipher\n\t7. Polybius Square Cipher\n\t8. Morse Code\n\t9. XOR Cipher\n\t10. Rail-fence Cipher\n ";
396 cin >> cipherNum;
397 cout << endl;
398
399 if (cipherNum == 1)
400 {
401 int a, b, c;
402 cout << "enter the keys.3 int a, b and c and should (a*c)%26=1 is true\n";
403 cout << "a =>";
404 cin >> a;
405 cout << "\nb=>";
406 cin >> b;
407 cout << "\nc=>";
408 cin >> c;
409 if ((a*c) % 26 != 1) {
410 while (true)
411 {
412 cout << "invalid\nenter the keys.3 int a, b and c and should (a*c)%26=1 is true\n";
413 cout << "a =>";
414 cin >> a;
415 cout << "\nb=>";
416 cin >> b;
417 cout << "\nc=>";
418 cin >> c;
419 if ((a*c) % 26 == 1) { break; }
420 }
421 }
422 string word;
423 int m;
424 cout << "enter your letter\n=>";
425 cin.ignore();
426 getline(cin, word);
427 for (int i = 0; i < word.size(); i++)
428 {
429 word[i] = char(tolower(word[i]));
430 word[i] + '0';
431 if (word[i] > 122 || 97 > word[i]) { continue; }
432 m = word[i] - 97;
433 if (m < b) { m = (c*(26 + (m - b))) % 26; } //to ignore the '-'
434 else { m = (c*(m - b)) % 26; }
435 word[i] = 97 + m;
436 }
437 cout << "->" << word;
438 }
439
440 if (cipherNum == 2)
441 {
442 char x[27];
443 x[0] = 'A', x[1] = 'B', x[2] = 'C', x[3] = 'D', x[4] = 'E', x[5] = 'F', x[6] = 'G', x[7] = 'H', x[8] = 'I', x[9] = 'J', x[10] = 'K', x[11] = 'L';
444 x[12] = 'M', x[13] = 'N', x[14] = 'O', x[15] = 'P', x[16] = 'Q', x[17] = 'R', x[18] = 'S', x[19] = 'T', x[20] = 'U', x[21] = 'V', x[22] = 'W', x[23] = 'X', x[24] = 'Y', x[25] = 'Z';
445 string ciphertext, text;
446 int shifts, y;
447 cout << "enter the cipher text : ";
448 cin.ignore();
449 getline(cin, ciphertext);
450 cout << endl;
451 cout << "enter the number of shifts : ";
452 cin >> shifts;
453 cout << endl;
454 for (int i = 0; i < ciphertext.size(); i++)
455 {
456 ciphertext[i] = char(toupper(ciphertext[i]));
457 for (int j = 0; j < 26; j++)
458 {
459 if (ciphertext[i] == x[j] && j - shifts >= 0)
460 {
461 text += x[j - shifts];
462 }
463 else if (ciphertext[i] == x[j] && j - shifts < 0)
464 {
465 y = (j + (26 - shifts));
466 text += x[y];
467 }
468 }
469 }
470 cout << "the plain text : " << text;
471 }
472
473 if (cipherNum == 3)
474 {
475 string ciphertext, text;
476 char x[26], y[26];
477 x[0] = 'A', x[1] = 'B', x[2] = 'C', x[3] = 'D', x[4] = 'E', x[5] = 'F', x[6] = 'G', x[7] = 'H', x[8] = 'I', x[9] = 'J', x[10] = 'K', x[11] = 'L';
478 x[12] = 'M', x[13] = 'N', x[14] = 'O', x[15] = 'P', x[16] = 'Q', x[17] = 'R', x[18] = 'S', x[19] = 'T', x[20] = 'U', x[21] = 'V', x[22] = 'W', x[23] = 'X', x[24] = 'Y', x[25] = 'Z';
479
480 y[25] = 'A', y[24] = 'B', y[23] = 'C', y[22] = 'D', y[21] = 'E', y[20] = 'F', y[19] = 'G', y[18] = 'H', y[17] = 'I', y[16] = 'J', y[15] = 'K', y[14] = 'L';
481 y[13] = 'M', y[12] = 'N', y[11] = 'O', y[10] = 'P', y[9] = 'Q', y[8] = 'R', y[7] = 'S', y[6] = 'T', y[5] = 'U', y[4] = 'V', y[3] = 'W', y[2] = 'X', y[1] = 'Y', y[0] = 'Z';
482 cout << "enter the cipher text : ";
483 cin.ignore();
484 getline(cin, ciphertext);
485 cout << endl;
486 for (int j = 0; j < ciphertext.size(); j++)
487 {
488 ciphertext[j] = char(toupper(ciphertext[j]));
489 for (int i = 0; i < 26; i++)
490 {
491 if (ciphertext[j] == y[i])
492 {
493 text += x[i];
494 }
495 }
496 if (ciphertext[j] == ' ')
497 {
498 text += ' ';
499 }
500 }
501 cout << "The desiphered Text is : " << text;
502 }
503
504 if (cipherNum == 4)
505 {
506 char letters[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
507 char ciphers[26] = { 'n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m' };
508 string sentence;
509 cin.ignore();
510 cout << "Enter the Ciphered Message : ";
511 getline(cin, sentence);
512 cout << "The Deciphered Message is : ";
513 for (int i = 0; i < sentence.size(); i++)
514 {
515 sentence[i] = char(tolower(sentence[i]));
516 if (sentence[i] == '1' || sentence[i] == '2' || sentence[i] == '3' || sentence[i] == '4' || sentence[i] == '5' || sentence[i] == '6' || sentence[i] == '7' || sentence[i] == '8' || sentence[i] == '9' || sentence[i] == '0')
517 cout << sentence[i];
518 else if (sentence[i] == ' ')
519 cout << ' ';
520 else
521 {
522 for (int k = 0; k < 26; k++)
523 {
524 if (sentence[i] == ciphers[k])
525 {
526 cout << letters[k];
527 break;
528 }
529 }
530 }
531
532 }
533 }
534
535 if (cipherNum == 5)
536 {
537 char letters[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
538 string ciphers[26] = { "aaaaa","aaaab","aaaba","aaabb","aabaa","aabab","aabba","aabbb","abaaa","abaab","ababa","ababb","abbaa","abbab","abbba","abbbb","baaaa","baaab","baaba","baabb","babaa","babab","babba","babbb","bbaaa","bbaab" };
539 string sentence;
540 string word = "";
541 int coun = 0;
542 cout << "Enter a space between each ciphered letters and 3 spaces between each ciphered words\n\n";
543 cout << "Enter the Ciphered Message : ";
544 getline(cin, sentence);
545 cout << "The Deciphered Message is : ";
546 for (int i = 0; i < sentence.size(); i++)
547 {
548 while (sentence[i] != ' ' && i < sentence.size())
549 {
550 word += sentence[i];
551 i++;
552 }
553 for (int k = 0; k < 26; k++)
554 {
555 if (word == ciphers[k])
556 {
557 cout << letters[k];
558 word.clear();
559 break;
560 }
561 }
562 while (sentence[i] == ' '&& i < sentence.size())
563 {
564 coun++; i++;
565 }
566 if (coun == 3)cout << " ";
567 coun = 0;
568 i--;
569 }
570 cout << endl;
571 }
572
573 if (cipherNum == 6)
574 {
575 string word, key, askii = "abcdefghijklmnopqrstuvwzyz";
576 cout << "enter the Keys of cipher\n=> ";
577 cin >> key;
578 cin.ignore();
579 cout << "enter the letter \n=> ";
580 getline(cin, word);
581 for (int i = 0; i < word.size(); i++)
582 {
583 word[i] = char(tolower(word[i]));
584 word[i] + '0';
585 if (word[i] > 122 || word[i] < 97) { continue; }
586 for (int a = 0; a < 26; a++)
587 {
588 if (key[a] == word[i]) { word[i] = askii[a]; break; }
589 }
590
591 }
592 cout << "=> " << word << endl;
593 }
594
595 if (cipherNum == 7)
596 {
597 int a, b, y, m;
598 string change, word;
599 char new_key[5][5] = {
600 { 'a','b','c','d','e' },
601 { 'f','g','h','i','j' },
602 { 'k','l','m','n','o' },
603 { 'p','q','r','s','t' },
604 { 'u','v','x','y','z' } };
605 char key[5][5] = {
606 { 'a','b','c','d','e' },
607 { 'f','g','h','i','j' },
608 { 'k','l','m','n','o' },
609 { 'p','q','r','s','t' },
610 { 'u','v','x','y','z' } };
611 cout << "enter the key\n=>";
612 cin >> change;
613
614 for (int i = 0; i < 5; i++)
615 {
616 for (int j = 0; j < 5; j++)
617 {
618 m = (change[i] - '0') - 1;
619
620 new_key[m][j] = key[i][j];
621
622 }
623 }
624
625 for (int i = 0; i < 5; i++)
626 {
627 for (int j = 0; j < 5; j++)
628 {
629 m = (change[j] - '0') - 1;
630 key[i][m] = new_key[i][j];
631
632 }
633 }
634 cout << "enter your letter\n=>";
635 cin >> word;
636 for (int i = 0; i < word.size(); i = i + 2)
637 {
638 if (word[i] == ' ') { continue; }
639 if (word[i] == ',') { cout << "w"; i + i - 1; continue; }
640 word[i] + '0';
641 a = word[i] - 48;
642 b = word[i + 1] - 48;
643 cout << key[a - 1][b - 1];
644 }
645 }
646
647 if (cipherNum == 8)
648 {
649 char letters[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
650 string ciphers[] = { ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.." };
651 string sentence;
652 int coun = 0;
653 string word;
654 cin.ignore();
655 cout << "Enter a space between each ciphered letters and 3 spaces between each ciphered words\n";
656 cout << "Enter the Ciphered Message : ";
657 getline(cin, sentence);
658 cout << "The Deciphered Message is : ";
659 for (int i = 0; i < sentence.size(); i++)
660 {
661 while (sentence[i] != ' ' && i < sentence.size())
662 {
663 word += sentence[i];
664 i++;
665 }
666 for (int k = 0; k < 26; k++)
667 {
668 if (word == ciphers[k])
669 {
670 cout << letters[k];
671 word.clear();
672 break;
673 }
674 }
675 while (sentence[i] == ' '&& i < sentence.size())
676 {
677 coun++; i++;
678 }
679 if (coun == 3)cout << " ";
680 coun = 0;
681 i--;
682 }
683 cout << endl;
684 }
685 if (cipherNum == 9)
686 {
687 string ciphertext, text;
688 char secretkey;
689 cout << "enter the cipher text : ";
690 cin.ignore();
691 getline(cin, ciphertext);
692 cout << endl;
693 cout << "enter the secret key : ";
694 cin >> secretkey;
695 cout << endl;
696 cout << "HEXA Representation :";
697 for (int i = 0; i < ciphertext.size(); i++)
698 {
699 text += int(ciphertext[i]) ^ (int(secretkey)) % (int(sizeof(ciphertext)));
700 cout << hex << int(text[i]);
701 }
702 cout << "\n" << "The Plain Text : " << text << "\n";
703 }
704
705 if (cipherNum == 10)
706 {
707 int key, m = 0;
708 cout << "\nchoose num bigger than 1 ==>>";
709 cin >> key;
710 string w;
711 cout << "\n enter the word which you would cipher ==>>";
712 cin >> w;
713 if (key == 1)
714 {
715 cout << w;
716 }
717 else if (key <= 0)
718 {
719 cout << "error >.< e5tar rakam tany ya zaky";
720 }
721 else if (key > 2 * (w.size() - 1))
722 {
723 cout << "this number is too longer pleas try again ^.^ ";
724 }
725 else
726 {
727
728 char c[key][28] = {};
729 for (int i = 0; i < key; i++)
730 {
731 for (int j = 0; j < 28; j++)
732 {
733 c[i][j] = '.';
734 }
735 }
736 int j = 0;
737 int i = 0;
738 int line = 0;
739 while (i < w.length())
740 {
741 while (line < key)
742 {
743 if (c[line][j] == ' ')
744 {
745 continue;
746 }
747 c[line][j] = 'x';
748 line++;
749 j++;
750 i++;
751 if (i >= w.length())
752 break;
753 }
754 line -= 2;
755
756 while (line >= 0)
757 {
758 if (c[line][j] == ' ')
759 {
760 continue;
761 }
762 c[line][j] = 'x';
763 line--;
764 j++;
765 i++;
766 if (i >= w.length())
767 break;
768 }
769 line += 2;
770 }
771
772
773 for (int i = 0; i < key; i++)
774 {
775 for (int j = 0; j < w.length(); j++)
776 {
777
778 if (c[i][j] == 'x')
779 {
780 c[i][j] = w[m];
781 m++;
782 }
783 }
784 }
785
786 j = 0;
787 i = 0;
788 line = 0;
789 while (i < w.length())
790 {
791 while (line < key)
792 {
793 if (c[line][j] == 'x')
794 {
795 continue;
796 }
797 cout << c[line][j];
798 line++;
799 j++;
800 i++;
801 if (i >= w.length())
802 break;
803 }
804 line -= 2;
805 while (line >= 0)
806 {
807 if (c[line][j] == 'x')
808 {
809 continue;
810 }
811 cout << c[line][j];
812 line--;
813 j++;
814 i++;
815 if (i >= w.length())
816 break;
817 }
818 line += 2;
819 }
820 }
821 }
822 return 0;
823 }
824 }