DEADSOFTWARE

Initial commit.
[LongFlight.git] / src / code / kalter / longflight / crypto / CIStream.java
1 package code.kalter.longflight.crypto;
3 import java.io.IOException;
4 import java.io.InputStream;
6 /**
7 * Шифровальный входной поток (обёртка для InputStream). Дешифровка:
8 * xor -> xchgb
9 *
10 * @author KalterFive
11 */
12 public class CIStream extends InputStream {
14 private final InputStream istream;
15 private final Random random;
17 // key - ключ для ГПСЧ
18 public CIStream(InputStream istream, int key) {
19 this.istream = istream;
20 this.random = new Random(key);
21 }
23 public int read() throws IOException {
24 int b = istream.read();
25 b ^= random.random(0xFF);
26 b = (b << 4) | (b >> 4);
27 return b;
28 }
30 public int available() throws IOException {
31 return istream.available();
32 }
34 public void close() throws IOException {
35 istream.close();
36 }
37 }