-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROT13MAP.CPP
executable file
·72 lines (66 loc) · 1.57 KB
/
ROT13MAP.CPP
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
#include <map>
#include <iostream>
#include <ctype.h>
class rot13{
public:
//initializes the map
rot13();
//given c, prints out c.rot(13)
void shift(char c);
private:
//oh my god!, who's got the map?
//havent we been here before?...
//it is the same tree...
map<char,char> letters;
};
void main(){
char a;
rot13 rotter;
while (cin>>a){
rotter.shift(a);
//putchar(~a-1/(~(a|32)/13*2-11)*13);
}
}
rot13::rot13(){
letters['a']='n';
letters['b']='o';
letters['c']='p';
letters['d']='q';
letters['e']='r';
letters['f']='s';
letters['g']='t';
letters['h']='u';
letters['i']='v';
letters['j']='w';
letters['k']='x';
letters['l']='y';
letters['m']='z';
letters['n']='a';
letters['o']='b';
letters['p']='c';
letters['q']='d';
letters['r']='e';
letters['s']='f';
letters['t']='g';
letters['u']='h';
letters['v']='i';
letters['w']='j';
letters['x']='k';
letters['y']='l';
letters['z']='m';
}
void rot13::shift(char c){
bool upper = false; //one who ups
map<char, char>::iterator search;
if (isupper(c)){ //this works
upper=true;
c=tolower(c);
}
//if(letters.find(c)){
search= letters.find(c);
c=search->second;
if(upper)
cout<<char(toupper(c));
else
cout<<c;
}