Steganography hauv GIF

Taw qhia

Txais tos.
Tsis ntev tas los no, thaum kuv tab tom kawm hauv tsev kawm ntawv qib siab, muaj kev kawm hauv kev qhuab qhia "Software method of information security." Txoj haujlwm xav kom peb tsim ib qho kev pab cuam uas kos cov lus hauv GIF cov ntaub ntawv. Kuv txiav txim siab ua nws hauv Java.

Hauv tsab xov xwm no kuv yuav piav qhia qee cov ntsiab lus theoretical, nrog rau qhov kev pab cuam me me no tau tsim li cas.

Theoretical ib feem

GIF hom ntawv

GIF (Graphics Interchange Format - ib hom kev sib pauv duab) yog ib hom kev khaws cov duab nraaj, muaj peev xwm khaws cia cov ntaub ntawv compressed yam tsis muaj kev poob zoo hauv hom txog li 256 xim. Hom ntawv no tau tsim nyob rau xyoo 1987 (GIF87a) los ntawm CompuServe rau kev xa cov duab raster hla cov tes hauj lwm. Xyoo 1989, cov hom ntawv tau hloov kho (GIF89a), kev txhawb nqa rau pob tshab thiab cov yeeb yaj kiab ntxiv.

GIF cov ntaub ntawv muaj cov qauv thaiv. Cov blocks no ib txwm muaj qhov ntev ntev (lossis nws nyob ntawm qee tus chij), yog li nws yuav luag tsis tuaj yeem ua yuam kev txog qhov twg txhua qhov thaiv nyob. Cov qauv ntawm qhov yooj yim tshaj plaws uas tsis yog animated GIF duab hauv GIF89a hom:

Steganography hauv GIF

Ntawm tag nrho cov blocks ntawm cov qauv, nyob rau hauv cov ntaub ntawv no peb yuav xav nyob rau hauv lub ntiaj teb no palette thaiv thiab tsis muaj lub luag hauj lwm rau lub palette:

  • CT - muaj lub ntiaj teb palette. Yog tias tus chij no tau teeb tsa, lub ntiaj teb palette yuav tsum pib tam sim ntawd tom qab lub logical screen kov.
  • Size - palette loj thiab tus naj npawb ntawm cov xim hauv daim duab. Tus nqi rau qhov parameter no:

loj
Tus naj npawb ntawm cov xim
Palette loj, bytes

7
256
768

6
128
384

5
64
192

4
32
96

3
16
48

2
8
24

1
4
12

0
2
6

Txoj kev encryption

Cov hauv qab no yuav raug siv los encrypt cov lus hauv cov ntaub ntawv duab:

  • LSB (tseem ceeb tshaj me ntsis) txoj kev
  • Palette ntxiv txoj kev

LSB method - ib txoj hauv kev ntawm steganography. Nws muaj kev hloov cov khoom tseem ceeb kawg hauv lub thawv (hauv peb rooj plaub, lub ntiaj teb palette bytes) nrog cov khoom ntawm cov lus zais.

Qhov kev zov me nyuam yuav siv ob qhov kawg hauv lub ntiaj teb palette bytes ua ib feem ntawm txoj kev no. Qhov no txhais tau hais tias rau 24-ntsis duab, qhov twg cov xim palette yog peb bytes rau liab, xiav, thiab ntsuab, tom qab kos ib cov lus rau hauv nws, txhua xim yuav hloov los ntawm qhov siab tshaj plaws ntawm 3/255 gradations. Xws li kev hloov pauv, thawj zaug, yuav pom tsis pom lossis nyuaj rau pom rau tib neeg lub qhov muag, thiab qhov thib ob, nws yuav tsis pom ntawm cov ntaub ntawv tsis zoo tso tawm.

Tus nqi ntawm cov ntaub ntawv yuav ncaj qha nyob ntawm seb qhov loj ntawm cov duab palette. Txij li thaum qhov siab tshaj plaws ntawm cov palette yog 256 xim, thiab yog tias ob lub ntsiab lus tau sau rau hauv cov khoom ntawm txhua xim, ces qhov siab tshaj plaws cov lus ntev (nrog rau qhov siab tshaj plaws palette hauv daim duab) yog 192 bytes. Thaum cov lus tau kos rau hauv daim duab, cov ntaub ntawv loj tsis hloov.

Palette expansion method, uas tsuas yog ua haujlwm rau GIF qauv. Nws yuav ua tau zoo tshaj plaws ntawm cov duab nrog me me palette. Nws cov ntsiab lus yog tias nws nce qhov loj ntawm lub palette, yog li muab qhov chaw ntxiv rau kev sau cov bytes tsim nyog rau qhov chaw ntawm cov xim bytes. Yog tias peb xav tias qhov tsawg kawg nkaus ntawm cov palette yog 2 xim (6 bytes), ces qhov siab tshaj plaws ntawm cov lus kos tuaj yeem yog 256 Γ— 3–6 = 762 bytes. Qhov tsis zoo yog tsis muaj kev ruaj ntseg cryptographic; cov lus kos tuaj yeem nyeem tau siv cov ntawv nyeem yog tias cov lus tsis raug rau kev encryption ntxiv.

Cov tswv yim nruab nrab

Kev tsim qauv

Tag nrho cov cuab yeej tsim nyog rau kev siv encryption thiab decryption algorithms yuav suav nrog hauv pob com.tsarik.steganography. Cov pob no suav nrog lub interface Encryptor nrog txoj kev encrypt ΠΈ decrypt, Chav kawm Binary, uas muab lub peev xwm ua haujlwm nrog me ntsis arrays, nrog rau cov chav kawm tshwj xeeb UnableToEncryptException ΠΈ UnableToDecryptException, uas yuav tsum tau siv nyob rau hauv txoj kev interface Encryptor nyob rau hauv cov ntaub ntawv ntawm encoding thiab decoding yuam kev feem.

Cov txheej txheem tseem ceeb pob com.tsarik.programs.gifed yuav suav nrog cov chav kawm runnable nrog txoj kev zoo li qub main, cia koj khiav qhov kev pab cuam; ib chav kawm uas khaws cov txheej txheem kev ua haujlwm; thiab pob khoom nrog rau lwm cov chav kawm.

Kev siv cov algorithms lawv tus kheej yuav raug nthuav tawm hauv pob com.tsarik.programs.gifed.gif chav kawm GIFEncryptorByLSBMethod ΠΈ GIFEncryptorByPaletteExtensionMethod. Ob chav kawm no yuav siv lub interface Encryptor.

Raws li cov qauv ntawm GIF hom, koj tuaj yeem tsim cov algorithm dav dav rau kev qhia cov lus rau hauv cov duab palette:

Steganography hauv GIF

Txhawm rau txiav txim siab txog qhov muaj cov lus hauv ib daim duab, nws yog ib qho tsim nyog yuav tsum tau ntxiv ib ntu ntawm cov khoom mus rau qhov pib ntawm cov lus, uas tus decoder nyeem ua ntej thiab kuaj xyuas qhov tseeb. Yog tias nws tsis sib xws, nws raug suav hais tias tsis muaj cov lus zais hauv daim duab. Tom ntej no koj yuav tsum qhia qhov ntev ntawm cov lus. Ces cov ntawv ntawm cov lus nws tus kheej.

Daim duab duab ntawm tag nrho daim ntawv thov:

Steganography hauv GIF

Kev ua raws li qhov program

Kev siv tag nrho cov kev pab cuam yuav muab faib ua ob yam: kev siv interface encryption thiab decryption txoj kev Encryptor, hauv chav kawm GIFEncryptorByLSBMethod ΠΈ GIFEncryptorByPaletteExtensionMethod, thiab kev siv ntawm tus neeg siv interface.

Xav txog chav kawm GIFEncryptorByLSBMethod.

Steganography hauv GIF

teb firstLSBit ΠΈ secondLSBit muaj cov lej ntawm cov khoom ntawm txhua byte ntawm cov duab uas cov lus yuav tsum tau nkag mus thiab los ntawm qhov twg cov lus yuav tsum tau nyeem. Teb checkSequence khaws ib daim tshev me ntsis kom paub meej txog cov lus kos. Txoj kev zoo li qub getEncryptingFileParameters rov qab tsis tau ntawm cov ntaub ntawv teev tseg thiab cov yam ntxwv ntawm cov lus muaj peev xwm.

Txoj kev algorithm encrypt chav kawm GIFEncryptorByLSBMethod:

Steganography hauv GIF

Thiab nws code:

@Override
public void encrypt(File in, File out, String text) throws UnableToEncodeException, NullPointerException, IOException {
	if (in == null) {
		throw new NullPointerException("Input file is null");
	}
	if (out == null) {
		throw new NullPointerException("Output file is null");
	}
	if (text == null) {
		throw new NullPointerException("Text is null");
	}
	
	// read bytes from input file
	byte[] bytes = new byte[(int)in.length()];
	InputStream is = new FileInputStream(in);
	is.read(bytes);
	is.close();
	
	// check format
	if (!(new String(bytes, 0, 6)).equals("GIF89a")) {
		throw new UnableToEncodeException("Input file has wrong GIF format");
	}
	
	// read palette size property from first three bits in the 10-th byte from the file
	byte[] b10 = Binary.toBitArray(bytes[10]);
	byte bsize = Binary.toByte(new byte[] {b10[0], b10[1], b10[2]});
	
	// calculate color count and possible message length
	int bOrigColorCount = (int)Math.pow(2, bsize+1);
	int possibleMessageLength = bOrigColorCount*3/4;
	int possibleTextLength = possibleMessageLength-2;// one byte for check and one byte for message length
	
	if (possibleTextLength < text.length()) {
		throw new UnableToEncodeException("Text is too big");
	}
	
	int n = 13;
	
	// write check sequence
	for (int i = 0; i < checkSequence.length/2; i++) {
		byte[] ba = Binary.toBitArray(bytes[n]);
		ba[firstLSBit] = checkSequence[2*i];
		ba[secondLSBit] = checkSequence[2*i+1];
		bytes[n] = Binary.toByte(ba);
		n++;
	}
	
	// write text length
	byte[] cl = Binary.toBitArray((byte)text.length());
	for (int i = 0; i < cl.length/2; i++) {
		byte[] ba = Binary.toBitArray(bytes[n]);
		ba[firstLSBit] = cl[2*i];
		ba[secondLSBit] = cl[2*i+1];
		bytes[n] = Binary.toByte(ba);
		n++;
	}
	
	// write message
	byte[] textBytes = text.getBytes();
	for (int i = 0; i < textBytes.length; i++) {
		byte[] c = Binary.toBitArray(textBytes[i]);
		for (int ci = 0; ci < c.length/2; ci++) {
			byte[] ba = Binary.toBitArray(bytes[n]);
			ba[firstLSBit] = c[2*ci];
			ba[secondLSBit] = c[2*ci+1];
			bytes[n] = Binary.toByte(ba);
			n++;
		}
	}
	
	// write output file
	OutputStream os = new FileOutputStream(out);
	os.write(bytes);
	os.close();
}

Algorithm thiab qhov chaws ntawm txoj kev decrypt chav kawm GIFEncryptorByLSBMethod:

Steganography hauv GIF

@Override
public String decrypt(File in) throws UnableToDecodeException, NullPointerException, IOException {
	if (in == null) {
		throw new NullPointerException("Input file is null");
	}
	
	// read bytes from input file
	byte[] bytes = new byte[(int)in.length()];
	InputStream is = new FileInputStream(in);
	is.read(bytes);
	is.close();
	
	// check format
	if (!(new String(bytes, 0, 6)).equals("GIF89a")) {
		throw new UnableToDecodeException("Input file has wrong GIF format");
	}
	
	// read palette size property from first three bits in the 10-th byte from the file
	byte[] b10 = Binary.toBitArray(bytes[10]);
	byte bsize = Binary.toByte(new byte[] {b10[0], b10[1], b10[2]});
	
	// calculate color count and possible message length
	int bOrigColorCount = (int)Math.pow(2, bsize+1);
	int possibleMessageLength = bOrigColorCount*3/4;
	int possibleTextLength = possibleMessageLength-2;	// one byte for check and one byte for message length
	
	int n = 13;
	
	// read check sequence
	byte[] csBits = new byte[checkSequence.length];
	for (int i = 0; i < 4; i++) {
		byte[] ba = Binary.toBitArray(bytes[n]);
		csBits[2*i] = ba[firstLSBit];
		csBits[2*i+1] = ba[secondLSBit];
		n++;
	}
	byte cs = Binary.toByte(csBits);
	
	if (cs != Binary.toByte(checkSequence)) {
		throw new UnableToDecodeException("There is no encrypted message in the image (Check sequence is incorrect)");
	}
	
	// read text length
	byte[] cl = new byte[8];
	for (int i = 0; i < 4; i++) {
		byte[] ba = Binary.toBitArray(bytes[n]);
		cl[2*i] = ba[firstLSBit];
		cl[2*i+1] = ba[secondLSBit];
		n++;
	}
	byte textLength = Binary.toByte(cl);
	
	if (textLength < 0) {
		throw new UnableToDecodeException("Decoded text length is less than 0");
	}
	if (possibleTextLength < textLength) {
		throw new UnableToDecodeException("There is no messages (Decoded message length (" + textLength + ") is less than Possible message length (" + possibleTextLength + "))");
	}
	
	// read text bits and make text bytes
	byte[] bt = new byte[textLength];
	for (int i = 0; i < bt.length; i++) {
		byte[] bc = new byte[8];
		for (int bci = 0; bci < bc.length/2; bci++) {
			byte[] ba = Binary.toBitArray(bytes[n]);
			bc[2*bci] = ba[firstLSBit];
			bc[2*bci+1] = ba[secondLSBit];
			n++;
		}
		bt[i] = Binary.toByte(bc);
	}
	
	return new String(bt);
}

Kev ua tiav ntawm chav kawm GIFEncryptorByPaletteExtensionMethod yuav zoo sib xws, tsuas yog txoj kev txuag / nyeem cov ntaub ntawv sib txawv.

Hauv chav kawm MainFrame Cov txheej txheem wrapper tau piav qhia: encryptImage(Encryptor encryptor) ΠΈ decryptImage(Encryptor encryptor), ua cov kev tshwm sim ntawm interface txoj kev Encryptor thiab cuam tshuam nrog tus neeg siv, piv txwv li qhib cov lus xaiv cov ntaub ntawv, qhia cov lus yuam kev, thiab lwm yam; zoo li lwm txoj hauv kev: openImage(), tso cai rau tus neeg siv xaiv cov duab, exit(), uas tawm hauv daim ntawv thov. Cov txheej txheem no hu ua los ntawm Action's coj cov zaub mov. Chav kawm no tseem siv cov txheej txheem pabcuam: createComponents() - creation ntawm daim ntawv Cheebtsam, loadImageFile(File f) - thauj cov duab rau hauv ib qho tshwj xeeb ntawm cov ntaub ntawv. Kev ua tiav ntawm chav kawm GIFEncryptorByPaletteExtensionMethod zoo ib yam li kev siv chav kawm GIFEncryptorByLSBMethod, qhov sib txawv tseem ceeb yog nyob rau hauv txoj kev cov lus bytes sau thiab nyeem los ntawm palette.

Txoj haujlwm ua haujlwm

LBS method

Wb hais tias muaj ib daim duab zoo li no:

Steganography hauv GIF

Hauv daim duab no, cov palette muaj 256 xim (raws li Xim txuag). Thawj plaub xim yog: dawb, dub, liab, ntsuab. Lwm cov xim yog dub. Lub ntiaj teb no palette me ntsis sequence yuav raws li nram no:

11111111 11111111 11111111 00000000 00000000 00000000 11111111 00000000 00000000 00000000 11111111 00000000...

Steganography hauv GIF

Thaum cov lus tau kos, cov kab hauv qab yuav raug hloov nrog cov khoom los ntawm cov lus. Cov duab tshwm sim yuav luag tsis txawv ntawm qhov qub.

Thawj
Duab nrog embedded lus

Steganography hauv GIF
Steganography hauv GIF

Palette expansion method

Thaum koj qhib ib daim duab uas muaj cov lus uas siv txoj kev no, koj yuav pom cov duab hauv qab no:

Steganography hauv GIF

Nws yog tseeb hais tias txoj kev no yuav tsis ua hauj lwm rau tag nrho-fledged espionage kev ua ub no, thiab tej zaum yuav xav tau ntxiv encryption ntawm cov lus.

Encryption / decryption hauv cov duab animated ua haujlwm ib yam li cov duab zoo li qub, tab sis cov animation tsis tawg.

Cov peev txheej siv:

Download tau:

Tau qhov twg los: www.hab.com

Ntxiv ib saib