Code base obscuration (for images) 1.0
It implements different obscuration methods on portable images (.pgm and .ppm)
|
Controller for the Paillier cryptosystem applied to PGM images. More...
#include <PaillierControllerPGM.hpp>
Public Member Functions | |
PaillierControllerPGM () | |
Default constructor. | |
~PaillierControllerPGM () | |
Destructor. | |
void | init () |
Initializes the controller. | |
const char * | getCFile () const |
Getter for the c_file attribute. | |
void | setCFile (char *newCFile) |
Setter for the c_file attribute. | |
void | checkParameters (char *arg_in[], int size_arg, bool param[]) |
Check the parameters passed to the program. | |
void | printHelp () |
Print the man page message. | |
uint8_t | histogramExpansion (OCTET ImgPixel, bool recropPixels) |
Perform histogram expansion on an image pixel. | |
template<typename T_in , typename T_out > | |
void | encrypt (bool distributeOnTwo, bool recropPixels, Paillier< T_in, T_out > paillier) |
Encrypt an image using the Paillier cryptosystem. | |
template<typename T_in , typename T_out > | |
void | decrypt (bool distributeOnTwo, Paillier< T_in, T_out > paillier) |
Decrypt an image using the Paillier cryptosystem. | |
template<typename T_in , typename T_out > | |
void | encryptCompression (bool recropPixels, Paillier< T_in, T_out > paillier) |
Encrypt an image using the Paillier cryptosystem with compression. | |
uint16_t * | compressBits (uint16_t *ImgInEnc, int nb_lignes, int nb_colonnes) |
This function compresses the encrypted bits of an image. | |
uint16_t * | decompressBits (uint16_t *ImgInEnc, int nb_lignes, int nb_colonnes, int nTailleOriginale) |
Method to decompress an encrypted 8-bit PGM image. | |
pair< int, int > | decomposeDimension (int n) |
Method to decompose the dimensions of a compressed image. | |
template<typename T_in , typename T_out > | |
void | decryptCompression (Paillier< T_in, T_out > paillier) |
Method to decrypt an 8-bit PGM image with compression. | |
Public Member Functions inherited from PaillierController | |
PaillierModel * | getModel () |
Gets the model. | |
commandLineInterface * | getView () |
Gets the view. | |
const char * | getCKeyFile () const |
Gets the key file. | |
void | setCKeyFile (char *newCKeyFile) |
Sets the key file. | |
void | generateAndSaveKeyPair () |
Generates and saves the key pair. | |
void | readKeyFile (bool isEncryption) |
Reads the key file. | |
Additional Inherited Members | |
Protected Member Functions inherited from PaillierController | |
bool | endsWith (const std::string &str, const std::string &suffix) |
Checks if the given string ends with the specified suffix. | |
void | convertToLower (char *arg_in[], int size_arg_in) |
Converts the given arguments to lower case. | |
bool | isPrime (uint64_t n, uint64_t i=2) |
Checks if the given number is prime. | |
uint64_t | check_p_q_arg (char *arg) |
Checks if the given argument is a prime number. | |
PaillierController () | |
Constructor for PaillierController. | |
~PaillierController () | |
Destructor for PaillierController. | |
Protected Attributes inherited from PaillierController | |
char * | c_key_file |
Pointer to the key file. | |
PaillierModel * | model = PaillierModel::getInstance() |
Instance of PaillierModel. | |
commandLineInterface * | view = commandLineInterface::getInstance() |
Instance of commandLineInterface. | |
Controller for the Paillier cryptosystem applied to PGM images.
This class is responsible for controlling the Paillier cryptosystem applied to PGM images. It inherits from the PaillierController class and provides additional functionalities specific to PGM images.
PaillierControllerPGM::PaillierControllerPGM | ( | ) |
Default constructor.
This constructor initializes the PaillierControllerPGM object with default values.
PaillierControllerPGM::~PaillierControllerPGM | ( | ) |
Destructor.
This destructor frees the memory allocated by the PaillierControllerPGM object.
void PaillierControllerPGM::checkParameters | ( | char * | arg_in[], |
int | size_arg, | ||
bool | param[] ) |
Check the parameters passed to the program.
This method checks the parameters passed to the program and sets the corresponding attributes of the PaillierControllerPGM object.
arg_in | An array of char pointers containing the arguments passed to the program. |
size_arg | The size of the arg_in array. |
bool | param[] array of flags to be set based on the command line arguments. 0 bool isEncryption = false ; 1 bool useKeys = false; 2 bool distributeOnTwo = false; 3 bool recropPixels = false; 4 bool optimisationLSB = false; |
uint16_t * PaillierControllerPGM::compressBits | ( | uint16_t * | ImgInEnc, |
int | nb_lignes, | ||
int | nb_colonnes ) |
This function compresses the encrypted bits of an image.
The function takes an encrypted image represented as a 2D array of 16-bit unsigned integers, and its dimensions (number of rows and columns). It compresses the encrypted bits of the image using a bit-packing technique, where each 16-bit integer is packed into 11 bits, and returns the compressed image as a new 2D array of 16-bit unsigned integers. The function also updates the number of columns of the compressed image to reflect the new size.
ImgInEnc | A 2D array of 16-bit unsigned integers representing the encrypted image to be compressed. |
nb_lignes | An integer representing the number of rows of the encrypted image. |
nb_colonnes | An integer representing the number of columns of the encrypted image. |
pair< int, int > PaillierControllerPGM::decomposeDimension | ( | int | n | ) |
Method to decompose the dimensions of a compressed image.
This method decomposes the dimensions of a compressed image into its height and width components.
int | n size of the compressed image in pixels. |
uint16_t * PaillierControllerPGM::decompressBits | ( | uint16_t * | ImgInEnc, |
int | nb_lignes, | ||
int | nb_colonnes, | ||
int | nTailleOriginale ) |
Method to decompress an encrypted 8-bit PGM image.
This method decompresses an encrypted 8-bit PGM image that was previously compressed using the encryptCompression method.
uint16_t | *ImgInEnc pointer to the encrypted and compressed image data. |
int | nb_lignes number of rows in the image. |
int | nb_colonnes number of columns in the image. |
void PaillierControllerPGM::decrypt | ( | bool | distributeOnTwo, |
Paillier< T_in, T_out > | paillier ) |
Decrypt an image using the Paillier cryptosystem.
This method decrypts an image using the Paillier cryptosystem and writes the decrypted image to a file.
T_in | The input integer type. |
T_out | The output integer type. |
distributeOnTwo | A bool value indicating whether the encrypted pixels were distributed over two bytes. |
paillier | A Paillier object used for decryption. |
void PaillierControllerPGM::decryptCompression | ( | Paillier< T_in, T_out > | paillier | ) |
Method to decrypt an 8-bit PGM image with compression.
This method decrypts an 8-bit PGM image that was previously encrypted using the encryptCompression method and performs decompression on the decrypted image before writing it to a file.
T_in | input integer type for Paillier cryptosystem. |
T_out | output integer type for Paillier cryptosystem. |
Paillier<T_in,T_out> | paillier instance of the Paillier cryptosystem. |
void PaillierControllerPGM::encrypt | ( | bool | distributeOnTwo, |
bool | recropPixels, | ||
Paillier< T_in, T_out > | paillier ) |
Encrypt an image using the Paillier cryptosystem.
This method encrypts an image using the Paillier cryptosystem and writes the encrypted image to a file.
T_in | The input integer type. |
T_out | The output integer type. |
distributeOnTwo | A bool value indicating whether to distribute the encrypted pixels over two bytes. |
recropPixels | A bool value indicating whether to recrop the pixels. |
paillier | A Paillier object used for encryption. |
void PaillierControllerPGM::encryptCompression | ( | bool | recropPixels, |
Paillier< T_in, T_out > | paillier ) |
Encrypt an image using the Paillier cryptosystem with compression.
This method encrypts an image using the Paillier cryptosystem with compression and writes the encrypted image to a file.
T_in | The input integer type. |
T_out | The output integer type. |
recropPixels | A bool value indicating whether to recrop the pixels. |
paillier | A Paillier object used for encryption. |
const char * PaillierControllerPGM::getCFile | ( | ) | const |
Getter for the c_file attribute.
This method returns the value of the c_file attribute.
uint8_t PaillierControllerPGM::histogramExpansion | ( | OCTET | ImgPixel, |
bool | recropPixels ) |
Perform histogram expansion on an image pixel.
This method performs histogram expansion on an image pixel to increase the dynamic range of the image.
ImgPixel | The input image pixel. |
recropPixels | A bool value indicating whether to recrop the pixels. |
|
virtual |
Initializes the controller.
This is a virtual function that can be overridden in derived classes to perform specific initialization tasks.
Reimplemented from PaillierController.
void PaillierControllerPGM::printHelp | ( | ) |
Print the man page message.
This method prints the help message for the program.
void PaillierControllerPGM::setCFile | ( | char * | newCFile | ) |
Setter for the c_file attribute.
This method sets the value of the c_file attribute.
newCFile | A pointer to the char array containing the new file name. |