Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by TheNoName ( 16 years ago )
/*  QuickLBS is steganography program for hiding files
    Copyright (C) 2010  Aleksandrs Himulya and Anton Tarasov

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#include <stdio.h>

// тип, описывающий байтовый массив
typedef struct bytearray_struct{
        char* array;
        long size;
} bytearray;


// функция принимает имя файла и выдает его содержимое в виде байтового массива
bytearray* loadFile&#40;char* file_path&#41;
{
        FILE* f = fopen&#40;file_path, "rb"&#41;;
         
        if ( f == NULL )
                return NULL;

        // узнаем размер
        fseek(f, 0, SEEK_END);
        long size = ftell(f);
        fseek(f, 0, SEEK_SET);

        // создаем байтовый массив
        bytearray* ba = new bytearray;
        ba->array = new char[size];
        ba->size = size;

        // считываем данные из файла и закрываем его
        fread(ba->array, size, 1, f);
        fclose(f);

        // возвращаем байтовый массив
        return ba;
}

// сохраняет байтовый массив в файл
int saveToFile&#40;char* file_path, bytearray* ba&#41;
{
        FILE* f = fopen&#40;file_path, "wb+"&#41;;
        if ( f == NULL )
                return 1;
        fwrite(ba->array, ba->size, 1, f);
        fclose(f);
        return 0;
}

bool getBit(char byte, char n)
{
    // let's count bits in this way: 87654321
    char mask = 1;
    mask = mask << (n - 1);
    char result = mask & byte;
    return bool(result);
}


char setBit(char byte, char n, bool bit)
{
    char mask = 1;
    mask = mask << (n -1);
    byte = byte | mask;
    return byte;
}

// упаковка данных
bytearray* packFile&#40;bytearray* pic, bytearray* secret, int n&#41;
{
        int i = 0;  // счетчик массива secret
        int j = 1024; // счетчик массива pic      
        while ( i < secret->size )
        {
                for(int k = 1; k <= n; k++)
                {
                        bool bit = getBit(  secret->array[i], i );                      
                        pic->array[j] = setBit( pic->array[j], k, bit );
                        i++;
                }
                j++;
                if (j  >= pic->size)
                        printf("ОШИБКА! Вышли за границы массиваn");
        }
        return pic;
}

int enter_num_bit(void)//задание номера используемого бита в байте (от 4 до 8)
{
        char input;
        int num;
        printf("Please enter number of bit which will replace [4/5/6/7/8]: ");
        scanf("", &input;);
        if (input == 8)
                num = 1;
        else if (input == 7)
                num = 2;
        else if (input == 6)
                num = 3;
        else if (input == 5)
                num = 4;
        else if (input == 4)
                num = 5;
        else
                printf("Wrong numbern");
        printf("num_debugn");
        return num;
}

void prepare_unpack (void)
{
        char* path_file_stg;
        char* path_file_ext;
        printf("Enter path to stegofile:");
        scanf("%s", &path;_file_stg);
        bytearray* ab_stg = loadFile&#40;(char*&#41;&path;_file_stg);
        if (ab_stg == NULL)
                printf("File not read: %s", path_file_stg);//открытие стегофайла
        printf("Enter path there will create hide file:");
        scanf("%s", &path;_file_ext);
//        int err = saveToFile&#40;(char*&#41;&path;_file_ext);
//        if (err != 0)
//                printf("File not write: %s", path_file_ext);//открытие стегофайла
        return;
}

void prepare_pack (void)
{
        char path_file_sec;
        char path_file_open[100];
        char path_file_stg;
        printf("Enter path to open file:");
        scanf("%s", &path;_file_open);
        bytearray* ba_open = loadFile&#40;(char*&#41;&path;_file_open);
        if (ba_open == NULL)
                printf("File not read: %sn", path_file_open);//перенос информации из файла изображения в структуру
        printf("Enter path to secret file:");
        scanf("%s", &path;_file_sec);
        bytearray* ba_secret = loadFile&#40;(char*&#41;&path;_file_sec);
        if (ba_secret == NULL)
                printf("File not read: %sn", path_file_sec);//перенос информации из файла со скрытой информацией в структуру
        printf("Enter path there will create new stego file:");
        scanf("%s", &path;_file_stg);
        printf("debug0n");
        int n;
        n = enter_num_bit();
        if(((ba_open->size - 1024)*n - ba_secret->size*8) > 0)
        {;}
        else
        {
                printf("Secret file too large or open file too smalln");
        }
        printf("debug1n");
        bytearray* ba_stg = packFile&#40;ba_open, ba_secret, n&#41;;
        printf("debug2n");
        int err = saveToFile&#40;(char*&#41;&path;_file_stg, ba_stg);
        if (err != 0)
                printf("File not save: %s", path_file_stg);//запись готового стегофайла
        return;
}

int main()
{
        char com;
        while (com != 'q')
        {
                printf("This is program for creating and extracting stegofiles[c(create)/e(extract)/q(quit)]:");
                scanf("", &com;);
                switch(com)//переход к...
                {
                        case 'c': prepare_pack();//созданию стегофайла
                        case 'e': prepare_unpack();//извлечению информации из стегофайла
                        case 'q': return 0;//выход
                        default:  printf ("Wrong commandn");//ошибка в случае неверной команды
                }
        }
        return 0;
}

 

Revise this Paste

Your Name: Code Language: