-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaders.h
More file actions
272 lines (243 loc) · 9.25 KB
/
headers.h
File metadata and controls
272 lines (243 loc) · 9.25 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/**
* \file headers.h
* \brief Заголовочный файл, содержащий объявления функций, используемых для стеганографических операций
*/
#ifndef HEADERS_H
#include "stb_image.h"
#include "stb_image_write.h"
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <filesystem>
#include <sstream>
/**
* \brief Структура для хранения данных изображения
*/
struct ImageData
{
unsigned char *data;
int width;
int height;
int channels;
ImageData();
};
/**
* \brief Читает содержимое файла в строку
*
* \param file_path Путь к файлу для чтения
* \return std::string Содержимое файла в виде строки
* \throw std::runtime_error Если файл не может быть открыт
*/
std::string read_file_to_string(const std::string &file_path);
/**
* \brief Встраивает сообщение в изображение методом QIM
* \param original Путь к исходному изображению
* \param stego Путь для сохранения стего-изображения
* \param msg_file Путь к файлу с встраиваемым сообщением
* \param q_str Параметр квантования
* \throw std::runtime_error Если файл не может быть открыт
*/
void qim_embed(const std::string &original, const std::string &stego, const std::string &msg_file,
const std::string &q_str);
/**
* \brief Извлекает сообщение из стего-изображения методом QIM
* \param stego Путь к стего-изображению
* \param q_str Параметр квантования
* \param output_file Путь для сохранения извлеченного сообщения
* \throw std::runtime_error Если файл не может быть открыт
*/
void qim_extract(const std::string &stego, const std::string &q_str, const std::string &output_file);
/**
* \brief Встраивает сообщение в изображение методом LSB
* \param original Путь к исходному изображению
* \param stego Путь для сохранения стего-изображения
* \param msg_file Путь к файлу с сообщением для встраивания
* \throw std::runtime_error Если файл не может быть открыт
*/
void lsb_embed(const std::string &original, const std::string &stego, const std::string &msg_file);
/**
* \brief Извлекает сообщение из стего-изображения методом LSB
* \param stego Путь к стего-изображению
* \param output_file Путь для сохранения извлеченного сообщения
* \throw std::runtime_error Если файл не может быть открыт
*/
void lsb_extract(const std::string &stego, const std::string &output_file);
/**
* \brief Встраивает сообщение в изображение методом CD
* \param original Путь к исходному изображению
* \param stego Путь для сохранения стего-изображения
* \param msg_file Путь к файлу с сообщением для встраивания
* \throw std::runtime_error Если файл не может быть открыт
*/
void cd_embed(const std::string &original, const std::string &stego, const std::string &msg_file);
/**
* \brief Извлекает сообщение из стего-изображения методом CD
* \param stego Путь к стего-изображению
* \param output_file Путь для сохранения извлеченного сообщения
* \throw std::runtime_error Если файл не может быть открыт
*/
void cd_extract(const std::string &stego, const std::string &output_file);
// Marlen part
/**
* @brief BasicImage is class that realise basic work with image throw stb_image
* module.
*
* @throw CAN_NOT_LOAD_IMAGE_FILE(LOAD_IMAGE_PIXELS:CAN_NOT_LOAD_IMAGE_FILE) -
* When image loader in stb_image can not open image file;
* @throw CAN_NOT_SAVE_IMAGE - When function save_result can not save image with
* redacted data throw stb_image module;
*
* @return In constructor function class returns own object with
* accessible(public) functions: get_image_loader, get_image_params,
* get_pixels_range, save_result, free_space
*/
class BasicImage
{
public:
/**
* @brief Constructor for class BasicImage, that helps work with images.
*
* @param img_path Constant that contains path to image file.
* @return BasicImage class.
*/
BasicImage(const std::string &img_path);
/**
* @brief Just return loader object of image
*
* @return unsigned char image.
*/
unsigned char *get_image_loader();
/**
* @brief Function to get image basic params such a Width, Height, Channels.
*
* @return Integer vector with 3 params.
*/
std::vector<int> get_image_params();
/**
* @brief Just return result of image assigned params.
*
* @return Unsigned char vector with pixels dataset.
*/
std::vector<unsigned char> get_pixels_range();
/**
* @brief Function that saves result of working with image and free space.
*
* @param output_path Constant value of output image path.
*/
void save_result(const std::string &output_path, std::vector<unsigned char> new_pixels);
/**
* @brief Function to free space that contains image data
*/
void free_space();
private:
int w, h, ch;
unsigned char *loaded_image;
std::vector<unsigned char> pixels;
};
/**
* @brief ChannelSwapping is class that realise encode and decode functionality
* of Channel Swapping encrypt algotithm.
*
* @throw TOO_MANY_SENSETIVE_DATA_TO_ENCODE - When encode function got too big
* sensetive data message even image can hold this;
* @throw IMAGE_CAN_NOT_BE_OPEN_TO_DECODE - When image loader on stb_image
* module can not open image file;
*/
class ChannelSwapping
{
public:
/**
* @brief Encode function with Channel Swapping algorithm.
*
* @param img_path Constant that contains path to input image file.
* @param sens_data Sensetive data to encode.
* @param output_path Constant that contains path to output image file, save
* file.
*/
void encode(const std::string &img_path, const std::string &sens_data, const std::string &output_path);
/**
* @brief Decode function with Channel Swapping algorithm.
*
* @param img_path Constant that contains path to input image file.
* @param sens_data_size Lenght of data, that was encoded to image.
*
* @return String value that is result of decoding proccess.
*/
std::string decode(const std::string &img_path, long long int sens_data_size);
/**
* @brief Get size of last encoded data
*/
long long int get_last_encoded_size() const;
private:
long long int last_encoded_size = 0;
};
/**
* @brief MidBitChange is class that realise encode and decode functionality of
* Mid Bit Changing encrypt algotithm.
*
* @throw MESSAGE_TO_LARGE_FOR_IMAGE - When encode function got too big
* sensetive data message even image can hold this;
* @throw FAILED_TO_SAVE_IMAGE - When image loader on stb_image module can not
* save redacted image in encode function;
*/
class MidBitChange
{
public:
/**
* @brief Encode function with Mid Bit Changing algorithm.
*
* @param img_path Constant that contains path to input image file.
* @param sens_data Sensetive data to encode.
* @param output_path Constant that contains path to output image file, save
* file.
*/
void encode(const std::string &img_path, const std::string &sens_data, const std::string &output_path);
/**
* @brief Decode function with Mid Bit Changing algorithm.
*
* @param img_path Constant that contains path to input image file.
* @param sens_data_size Lenght of data, that was encoded to image.
*
* @return String value that is result of decoding proccess.
*/
std::string decode(const std::string &img_path, const size_t sens_data_size);
};
/**
* @brief EOFHiding is class that realise encode and decode functionality of End
* Of File hidding algotithm.
*
* @throw FILE_CAN_NOT_BE_OPEN - Universal error that appears when image file
* can not be open.
* @throw FILE_IS_EMPTY - universal Error that appears when image file is empty.
* @throw SENS_DATA_SIZE_IS_INCCORECT - When sensetive data size is negative or
* equals zero.
*/
class EOFHiding
{
public:
/**
* @brief Hidding(encoding) sensetive data in the end of file (EOF
* Steganography).
*
* @param img_path Path to original(container) image file.
* @param sens_data Sensetive data to hide.
* @param output_path Output file path and name.
*/
void encode(const std::string &img_path, const std::string &sens_data, const std::string &output_path);
/**
* @brief Taking(decoding) sensetive data from th end of file.
*
* @param img_path Path to container image file.
* @param sens_data_size Lenght of hidden sensetive data.
*
* @return String data that is result of decoding.
*/
std::string decode(const std::string &img_path, long long int sens_data_size);
};
#endif