219,536pages on
this wiki
Add New Page
Discuss this page0 Share
Programa:         Unidad6Ejercicio20.cpp
Descripción:      Esteganografía (incluye un texto en un BMP).
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
using namespace std;

struct cabeceraBMP {
        char Signature[2];              /* Signatura = "BM"             */
        unsigned int FileSize;          /* Tamaño Fichero               */
        unsigned int Reserved;          /* Reservado                    */
        unsigned int DataOffset;        /* Desplazamiento de los datos  */

struct propiedadesBMP {
        unsigned int size;               /* Header size in bytes      */
        int width, height;               /* Width and height of image */
        unsigned short int planes;       /* Number of colour planes   */
        unsigned short int bits;         /* Bits per pixel            */
        unsigned int compression;        /* Compression type          */
        unsigned int imagesize;          /* Image size in bytes       */
        int xresolution, yresolution;    /* Pixels per meter          */
        unsigned int ncolours;           /* Number of colours         */
        unsigned int importantcolours;   /* Important colours         */

struct pixel {
        unsigned char byteR, byteG, byteB;

void leeCabecera(ifstream &f, cabeceraBMP &c);
void leePropiedades(ifstream &f, propiedadesBMP &p);
void leeImagen(ifstream &f, char *img, unsigned int tam);
void escribeCabecera(ofstream &f, cabeceraBMP &c);
void escribePropiedades(ofstream &f, propiedadesBMP &p);
void escribeImagen(ofstream &f, char *img, unsigned int tam);
void camufla(char *img, char *cad);
int bit(char c,int pos);

int main() {
        cabeceraBMP cBMP;
        propiedadesBMP pBMP;
        char *imagen;
        unsigned int t;
        char nombreOri[80], nombreDes[80], cad[80];

        cout << "Introduzca el nombre del fichero origen ";
        cin >> nombreOri;
        cout << endl << "Introduzca el nombre del fichero destino ";
        cin >> nombreDes;

        ifstream fe(nombreOri, ios::in | ios::binary);
        ofstream fs(nombreDes, ios::out | ios::binary);

        if(fe.is_open() && fs.is_open())
                imagen = new char[pBMP.imagesize];

                cout << "Introduzca una cadena ";
                cin >> cad;
                camufla(imagen, cad);


                cout << "Error: El fichero no existe ";

void leeCabecera(ifstream &f, cabeceraBMP &c)
{<char*>(&c.Signature[0]), sizeof(c.Signature[0]));<char*>(&c.Signature[1]), sizeof(c.Signature[1]));<char*>(&c.FileSize), sizeof(c.FileSize));<char*>(&c.Reserved), sizeof(c.Reserved));<char*>(&c.DataOffset), sizeof(c.DataOffset));

void leePropiedades(ifstream &f, propiedadesBMP &p)
{<char*>(&p.size), sizeof(p.size));<char*>(&p.width), sizeof(p.width));<char*>(&p.height), sizeof(p.height));<char*>(&p.planes), sizeof(p.planes));<char*>(&p.bits), sizeof(p.bits));<char*>(&p.compression), sizeof(p.compression));<char*>(&p.imagesize), sizeof(p.imagesize));<char*>(&p.xresolution), sizeof(p.xresolution));<char*>(&p.yresolution), sizeof(p.yresolution));<char*>(&p.ncolours), sizeof(p.ncolours));<char*>(&p.importantcolours), sizeof(p.importantcolours));
        if(p.imagesize == 0) // La imagen esta comprimida
                p.imagesize = p.width * p.height * p.bits / 8;

void leeImagen(ifstream &f, char *img, unsigned int tam)
        for(unsigned int i = 0; i < tam; i++)
      <char*>(img + i), sizeof(*img));

void escribeCabecera(ofstream &f, cabeceraBMP &c)
        f.write(reinterpret_cast<char*>(&c.Signature[0]), sizeof(c.Signature[0]));
        f.write(reinterpret_cast<char*>(&c.Signature[1]), sizeof(c.Signature[1]));
        f.write(reinterpret_cast<char*>(&c.FileSize), sizeof(c.FileSize));
        f.write(reinterpret_cast<char*>(&c.Reserved), sizeof(c.Reserved));
        f.write(reinterpret_cast<char*>(&c.DataOffset), sizeof(c.DataOffset));

void escribePropiedades(ofstream &f, propiedadesBMP &p)
        f.write(reinterpret_cast<char*>(&p.size), sizeof(p.size));
        f.write(reinterpret_cast<char*>(&p.width), sizeof(p.width));
        f.write(reinterpret_cast<char*>(&p.height), sizeof(p.height));
        f.write(reinterpret_cast<char*>(&p.planes), sizeof(p.planes));
        f.write(reinterpret_cast<char*>(&p.bits), sizeof(p.bits));
        f.write(reinterpret_cast<char*>(&p.compression), sizeof(p.compression));
        f.write(reinterpret_cast<char*>(&p.imagesize), sizeof(p.imagesize));
        f.write(reinterpret_cast<char*>(&p.xresolution), sizeof(p.xresolution));
        f.write(reinterpret_cast<char*>(&p.yresolution), sizeof(p.yresolution));
        f.write(reinterpret_cast<char*>(&p.ncolours), sizeof(p.ncolours));
        f.write(reinterpret_cast<char*>(&p.importantcolours), sizeof(p.importantcolours));

void escribeImagen(ofstream &f, char *img, unsigned int tam)
        for(unsigned int i = 0; i < tam; i++)
                f.write(reinterpret_cast<char*>(img + i), sizeof(*img));

int bit(char c,int pos)
    int res;
    pos = pow(2, pos);
    res = c & pos ? 1 : 0;
    return res;

void camufla(char *img, char *cad)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random wikia