Code base obscuration (for images) 1.0
It implements different obscuration methods on portable images (.pgm and .ppm)
Loading...
Searching...
No Matches
PaillierControllerPGM Class Reference

Controller for the Paillier cryptosystem applied to PGM images. More...

#include <PaillierControllerPGM.hpp>

Inheritance diagram for PaillierControllerPGM:
Collaboration diagram for PaillierControllerPGM:

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
PaillierModelgetModel ()
 Gets the model.
 
commandLineInterfacegetView ()
 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.
 
PaillierModelmodel = PaillierModel::getInstance()
 Instance of PaillierModel.
 
commandLineInterfaceview = commandLineInterface::getInstance()
 Instance of commandLineInterface.
 

Detailed Description

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.

Author
Katia Auxilien
Date
29 May 2024, 13:55:00

Constructor & Destructor Documentation

◆ PaillierControllerPGM()

PaillierControllerPGM::PaillierControllerPGM ( )

Default constructor.

This constructor initializes the PaillierControllerPGM object with default values.

Author
Katia Auxilien
Date
29 May 2024, 13:55:00

◆ ~PaillierControllerPGM()

PaillierControllerPGM::~PaillierControllerPGM ( )

Destructor.

This destructor frees the memory allocated by the PaillierControllerPGM object.

Author
Katia Auxilien
Date
29 May 2024, 13:55:00

Member Function Documentation

◆ checkParameters()

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.

Parameters
arg_inAn array of char pointers containing the arguments passed to the program.
size_argThe size of the arg_in array.
boolparam[] 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;
Authors
Katia Auxilien
Date
29 May 2024, 13:55:00

◆ compressBits()

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.

Parameters
ImgInEncA 2D array of 16-bit unsigned integers representing the encrypted image to be compressed.
nb_lignesAn integer representing the number of rows of the encrypted image.
nb_colonnesAn integer representing the number of columns of the encrypted image.
Returns
A 2D array of 16-bit unsigned integers representing the compressed encrypted image.
Authors
Katia Auxilien
Date
29 May 2024, 13:55:00

◆ decomposeDimension()

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.

Parameters
intn size of the compressed image in pixels.
Returns
pair<int, int> pair containing the height and width of the decomposed image.
Author
Katia Auxilien
Date
29 mai 2024, 13:55:00

◆ decompressBits()

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.

Parameters
uint16_t*ImgInEnc pointer to the encrypted and compressed image data.
intnb_lignes number of rows in the image.
intnb_colonnes number of columns in the image.
Returns
uint16_t* pointer to the decompressed image data.
Author
Katia Auxilien
Date
29 mai 2024, 13:55:00

◆ decrypt()

template<typename T_in , typename T_out >
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.

Template Parameters
T_inThe input integer type.
T_outThe output integer type.
Parameters
distributeOnTwoA bool value indicating whether the encrypted pixels were distributed over two bytes.
paillierA Paillier object used for decryption.
Author
Katia Auxilien
Date
29 May 2024, 13:55:00

◆ decryptCompression()

template<typename T_in , typename T_out >
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.

Template Parameters
T_ininput integer type for Paillier cryptosystem.
T_outoutput integer type for Paillier cryptosystem.
Parameters
Paillier<T_in,T_out>paillier instance of the Paillier cryptosystem.
Author
Katia Auxilien
Date
29 mai 2024, 13:55:00

◆ encrypt()

template<typename T_in , typename T_out >
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.

Template Parameters
T_inThe input integer type.
T_outThe output integer type.
Parameters
distributeOnTwoA bool value indicating whether to distribute the encrypted pixels over two bytes.
recropPixelsA bool value indicating whether to recrop the pixels.
paillierA Paillier object used for encryption.
Author
Katia Auxilien
Date
29 May 2024, 13:55:00

◆ encryptCompression()

template<typename T_in , typename T_out >
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.

Template Parameters
T_inThe input integer type.
T_outThe output integer type.
Parameters
recropPixelsA bool value indicating whether to recrop the pixels.
paillierA Paillier object used for encryption.
Author
Katia Auxilien
Date
29 May 2024, 13:55:00

◆ getCFile()

const char * PaillierControllerPGM::getCFile ( ) const

Getter for the c_file attribute.

This method returns the value of the c_file attribute.

Returns
A constant pointer to the char array containing the file name.
Author
Katia Auxilien
Date
29 May 2024, 13:55:00

◆ histogramExpansion()

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.

Parameters
ImgPixelThe input image pixel.
recropPixelsA bool value indicating whether to recrop the pixels.
Returns
The histogram-expanded image pixel.
Author
Katia Auxilien
Date
29 May 2024, 13:55:00

◆ init()

void PaillierControllerPGM::init ( )
virtual

Initializes the controller.

This is a virtual function that can be overridden in derived classes to perform specific initialization tasks.

Author
Katia Auxilien
Date
30 April 2024

Reimplemented from PaillierController.

◆ printHelp()

void PaillierControllerPGM::printHelp ( )

Print the man page message.

This method prints the help message for the program.

Author
Katia Auxilien
Date
29 May 2024, 13:55:00

◆ setCFile()

void PaillierControllerPGM::setCFile ( char * newCFile)

Setter for the c_file attribute.

This method sets the value of the c_file attribute.

Parameters
newCFileA pointer to the char array containing the new file name.
Author
Katia Auxilien
Date
29 May 2024, 13:55:00