-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
42 lines (37 loc) · 1.04 KB
/
main.cpp
File metadata and controls
42 lines (37 loc) · 1.04 KB
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
/**
* Ceasar cipher takes a given letter and changes the letter by moving the
* letter a key value amount.
*/
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <time.h>
using std::cin;
using std::cout;
using std::endl;
// axilliary function for creating key value
int randomize() {
srand(time(0));
return rand() % 26; // range of 0 to 25, 26 non-inclusive
}
// c: user inputted letter
char cipher(char c) {
int temp = randomize();
// cout << "whats in randomize: " << temp <<endl;
char alpha[] = {'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'}; // 26 LETTERS
if (c != alpha[temp])
return alpha[(c + temp) % 26];
else
return cipher(c);
}
int main(int argc, char *argv[]) {
char ch1;
cout << "please only insert ONE capital letter" << endl;
cin >> ch1;
char code = cipher(ch1);
cout << "given: " << ch1 << ", encrypted: " << code << " key: " << code - ch1;
}