-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdecrypt.cpp
More file actions
47 lines (44 loc) · 975 Bytes
/
decrypt.cpp
File metadata and controls
47 lines (44 loc) · 975 Bytes
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
/*********************************************************
File Name: decrypt.cpp
Author: Abby Cin
Mail: abbytsing@gmail.com
Created Time: Sat 17 Dec 2016 04:02:01 PM CST
**********************************************************/
#include <iostream>
#include <fstream>
#include "crypto.h"
void cb(int magic, std::string &s)
{
for (auto &x : s)
x -= magic;
}
int main(int argc, char *argv[])
{
if (argc != 3) {
fprintf(stderr, "%s magic path\n", argv[0]);
return 1;
}
int magic = 0;
try {
magic = std::stoi(argv[1]);
}
catch (const std::logic_error &e) {
std::cerr << "Invalid magic number\n";
return 1;
}
std::ifstream in(argv[2]);
if (!in.is_open()) {
std::cerr << "Can't open file: " << argv[2] << std::endl;
return 1;
}
std::string s;
char c = '\0';
in.read(&c, 1);
in.read(&c, 1);
in.read(&c, 1);
std::getline(in, s);
in.close();
Crypto crypto;
auto res = crypto.decode(s, magic, cb);
std::cout << res << std::endl;
}