-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvigenere.cpp
More file actions
46 lines (40 loc) · 1.19 KB
/
vigenere.cpp
File metadata and controls
46 lines (40 loc) · 1.19 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
43
44
45
46
// Require C++ >= 11 to compile
#include <iostream>
#include "vigenere.hpp"
int main(int argc, char *argv[])
{
if (argc == 1)
{
std::cout << "vigenere <command> [input] [key]" << std::endl
<< std::endl
<< "<command>" << std::endl
<< "e\tEncrypt string [input] with string [key]" << std::endl
<< "d\tDecrypt string [input] with string [key]" << std::endl;
return 0;
}
else if (argc != 4)
{
std::cout << "Wrong parameter(s)" << std::endl;
return 1;
}
std::string cmd = argv[1];
std::string input = argv[2];
std::string key = argv[3];
// Standardized [key] string
std::transform(key.begin(), key.end(), key.begin(), ::toupper);
if (!isAlphaOnly(key))
{
std::cout << "[key] contain irregular character(s)" << std::endl;
return 1;
}
if (key.length() < 2)
{
std::cout << "[key] is too short" << std::endl;
return 1;
}
if (cmd == "e")
std::cout << encrypt(input, key);
else if (cmd == "d")
std::cout << decrypt(input, key);
return 0;
}