DEADSOFTWARE

Initial commit.
[LongFlight.git] / Crypto / 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 * Шифровальный входной поток
8 *
9 * @author Kalter
10 */
11 public class CIStream extends InputStream {
13 private final InputStream istream;
14 private final Random random;
16 public CIStream(InputStream istream, int key) {
17 this.istream = istream;
18 this.random = new Random(key);
19 }
21 @Override
22 public int read() throws IOException {
23 int b = istream.read();
24 b = (b << 4) | (b >> 4);
25 b ^= random.random(0xFF);
26 return b;
27 }
29 @Override
30 public int available() throws IOException {
31 return istream.available();
32 }
34 @Override
35 public void close() throws IOException {
36 istream.close();
37 }
38 }