11#ifndef PAILLIERCONTROLLER_PGM
12#define PAILLIERCONTROLLER_PGM
141 template <
typename T_in,
typename T_out>
156 template <
typename T_in,
typename T_out>
170 template <
typename T_in,
typename T_out>
188 uint16_t *
compressBits(uint16_t *ImgInEnc,
int nb_lignes,
int nb_colonnes);
201 uint16_t *
decompressBits(uint16_t *ImgInEnc,
int nb_lignes,
int nb_colonnes,
int nTailleOriginale);
226 template <
typename T_in,
typename T_out>
258template <
typename T_in,
typename T_out>
263 char cNomImgLue[250];
264 strcpy(cNomImgLue, s_file.c_str());
266 string toErase =
".pgm";
267 size_t pos = s_file.find(
".pgm");
268 s_file.erase(pos, toErase.length());
269 string s_fileNew = s_file +
"_E.pgm";
270 char cNomImgEcriteEnc[250];
271 strcpy(cNomImgEcriteEnc, s_fileNew.c_str());
289 uint64_t x = 0, y = 1;
290 for (
int i = 0; i < nTaille; i++)
295 uint8_t pixel_enc_dec_x = pixel_enc / n;
296 uint8_t pixel_enc_dec_y = pixel_enc % n;
297 ImgOutEnc[x] = pixel_enc_dec_x;
298 ImgOutEnc[y] = pixel_enc_dec_y;
317 for (
int i = 0; i < nTaille; i++)
321 ImgOutEnc[i] = pixel_enc;
332template <
typename T_in,
typename T_out>
336 char cNomImgLue[250];
337 strcpy(cNomImgLue, s_file.c_str());
339 string toErase =
".pgm";
340 size_t pos = s_file.find(
".pgm");
341 s_file.erase(pos, toErase.length());
342 string s_fileNew = s_file +
"_D.pgm";
343 char cNomImgEcriteDec[250];
344 strcpy(cNomImgEcriteDec, s_fileNew.c_str());
347 uint64_t n, lambda, mu;
365 for (
int i = 0; i < nH * (nW / 2); i++)
368 uint8_t pixel_enc_dec_x = ImgIn[x];
369 uint8_t pixel_enc_dec_y = ImgIn[y];
370 pixel = (pixel_enc_dec_x * n) + pixel_enc_dec_y;
374 ImgOutDec[i] =
static_cast<OCTET>(c);
387 for (
int i = 0; i < nTaille; i++)
389 uint16_t pixel = ImgIn[i];
391 ImgOutDec[i] =
static_cast<OCTET>(c);
399template <
typename T_in,
typename T_out>
404 char cNomImgLue[250];
405 strcpy(cNomImgLue, s_file.c_str());
407 string toErase =
".pgm";
408 size_t pos = s_file.find(
".pgm");
409 s_file.erase(pos, toErase.length());
410 string s_fileNew = s_file +
"_E.pgm";
411 char cNomImgEcriteEnc[250];
412 strcpy(cNomImgEcriteEnc, s_fileNew.c_str());
429 for (
int i = 0; i < nTaille; i++)
434 while (pixel_enc % 32 != 0)
439 ImgOutEnc[i] = pixel_enc;
442 uint16_t *ImgOutEncComp =
compressBits(ImgOutEnc, nH, nW);
443 int nbPixelsComp = ceil((
double)(nH * nW * 11) / 16);
444 printf(
"Size : %d\n", nbPixelsComp);
447 int nHComp = dimensionComp.first;
448 int nWComp = dimensionComp.second;
454 delete[] ImgOutEncComp;
457template <
typename T_in,
typename T_out>
461 char cNomImgLue[250];
462 strcpy(cNomImgLue, s_file.c_str());
464 string toErase =
".pgm";
465 size_t pos = s_file.find(
".pgm");
466 s_file.erase(pos, toErase.length());
467 string s_fileNew = s_file +
"_D.pgm";
468 char cNomImgEcriteDec[250];
469 strcpy(cNomImgEcriteDec, s_fileNew.c_str());
471 int nH, nW, nTaille, nHComp, nWComp, nTailleComp;
472 uint64_t n, lambda, mu;
479 nTailleComp = nHComp * nWComp;
480 printf(
"Controller : %d %d\n", nHComp, nWComp);
485 nH = dimesionOriginal.second;
486 nW = dimesionOriginal.first;
493 for (
int i = 0; i < nTaille; i++)
495 uint16_t pixel = ImgInEnc[i];
497 ImgOutDec[i] =
static_cast<OCTET>(c);
Superclass, of Paillier main, that contain common methods between subclasses.
Superclass of Paillier main that contains common methods between subclasses.
Definition PaillierController.hpp:31
PaillierModel * model
Instance of PaillierModel.
Definition PaillierController.hpp:35
Controller for the Paillier cryptosystem applied to PGM images.
Definition PaillierControllerPGM.hpp:38
void printHelp()
Print the man page message.
Definition PaillierControllerPGM.cpp:196
void encryptCompression(bool recropPixels, Paillier< T_in, T_out > paillier)
Encrypt an image using the Paillier cryptosystem with compression.
Definition PaillierControllerPGM.hpp:400
void decrypt(bool distributeOnTwo, Paillier< T_in, T_out > paillier)
Decrypt an image using the Paillier cryptosystem.
Definition PaillierControllerPGM.hpp:333
uint16_t * compressBits(uint16_t *ImgInEnc, int nb_lignes, int nb_colonnes)
This function compresses the encrypted bits of an image.
Definition PaillierControllerPGM.cpp:217
const char * getCFile() const
Getter for the c_file attribute.
Definition PaillierControllerPGM.cpp:34
void setCFile(char *newCFile)
Setter for the c_file attribute.
Definition PaillierControllerPGM.cpp:39
uint16_t * decompressBits(uint16_t *ImgInEnc, int nb_lignes, int nb_colonnes, int nTailleOriginale)
Method to decompress an encrypted 8-bit PGM image.
Definition PaillierControllerPGM.cpp:265
pair< int, int > decomposeDimension(int n)
Method to decompose the dimensions of a compressed image.
Definition PaillierControllerPGM.cpp:309
~PaillierControllerPGM()
Destructor.
Definition PaillierControllerPGM.cpp:24
void init()
Initializes the controller.
Definition PaillierControllerPGM.cpp:26
void checkParameters(char *arg_in[], int size_arg, bool param[])
Check the parameters passed to the program.
Definition PaillierControllerPGM.cpp:46
void encrypt(bool distributeOnTwo, bool recropPixels, Paillier< T_in, T_out > paillier)
Encrypt an image using the Paillier cryptosystem.
Definition PaillierControllerPGM.hpp:259
uint8_t histogramExpansion(OCTET ImgPixel, bool recropPixels)
Perform histogram expansion on an image pixel.
Definition PaillierControllerPGM.cpp:201
PaillierControllerPGM()
Default constructor.
Definition PaillierControllerPGM.cpp:20
void decryptCompression(Paillier< T_in, T_out > paillier)
Method to decrypt an 8-bit PGM image with compression.
Definition PaillierControllerPGM.hpp:458
This class implements the Paillier cryptosystem.
Definition Paillier.hpp:33
T_out paillierEncryption(uint64_t n, uint64_t g, T_in m)
Encrypt a message using Paillier cryptosystem.
Definition Paillier.hpp:407
T_in paillierDecryption(uint64_t n, uint64_t lambda, uint64_t mu, T_out c)
Decrypt a ciphertext using Paillier cryptosystem.
Definition Paillier.hpp:480
PaillierPublicKey getPublicKey() const
Getter function for the public key.
Definition Paillier_model.cpp:32
static PaillierModel * getInstance()
Static function to get the singleton instance of the PaillierModel class.
Definition Paillier_model.hpp:73
PaillierPrivateKey getPrivateKey() const
Getter function for the private key.
Definition Paillier_model.cpp:31
uint64_t getMu() const
Getter method for the mu value.
Definition Paillier_private_key.cpp:41
uint64_t getN() const
Getter method for the n value.
Definition Paillier_private_key.cpp:46
uint64_t getLambda() const
Getter method for the lambda value.
Definition Paillier_private_key.cpp:36
uint64_t getN() const
Getter method for the n value.
Definition Paillier_public_key.cpp:29
uint64_t getG() const
Getter method for the g value.
Definition Paillier_public_key.cpp:34
static void lire_image_p(char nom_image[], OCTET *pt_image, int taille_image)
Reads a PGM image with variable size and stores it in an OCTET array.
Definition image_pgm.cpp:69
static void lire_nb_lignes_colonnes_image_p(char nom_image[], int *nb_lignes, int *nb_colonnes)
Reads the number of lines and columns of a PGM image.
Definition image_pgm.cpp:45
static pair< int, int > read_image_pgm_compressed_and_get_originalDimension(char nom_image[], uint16_t *pt_image)
Reads a compressed PGM image with 16-bit depth and returns the original dimensions.
Definition image_pgm.cpp:233
static void ecrire_image_p(char nom_image[], OCTET *pt_image, int nb_lignes, int nb_colonnes)
Writes a PGM image from an OCTET array with given dimensions.
Definition image_pgm.cpp:21
static void ecrire_image_pgm_variable_size(char nom_image[], uint8_t *pt_image, int nb_lignes, int nb_colonnes, uint8_t max_value)
Writes a PGM image with variable size.
Definition image_pgm.cpp:124
static uint8_t lire_image_pgm_and_get_maxgrey(char nom_image[], uint8_t *pt_image, int taille_image)
Reads a PGM image with 8-bit depth and returns the maximum grey value.
Definition image_pgm.cpp:96
static void write_image_pgm_compressed_variable_size(char nom_image[], uint16_t *pt_image, int nb_lignes, int nb_colonnes, uint16_t max_value, int imgSize, int nHOriginal, int nWOriginal)
Writes a compressed PGM image with variable size and 16-bit depth.
Definition image_pgm.cpp:202
This file contains the declaration of the image_pgm class, which is used to read and write PGM images...
unsigned char OCTET
Definition image_pgm.hpp:21
This file defines the image_portable class, which is a base class for different image formats.
#define allocation_tableau(nom, type, nombre)
Allocate a dynamic array of a given type and size.
Definition image_portable.hpp:27