package code.kalter.longflight.crypto; import java.io.IOException; import java.io.InputStream; /** * Шифровальный входной поток (обёртка для InputStream). Дешифровка: * xor -> xchgb * * @author KalterFive */ public class CIStream extends InputStream { private final InputStream istream; private final Random random; // key - ключ для ГПСЧ public CIStream(InputStream istream, int key) { this.istream = istream; this.random = new Random(key); } public int read() throws IOException { int b = istream.read(); b ^= random.random(0xFF); b = (b << 4) | (b >> 4); return b; } public int available() throws IOException { return istream.available(); } public void close() throws IOException { istream.close(); } }