Steganography
A C++ Steganography tool which leverages the LSB and DCT embedding techniques
steganography.hpp
1 /* This file is a part of "Steganography" a C++ steganography tool.
2 
3 Copyright (C) 2019 James Lee <jamesl33info@gmail.com>.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 
18 #include <fstream>
19 #include <iostream>
20 #include <vector>
21 #include <boost/filesystem.hpp>
22 #include <opencv2/core/core.hpp>
23 #include <opencv2/highgui/highgui.hpp>
24 #include "exceptions.hpp"
25 
26 #ifndef STEGANOGRAPHY_HPP
27 #define STEGANOGRAPHY_HPP
28 
33 {
34  public:
40  explicit Steganography(const boost::filesystem::path &image_path)
41  {
42  this->image_path = image_path;
43  this->image = cv::imread(image_path.string(), cv::IMREAD_UNCHANGED);
44 
45  if (!this->image.data)
46  {
47  throw ImageException("Error: Failed to open input image");
48  }
49  }
50 
59  virtual void Encode(const boost::filesystem::path & payload_path) = 0;
60 
67  virtual void Decode() = 0;
68 
69  protected:
75  boost::filesystem::path image_path;
76 
81  cv::Mat image;
82 
89  std::vector<unsigned char> ReadPayload(const boost::filesystem::path & payload_path);
90 
97  void WritePayload(const boost::filesystem::path &payload_path, const std::vector<unsigned char> &payload);
98 
109  template <class T>
110  inline void SetBit(T *target, const int &bit, const int &value)
111  {
112  *target ^= (-(unsigned int)value ^ *target) & (1UL << bit);
113  }
114 
125  template <class T>
126  inline int GetBit(const T &target, const int &bit)
127  {
128  return (target >> bit) & 1UL;
129  }
130 };
131 
132 #endif // STEGANOGRAPHY_HPP
boost::filesystem::path image_path
Definition: steganography.hpp:75
void WritePayload(const boost::filesystem::path &payload_path, const std::vector< unsigned char > &payload)
Definition: steganography.cpp:33
int GetBit(const T &target, const int &bit)
Definition: steganography.hpp:126
Definition: exceptions.hpp:23
void SetBit(T *target, const int &bit, const int &value)
Definition: steganography.hpp:110
Definition: steganography.hpp:32
virtual void Encode(const boost::filesystem::path &payload_path)=0
virtual void Decode()=0
Steganography(const boost::filesystem::path &image_path)
Definition: steganography.hpp:40
cv::Mat image
Definition: steganography.hpp:81
std::vector< unsigned char > ReadPayload(const boost::filesystem::path &payload_path)
Definition: steganography.cpp:20