1. 程式人生 > >JPEG圖片的隱寫

JPEG圖片的隱寫

兩個星期前就想要完成基於JPEG-Jsteg演算法的圖片隱寫,然而兩個星期過去,平時事情很多,關鍵這個東西網上相關資料很少,成型的程式碼更是幾乎沒有,所以這裡先記錄一個基於圖片結束標誌符的隱寫(。。。),希望有操作過DCT係數(c/c++語言)的大佬可以留言或者發我郵箱[email protected]

#include<iostream>
#include<fstream>
using namespace std;
class picture
{
    private:
        ifstream ifile_picture;
        ifstream ifile_txt;
ofstream ofile_picture; ofstream ofile_txt; int length_ifile_picture,length_ifile_txt; char name_ifile_picture[50], name_ifile_txt[50], name_ofile_picture[50],name_ofile_txt[50]; public: void Open(ifstream &ifile,char *name,int &length); void M
(); void m(); }; void picture::Open(ifstream &ifile,char *name,int &length) { ifile.open(name,ios::binary|ios::in); if (!ifile) { cout<<"Open "<<name<<" failed!"<<endl; return ; } ifile.seekg(0, ios::end); length = ifile.
tellg(); ifile.seekg(0, ios::beg); } void picture::M() { char *str; cout<<"請輸入圖片名(需要加字尾名):"<<endl; cin>>this->name_ifile_picture; Open(this->ifile_picture, this->name_ifile_picture, this->length_ifile_picture); str = new char[length_ifile_picture + 5]; this->ifile_picture.read(str, this->length_ifile_picture); while(1) { if(str[this->length_ifile_picture-2]==-1 && str[this->length_ifile_picture-1]==-39) break; //影象結束標誌 FF D9 else this->length_ifile_picture--; } cout<<"請輸入修改後的圖片名(需要加字尾名):"<<endl; cin>>this->name_ofile_picture; this->ofile_picture.open(this->name_ofile_picture,ios::binary|ios::out); if (!this->ofile_picture) { cout<<"Open "<<this->name_ofile_picture<<" failed!"<<endl; return ; } this->ofile_picture.write(str, this->length_ifile_picture); this->ifile_picture.close(); delete []str; cout<<"請輸入文字名(需要加字尾名):"<<endl; cin>>this->name_ifile_txt; Open(this->ifile_txt, this->name_ifile_txt, this->length_ifile_txt); str = new char[length_ifile_txt + 5]; this->ifile_txt.read(str, this->length_ifile_txt); this->ofile_picture.write(str, this->length_ifile_txt); this->ifile_txt.close(); this->ofile_picture.close(); delete []str; cout<<"成功!"<<endl; } void picture::m() //資訊提取 { char *str; cout<<"請輸入圖片名(需要加字尾名):"<<endl; cin>>this->name_ifile_picture; Open(this->ifile_picture, this->name_ifile_picture, this->length_ifile_picture); str = new char[length_ifile_picture + 5]; this->ifile_picture.read(str, this->length_ifile_picture); int l=this->length_ifile_picture; while(1) { if(str[l-2]==-1 && str[l-1] == -39) break; //影象結束標誌 FF D9 else l--; } cout<<"請輸入資訊提取存入文字名(需要加字尾名):"<<endl; cin>>this->name_ofile_txt; this->ofile_txt.open(this->name_ofile_txt,ios::binary|ios::out); if (!this->ofile_picture) { cout<<"Open "<<this->name_ofile_txt<<" failed!"<<endl; return ; } this->ofile_txt.write(str+l, this->length_ifile_picture-l); this->ifile_picture.close(); this->ofile_txt.close(); delete []str; cout<<"成功!"<<endl; } int main() { picture a; a.M() ; a.m() ; return 0; }