idevoid encrypt (File in, File out, String text) throws UnableToEncodeException, NullPointerException, IOException {(in == null) {new NullPointerException ("Input file is null");
} (out == null) {new NullPointerException ("Output file is null");
} (text == null) {new NullPointerException ("Text is null");
}
// read bytes from input file [] bytes = new byte [(int) in.length ()]; is = new FileInputStream (in);. read (bytes);. close () ;
// check format (! (new String (bytes, 0, 6)). equals ("GIF89a")) {new UnableToEncodeException ("Input file has wrong GIF format");
}
// read palette size property from first three bits in the 10-th byte from the file [] b10 = Binary.toBitArray (bytes [10]); bsize = Binary.toByte (new byte [ ] {b10 [0], b10 [1], b10 [2]});
// calculate color count and possible message lengthbOrigColorCount = (int) Math.pow (2, bsize +1); possibleMessageLength = bOrigColorCount * 3/4; possibleTextLength = possibleMessageLength-2 ;//one byte for check and one byte for message length (possibleTextLength
} n = 13;
// write check sequence (int i = 0; i
}
// write text length [] cl = Binary.toBitArray ((byte) text.length ()); (int i = 0; i
}
// write message [] textBytes = text.getBytes (); (int i = 0; i
}
}
// write output fileos = new FileOutputStream (out);. write (bytes);. close ();
}
Алгоритм і вихідний код методу decrypt класу GIFEncryptorByLSBMethod:
В
Рис. 5. Алгоритм методу decrypt
@ OverrideString decrypt (File in) throws UnableToDecodeException, NullPointerException, IOException {(in == null) {new NullPointerException ("Input file is null");
}
// read bytes from input file [] bytes = new byte [(int) in.length ()]; is = new FileInputStream (in);. read (bytes);. close () ;
// check format (! (new String (bytes, 0...