-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
79 lines (67 loc) · 1.9 KB
/
main.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
73
74
75
76
77
78
79
// g++ PhotoMagic.o LFSR.o bit_flags.o -o encrypt -lsfml-graphics -lsfml-window -lsfml-system
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
#include <sstream>
#include <map>
#include <bitset>
#include <algorithm>
#include<iterator>
#include "EncFile.hpp"
void split(const std::string& str,std::vector<std::string>& cont, char delim = ' ');
filetype findFileType(std::string ext);
int main(int argc, char** argv)
{
std::string password;
//if a password argument was given (only 4 arguments)
//sum integer value of every element in password
//convert to string representation of binary value
//and initialize lfsr with this seedand default tap of 2
if(argc==4){
password = argv[3];
}
//else initialize tap and seed as given tap and seed
else{
cout<<"Correct Format: ./Encrypt infile outfile password"<<endl;
return -1;
}
// create vector of tokens
// to extract filetype
std::vector<std::string> tokens;
std::string input = argv[1];//set name of input file
std::string output = argv[2];//set name of output file
split(input, tokens, '.');
string ext = tokens.back();
filetype ftype;
ftype=findFileType(ext);
EncFile file(input,ftype,password,output);
file.softEncrypt();
try{
file.writeFile();
}
catch(std::runtime_error e){
cout<<e.what()<<endl;
}
return 0;
}
// function to split string
// works similar to (no default delimeter) string.split() in python
void split(const std::string& str,std::vector<std::string>& cont, char delim)
{
std::stringstream ss(str);
std::string token;
while (std::getline(ss, token, delim)) {
cont.push_back(token);
}
}
filetype findFileType(std::string ext){
if(ext == "jpg"||ext=="jpeg"||ext=="png"||ext=="pdf")
return filetype::image;
else if(ext=="txt")
return filetype::text;
else
throw std::runtime_error("invalid file extension");
return none;
}