Steganography na GIF

Okwu Mmalite

Ekele diri m.
N'oge na-adịghị anya gara aga, mgbe m na-agụ akwụkwọ na mahadum, e nwere ọrụ nkuzi na ịdọ aka ná ntị "Ụzọ Software nke nchekwa ozi." Ọrụ ahụ chọrọ ka anyị mepụta mmemme na-etinye ozi na faịlụ GIF. Ekpebiri m ime ya na Java.

N'isiokwu a, m ga-akọwa ụfọdụ isi ihe ọmụma, yana otu esi emepụta obere mmemme a.

Akụkụ usoro iwu

Ụdị GIF

GIF (Graphics Interchange Format - usoro maka mgbanwe onyonyo) bụ usoro maka ịchekwa onyogho eserese, nke nwere ike ịchekwa data abịakọrọ na-enweghị ọdịda dị mma n'ụdị ruru agba 256. Emepụtara usoro a na 1987 (GIF87a) site na CompuServe maka ịnyefe onyonyo raster na netwọkụ. Na 1989, a gbanwere usoro ahụ (GIF89a), agbakwunyere nkwado maka nghọta na ihe ngosi.

Faịlụ GIF nwere usoro ngọngọ. Ihe mgbochi ndị a na-enwekarị ogologo ogologo (ma ọ bụ na-adabere na ụfọdụ ọkọlọtọ), n'ihi ya, ọ fọrọ nke nta ka ọ bụrụ na ọ gaghị ekwe omume imehie ebe ngọngọ ọ bụla dị. Nhazi nke onyonyo GIF kacha dị mfe na-abụghị animated na usoro GIF89a:

Steganography na GIF

N'ime ngọngọ niile nke ihe owuwu ahụ, na nke a, anyị ga-enwe mmasị na ngọngọ palette zuru ụwa ọnụ na paramita maka palette:

  • CT - ọnụnọ nke palette zuru ụwa ọnụ. Ọ bụrụ na edobere ọkọlọtọ a, palette zuru ụwa ọnụ ga-amalite ozugbo akachara ihuenyo ezi uche dị na ya.
  • Size - palette size na ọnụ ọgụgụ nke agba na foto. Uru maka oke a:

size
Ọnụọgụ agba
Nha palette, 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

Ụzọ nzuzo

A ga-eji ụzọ ndị a iji zoo ozi na faịlụ onyonyo:

  • Usoro LSB (Bit kacha nta).
  • Usoro mgbakwunye palette

Usoro LSB - a nkịtị usoro nke steganography. Ọ mejupụtara iji dochie ibe n'ibe ikpeazụ n'ime akpa (n'ọnọdụ anyị, bytes palette ụwa) na ibe nke ozi zoro ezo.

Ihe omume a ga-eji nkeji abụọ ikpeazụ na palette bytes zuru ụwa ọnụ dịka akụkụ nke usoro a. Nke a pụtara na maka onyonyo 24-bit, ebe agba palette bụ bytes atọ maka ọbara ọbara, acha anụnụ anụnụ na akwụkwọ ndụ akwụkwọ ndụ, mgbe etinyere ozi n'ime ya, akụrụngwa agba ọ bụla ga-agbanwe site na oke nke 3/255 gradations. Mgbanwe dị otú ahụ, nke mbụ, ga-abụ ihe a na-adịghị ahụ anya ma ọ bụ sie ike ịhụ anya mmadụ, na nke abụọ, a gaghị ahụ ya na ngwaọrụ mmepụta ozi dị ala.

Ọnụ ọgụgụ nke ozi ga-adabere kpọmkwem na nha nke palette oyiyi. Ebe ọ bụ na ọnụ ọgụgụ kachasị elu nke palette bụ 256 agba, ma ọ bụrụ na edere ozi abụọ n'ime akụkụ nke agba ọ bụla, mgbe ahụ ogologo ozi kachasị (ya na palette kachasị na foto) bụ 192 bytes. Ozugbo etinyere ozi ahụ na onyonyo a, nha faịlụ anaghị agbanwe.

Usoro mgbasawanye palette, nke na-arụ ọrụ naanị maka usoro GIF. Ọ ga-adị irè na ihe oyiyi na obere palette. Ihe kachasị mkpa bụ na ọ na-abawanye nha nke palette ahụ, si otú ahụ na-enye ohere ọzọ maka ide ihe ndị dị mkpa n'ọnọdụ nke agba agba. Ọ bụrụ na anyị na-atụle na opekempe size nke palette bụ 2 agba (6 bytes), mgbe ahụ kacha size nke ozi agbakwunyere nwere ike ịbụ 256 × 3-6 = 762 bytes. Ọdịmma a bụ nchekwa nzuzo dị ala; enwere ike ịgụ ozi agbakwunyere site na iji editọ ederede ọ bụla ma ọ bụrụ na edobebeghị ozi nzuzo ọzọ.

Akụkụ bara uru

Nhazi mmemme

Ngwa niile dị mkpa maka mmejuputa ezoro ezo na algọridim nke decryption ga-etinye na ngwugwu com.tsarik.steganography. Nke a ngwugwu gụnyere interface Encryptor na usoro encrypt и decrypt, Klas Binary, nke na-enye ike na-arụ ọrụ na bit arrays, yana ewepụrụ klas UnableToEncryptException и UnableToDecryptException, nke kwesịrị iji na interface ụzọ Encryptor n'ihe gbasara ngbanwe na ndoputa mperi n'otu n'otu.

Isi ngwungwu mmemme com.tsarik.programs.gifed ga-agụnye klaasị mmemme na-agba ọsọ nwere usoro kwụ ọtọ main, na-enye gị ohere ịme mmemme ahụ; klas nke na-echekwa paramita mmemme; na ngwugwu na klas ndị ọzọ.

A ga-egosipụta mmejuputa algọridim n'onwe ha na ngwugwu com.tsarik.programs.gifed.gif klas GIFEncryptorByLSBMethod и GIFEncryptorByPaletteExtensionMethod. Klas abụọ a ga-emejuputa interface ahụ Encryptor.

Dabere na nhazi nke usoro GIF, ị nwere ike ịmepụta algọridim n'ozuzu maka iwebata ozi na palette oyiyi:

Steganography na GIF

Iji chọpụta ọnụnọ nke ozi na onyonyo, ọ dị mkpa ịgbakwunye ụfọdụ usoro nke bits na mmalite nke ozi ahụ, nke decoder na-agụ na mbụ wee lelee maka izi ezi. Ọ bụrụ na ọ dabaraghị, mgbe ahụ, a na-ewere ya na ọ dịghị ozi zoro ezo na foto a. Ọzọ, ịkwesịrị ịkọwa ogologo ozi ahụ. Mgbe ahụ ederede ozi n'onwe ya.

Eserese klas nke ngwa niile:

Steganography na GIF

Mmejuputa mmemme

Enwere ike kewaa mmejuputa mmemme ahụ n'ime akụkụ abụọ: mmejuputa ntinye nzuzo na ụzọ decryption Encryptor, na klas GIFEncryptorByLSBMethod и GIFEncryptorByPaletteExtensionMethod, na mmejuputa nke interface onye ọrụ.

Tụlee ihe ọmụmụ ahụ GIFEncryptorByLSBMethod.

Steganography na GIF

ubi firstLSBit и secondLSBit nwere ọnụọgụ ọnụọgụ byte nke ọ bụla nke onyonyo a ga-esi tinye ozi na ebe ekwesịrị ịgụ ya. Ubi checkSequence na-echekwa usoro nlele ntakịrị iji hụ na nnabata nke ozi agbakwunyere. Usoro kwụ ọtọ getEncryptingFileParameters weghachi paramita nke faịlụ akọwapụtara yana njirimara nke ozi nwere ike.

Usoro algọridim encrypt klas GIFEncryptorByLSBMethod:

Steganography na GIF

Na koodu ya:

@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 na koodu isi mmalite nke usoro ahụ decrypt klas GIFEncryptorByLSBMethod:

Steganography na 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);
}

Mmejuputa klaasị GIFEncryptorByPaletteExtensionMethod ga-adị ka nke ahụ, naanị usoro nke ịchekwa / ịgụ ozi dị iche.

Na klaasị MainFrame A na-akọwa usoro mkpuchi: encryptImage(Encryptor encryptor) и decryptImage(Encryptor encryptor), nhazi nsonaazụ nke ụzọ interface Encryptor na iso onye ọrụ na-emekọrịta ihe, ya bụ imepe dialog nhọrọ faịlụ, na-egosi ozi njehie, wdg; yana usoro ndị ọzọ: openImage(), na-ekwe ka onye ọrụ họrọ ihe oyiyi, exit(), nke na-apụ na ngwa. A na-akpọ usoro ndị a site na Actionihe menu kwekọrọ. Klas a na-etinyekwa usoro inyeaka: createComponents() - ike nke ụdị components, loadImageFile(File f) - na-ebunye onyonyo n'ime akụrụngwa pụrụ iche site na faịlụ. Mmejuputa klaasị GIFEncryptorByPaletteExtensionMethod yiri mmejuputa klaasị GIFEncryptorByLSBMethod, Isi ihe dị iche bụ n'ụzọ e si ede ma na-agụ site na palette ozi.

Ọrụ mmemme

Usoro LBS

Ka anyị kwuo na enwere onyonyo dị ka nke a:

Steganography na GIF

N'ihe onyonyo a, palette ahụ nwere agba 256 (dị ka Paint na-echekwa). Agba anọ mbụ bụ: ọcha, nwa, ọbara ọbara, akwụkwọ ndụ akwụkwọ ndụ. Agba ndị ọzọ bụ oji. Usoro palette zuru ụwa ọnụ ga-abụ nke a:

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

Steganography na GIF

Ozugbo agbakwunyere ozi ahụ, a ga-eji ibe n'ime ozi dochie ibe n'okpuru akara. Ihe oyiyi a na-esi na ya pụta fọrọ nke nta ka ọ dị iche na nke mbụ.

Mbụ
Foto nwere ozi agbakwunyere

Steganography na GIF
Steganography na GIF

Usoro mgbasawanye palette

Mgbe imepere onyonyo nwere ozi site na iji usoro a, ị ga-ahụ foto a:

Steganography na GIF

O doro anya na usoro a agaghị arụ ọrụ maka ọrụ nledo zuru oke, ma nwee ike ịchọ ọzọ izo ya ezo nke ozi ahụ.

Izo ya ezo/decryption na eserese eserese na-arụ ọrụ dị ka ọ dị na onyonyo kwụ ọtọ mgbe niile, mana eserese anaghị agbaji.

Isi mmalite ejiri:

Download:

isi: www.habr.com

Tinye a comment