-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtbash.cpp
72 lines (65 loc) · 1.63 KB
/
Atbash.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 🗃️
#include <iostream>
#include <string>
// end include
// declare functions 🛠️
// get the Atbash corresponding letter [eg: a -> z, b -> y, h -> s]
char Atbash(char x);
// convert a string to the corresponding Atbash cyper
std::string Atbash(std::string TheString);
// main with args
int main(int argc, char *argv[])
{
// if there is only one word there is no need for a for loop
if (argc == 2)
{
std::cout << Atbash(argv[1]) << std::endl;
}
// add all the argvs if there is more then one and Atbsh cyper
else if (argc > 2)
{
// The for loop for adding all of the argvs to one string
std::string concatenated_args;
for (int i = 1; i < argc; ++i)
{
concatenated_args += argv[i];
if (i < argc - 1)
{
concatenated_args += " "; // Add a space between arguments } }
}
}
std::cout << Atbash(concatenated_args) << std::endl;
}
// error wrong Usage
else
{
std::cout << "Usage: command [The string ]" << std::endl;
}
return 0;
}
// get the Atbash corresponding letter [eg: a -> z, b -> y, h -> s]
char Atbash(char x)
{
if (x >= 'a' && x <= 'z')
{
return ('a' + 'z') - x;
}
else if (x >= 'A' && x <= 'Z')
{
return ('A' + 'Z') - x;
}
else
{
return x;
}
}
// convert a string to the corresponding Atbash cyper
std::string Atbash(std::string TheString)
{
std::string afterCode = "";
for (int i = 0; i < TheString.length(); ++i)
{
afterCode += (Atbash(TheString[i]));
}
return afterCode;
}