1 package org.jastacry.layer;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.OutputStream;
6 import java.util.Objects;
7
8 import org.jastacry.JastacryException;
9
10
11
12
13
14
15
16
17 public class XorLayer extends AbstractBasicLayer
18 {
19
20
21
22 public static final String LAYERNAME = "Xor Layer";
23
24
25
26 private byte bitMask;
27
28
29
30
31 public XorLayer()
32 {
33 super(XorLayer.class, LAYERNAME);
34 }
35
36
37
38
39
40
41 @Override
42 public final void init(final String data)
43 {
44 this.bitMask = (byte) Integer.parseInt(data);
45 }
46
47
48
49
50
51
52
53
54 public final void encodeAndDecode(final InputStream inputStream, final OutputStream outputStream) throws JastacryException
55 {
56 try
57 {
58 int iChar;
59 byte bChar;
60 while ((iChar = inputStream.read()) != -1)
61 {
62 bChar = (byte) iChar;
63 bChar = (byte) (bChar ^ this.bitMask);
64 outputStream.write(bChar);
65 }
66 logger.info("close pipe");
67 outputStream.close();
68 }
69 catch (IOException e)
70 {
71 throw (JastacryExceptionl#JastacryException">JastacryException) new JastacryException("encodeAndDecode failed").initCause(e);
72 }
73 }
74
75
76
77
78
79
80 @Override
81 public boolean equals(final Object o)
82 {
83 return o == this || o instanceof XorLayer/../org/jastacry/layer/XorLayer.html#XorLayer">XorLayer && ((XorLayer) o).bitMask == this.bitMask;
84 }
85
86
87
88
89
90 @Override
91 public int hashCode()
92 {
93 return Objects.hash(bitMask);
94 }
95 }