Beispiel #1
0
/** \brief Checks if the given Pixel is empty (not used). It is empty, if least significant bits are all 0.
 * \param pixel const Pixel& the pixel that should be checked
 * \return bool true if pixel is not used until now, else false
 */
bool SteganoHide::isPixelEmpty(const Pixel &pixel) {
    Magick::ColorRGB pixelColor = this->steganoImage.pixelColor(pixel.x, pixel.y);

    const unsigned char redLeastSignificantBit = convert16BitTo8BitRGB(pixelColor.redQuantum()) % 10;
    const unsigned char greenLeastSignificantBit = convert16BitTo8BitRGB(pixelColor.greenQuantum()) % 10;
    const unsigned char blueLeastSignificantBit = convert16BitTo8BitRGB(pixelColor.blueQuantum()) % 10;
  //  std::cout << (int)redLeastSignificantBit << ":" << (int)greenLeastSignificantBit << ":" << (int)blueLeastSignificantBit << std::endl;

    return (redLeastSignificantBit == 5 && greenLeastSignificantBit == 5 && blueLeastSignificantBit == 5);
}
Beispiel #2
0
/** \brief Draw a finish pixel at the specified position. The finishpixel has at the least-significant bit of their rgb-value r: 3, g: 0, b: 0
 *
 * \param &pixel const Pixel a pixel-struct describing the pixel-position where the finish-pixel should be set.
 */
void SteganoHide::drawFinishPixel(const Pixel &pixel) {
    Magick::ColorRGB pixelColor = this->steganoImage.pixelColor(pixel.x, pixel.y);

    RGB pixelRGB(convert16BitTo8BitRGB(pixelColor.redQuantum()),
                 convert16BitTo8BitRGB(pixelColor.greenQuantum()),
                 convert16BitTo8BitRGB(pixelColor.blueQuantum()));

    pixelRGB.red = (pixelRGB.red - (pixelRGB.red % 10)) + 3;
    pixelRGB.green = pixelRGB.green - (pixelRGB.green % 10);
    pixelRGB.blue = pixelRGB.blue - (pixelRGB.blue % 10);

    this->steganoImage.pixelColor(pixel.x, pixel.y, Magick::ColorRGB(pixelRGB.toString()));
}
Beispiel #3
0
/** \brief Normalize the loaded image.(set all least significant bits of all RGB-Values to 0).
 * This change takes effect only while editing the picture. In the exported image, all pixel have their old value (except the edited ones).
 * This is needed to differentiate between edited and not edited pixel.
 */
void SteganoHide::normalizeImage() {
    for(unsigned int xValue = 0; xValue < this->xResolution; xValue++) {
        for(unsigned int yValue = 0; yValue < this->yResolution; yValue++) {
            Magick::ColorRGB curPixelColor = this->steganoImage.pixelColor(xValue, yValue);


            RGB curPixelRGB(convert16BitTo8BitRGB(curPixelColor.redQuantum()),
                            convert16BitTo8BitRGB(curPixelColor.greenQuantum()),
                            convert16BitTo8BitRGB(curPixelColor.blueQuantum()));
            RGB curPixelRoundedRGB(curPixelRGB.red - (curPixelRGB.red % 10) + 5,
                                   curPixelRGB.green - (curPixelRGB.green % 10) + 5,
                                   curPixelRGB.blue - (curPixelRGB.blue % 10) + 5);
            this->steganoImage.pixelColor(xValue, yValue, Magick::ColorRGB(curPixelRoundedRGB.toString()));
        }
        this->doneBytes += this->yResolution;
    }
}
Beispiel #4
0
 // TODO: handle wrong input
bool SteganoHide::hideNumberInMagickColorRGB(const unsigned short &smallNumber, Magick::ColorRGB &color) {
    RGB pixelRGB(convert16BitTo8BitRGB(color.redQuantum()),
                 convert16BitTo8BitRGB(color.greenQuantum()),
                 convert16BitTo8BitRGB(color.blueQuantum()));

    RGB roundedRGB;
    roundedRGB.red = pixelRGB.red - (pixelRGB.red % 10);
    roundedRGB.green = pixelRGB.green - (pixelRGB.green % 10);
    roundedRGB.blue = pixelRGB.blue - (pixelRGB.blue % 10);

    unsigned char mostSignificantBit = std::floor(smallNumber / 100);
    unsigned char middleSigificantBit = std::floor(smallNumber % 100 / 10);
    unsigned char leastSignificantBit = smallNumber % 10;

   /* if(mostSignificantBit > 5 || middleSigificantBit > 5 || leastSignificantBit > 5) {
        throw hideNumber2Big;
    }*/

    // there was an overflow: eg. roundedRGB.blue = 250 and leastSignificantLetterBit = 8 => 258 => 2
    // This way to check overflow is possible, because *SignificantLetterBit >= 0
    if(roundedRGB.green + middleSigificantBit > 255) {
        return false;
    }
    if(roundedRGB.blue + leastSignificantBit > 255) {
        return false;
    }



   // std::cout << (int)roundedRGB.blue << "+" << (int)leastSignificantBit << "=";
    roundedRGB.red += mostSignificantBit;
    roundedRGB.green += middleSigificantBit;
    roundedRGB.blue += leastSignificantBit;
    //std::cout << (int)roundedRGB.blue << std::endl;

    color = Magick::ColorRGB(roundedRGB.toString());
    return true;
}
Beispiel #5
0
// TODO: shorten this method and outsource some inner methods and add header comment
std::stringstream SteganoExpose::unhidePhrase(const std::string &password)
{
    if(!this->steganoImage.isValid())
    {
        throw SteganoException::UnhideFileNotSpecified();
    }

    this->exposeFinished = false;
    Chunk hiddenChunk("vaPh");
    std::cout << this->steganoImage.baseFilename() << std::endl;
    PrivateChunk privChunk(this->steganoImage.baseFilename(), "./omg.png");
    char *chunkData = new char[privChunk.getChunkSize(hiddenChunk)];
    privChunk.readChunk(hiddenChunk, chunkData);
    commentReaderStream.str(chunkData);
    calculateNextShift();

    Pixel curPixel(0, 0);
    std::stringstream returnPhrase;
    for(unsigned int runCounter = 0; ; runCounter++)
    {
        curPixel.x = 0;
        curPixel.y = 0;
        int_least64_t steps = quadraticSondation(runCounter, this->xResolution * this->yResolution);
        //   std::cout << "Push by" << steps << std::endl;
        pushPixelBy(curPixel, steps);
        //  std::cout << curPixel.x << ":" << curPixel.y << std::endl;

        if(runCounter == shiftIndex)
        {
            pushPixelBy(curPixel, shiftAmount);
            calculateNextShift();
        }
        // std::cout << curPixel.x << "::" << curPixel.y << std::endl;
        Magick::ColorRGB curPixelColor = this->steganoImage.pixelColor(curPixel.x, curPixel.y);

        unsigned char redLeastSignificantBit = convert16BitTo8BitRGB(curPixelColor.redQuantum()) % 10;
        unsigned char greenLeastSignificantBit = convert16BitTo8BitRGB(curPixelColor.greenQuantum()) % 10;
        unsigned char blueLeastSignificantBit = convert16BitTo8BitRGB(curPixelColor.blueQuantum()) % 10;

        // there was an overflow at the pixel color. we need to handle it special.
        unsigned char decryptedChar = 0;
        if(redLeastSignificantBit == 4)
        {
            decryptedChar += greenLeastSignificantBit * 10;
            decryptedChar += blueLeastSignificantBit;
            incrementPixel(curPixel);

            curPixelColor = this->steganoImage.pixelColor(curPixel.x, curPixel.y);
            redLeastSignificantBit = convert16BitTo8BitRGB(curPixelColor.redQuantum()) % 10;
            greenLeastSignificantBit = convert16BitTo8BitRGB(curPixelColor.greenQuantum()) % 10;
            blueLeastSignificantBit = convert16BitTo8BitRGB(curPixelColor.blueQuantum()) % 10;
            decryptedChar += redLeastSignificantBit * 100;
            decryptedChar += greenLeastSignificantBit * 10;
            decryptedChar += blueLeastSignificantBit;
        }
        else
        {
            decryptedChar = redLeastSignificantBit * 100;
            decryptedChar += greenLeastSignificantBit * 10;
            decryptedChar += blueLeastSignificantBit;
        }
        if(isFinishPixel(curPixel))
        {
            break;
        }
        returnPhrase << decryptedChar;
    }
    this->exposeFinished = true;
    return returnPhrase;
}