-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage.cpp
173 lines (172 loc) · 4.86 KB
/
Image.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "Image.h"
inline bool exist (string name) {
ifstream f(name.c_str());
if(f.good())
{
f.close();
return true;
}
return false;
}
Image::Image(){}
int Image::desteg(string stegofile,string extractedfile)
{
string command = "steghide extract -sf "+stegofile+" -p groupH -xf "+extractedfile+" -f";
system(command.c_str());
}
int Image::steg(string secretfile,string coverfile,string stegofile)
{
string command = "steghide embed -cf "+coverfile+" -ef "+ secretfile+" -p groupH -sf "+stegofile+" -f";
system(command.c_str());
}
int Image::desteg()
{
destegImagePath = string(IMAGE_DIR)+ownerUsername+"_"+imageId+"_desteg"+".jpg";
propertiesPath = string(IMAGE_DIR)+ownerUsername+"_"+imageId+"_properties"+".txt";
//extracting desteg from steg
desteg(stegImagePath,destegImagePath);
//extracting properties from desteg
desteg(destegImagePath,propertiesPath);
return 0;
}
//properties are written
int Image::steg()
{
propertiesPath = IMAGE_DIR+ownerUsername+"_"+imageId+"_properties"+".txt";
destegImagePath = IMAGE_DIR+ownerUsername+"_"+imageId+"_desteg"+".jpg";
stegImagePath = IMAGE_DIR+ownerUsername+"_"+imageId+"_steg"+".jpg";
//Embedding properties into original to desteg
steg(propertiesPath,destegImagePath,destegImagePath);
//Embedding desteg into default to steg
steg(destegImagePath,string(COVER_IMAGE),stegImagePath);
return 0;
}
void Image::removeMiddleFiles()
{
string command="rm "+destegImagePath+" "+propertiesPath+" -f";
system(command.c_str());
}
void Image::writeProperties()
{
propertiesPath = IMAGE_DIR+ownerUsername+"_"+imageId+"_properties"+".txt";
ofstream output;
output.open(propertiesPath);
for(int i = 0;i<properties.size();i++)
{
output<<properties[i].user_name<<" "<<properties[i].views;
if(i<properties.size()-1)
output<<endl;
}
output.close();
}
bool Image::findImage(string ownerusername,string imageId)
{
setownerUsername(ownerusername);
setImageId(imageId);
stegImagePath=string(IMAGE_DIR)+ownerUsername+"_"+imageId+"_steg.jpg";
if(!exist(stegImagePath))
return false;
return true;
}
void Image::writeImage(string image,string ownerusername,string imageId)
{
setownerUsername(ownerusername);
setImageId(imageId);
stegImagePath = IMAGE_DIR+ownerUsername+"_"+imageId+"_steg"+".jpg";
ofstream out;
out.open(stegImagePath,ios_base::out | ios_base::binary);
out<<image;
out.close();
}
int Image::updateProperties()
{
desteg();
writeProperties();
steg();
string command = "rm "+destegImagePath+" "+propertiesPath+" -f";
system(command.c_str());
}
int Image::readProperties()
{
desteg();
ifstream input;
input.open(propertiesPath);
while (!input.eof())
{
userProperty prop;
input>>prop.user_name;
input>>prop.views;
if(prop.user_name=="DoNotUse")
break;
properties.push_back(prop);
}
input.close();
string command = "rm "+destegImagePath+" "+propertiesPath+" -f";
system(command.c_str());
return 0;
}
int Image::chooseImage(string path)
{
destegImagePath = IMAGE_DIR+ownerUsername+"_"+imageId+"_desteg"+".jpg";
string command = "convert "+path+" "+destegImagePath;
system(command.c_str());
return 0;
}
int Image::setImageId(string id)
{
imageId=id;
return 0;
}
int Image::getImageId(string& id)
{
if(imageId=="")
return USERNAME_ERROR;
id= imageId;
return 0;
}
int Image::setownerUsername(string username)
{
ownerUsername=username;
return 0;
}
int Image::getownerUsername(string& username)
{
if(ownerUsername=="")
return USERNAME_ERROR;
username= ownerUsername;
return 0;
}
string Image::extractImage()
{
//steg();
ifstream fin(stegImagePath,ios::binary);
string extract = string(istreambuf_iterator<char>(fin), istreambuf_iterator<char>());
fin.close();
return extract;
}
string Image::getAuthorizedImagePath()
{
desteg();
string command = "rm "+propertiesPath+" -f";
system(command.c_str());
return destegImagePath;
}
string Image::getUnAuthorizedImagePath()
{
return stegImagePath;
}
string Image::getSmallScaleImage()
{
string command = "convert "+destegImagePath+" -resize 64x64 64x64temp.jpg";
system(command.c_str());
ifstream fin("64x64temp.jpg",ios::binary);
string extract = string(istreambuf_iterator<char>(fin), istreambuf_iterator<char>());
fin.close();
command = "rm 64x64temp.jpg -f";
system(command.c_str());
extract = base64_encode(reinterpret_cast<const unsigned char*>(reinterpret_cast<const unsigned char*> (extract.c_str())), extract.size() + 1);
extract = base64_encode(reinterpret_cast<const unsigned char*>(reinterpret_cast<const unsigned char*> (extract.c_str())), extract.size() + 1);
return extract;
}
Image::~Image()
{}