RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.net.codec.IsaacCipher Class Reference

An implementation of an ISAAC cipher. More...

Public Member Functions

int getKey ()
 Gets the next value.
void init (boolean flag)
 Initializes the ISAAC.
void isaac ()
 Generates 256 results.
 IsaacCipher (int[] seed)
 Creates the ISAAC cipher.

Private Attributes

int a
 The accumulator.
int b
 The last result.
int c
 The counter.
int count = 0
 The count through the results.
int memory [] = new int[SIZE]
 The internal memory state.
int results [] = new int[SIZE]
 The results.

Static Private Attributes

static final int MASK = (SIZE - 1) << 2
 For pseudorandom lookup.
static final int RATIO = 0x9e3779b9
 The golden ratio.
static final int SIZE = 1 << SIZE_LOG
 The size of the results and memory arrays.
static final int SIZE_LOG = 8
 The log of the size of the results and memory arrays.

Detailed Description

An implementation of an ISAAC cipher.

See http://en.wikipedia.org/wiki/ISAAC_(cipher) for more information.

This implementation is based on the one written by Bob Jenkins, which is available at http://www.burtleburtle.net/bob/java/rand/Rand.java.

Author
Graham Edgecombe

Definition at line 36 of file IsaacCipher.java.

Constructor & Destructor Documentation

◆ IsaacCipher()

com.runehive.net.codec.IsaacCipher.IsaacCipher ( int[] seed)

Creates the ISAAC cipher.

Parameters
seedThe seed.

Definition at line 93 of file IsaacCipher.java.

93 {
94 for (int i = 0; i < seed.length; i++) {
95 results[i] = seed[i];
96 }
97 init(true);
98 }

References init(), and results.

Here is the call graph for this function:

Member Function Documentation

◆ getKey()

int com.runehive.net.codec.IsaacCipher.getKey ( )

Gets the next value.

Returns
The next value.

Definition at line 105 of file IsaacCipher.java.

105 {
106 if (count-- == 0) {
107 isaac();
108 count = SIZE - 1;
109 }
110 return results[count];
111 }

References count, isaac(), results, and SIZE.

Here is the call graph for this function:

◆ init()

void com.runehive.net.codec.IsaacCipher.init ( boolean flag)

Initializes the ISAAC.

Parameters
flagFlag indicating if we should perform a second pass.

Definition at line 176 of file IsaacCipher.java.

176 {
177 int i;
178 int a, b, c, d, e, f, g, h;
179 a = b = c = d = e = f = g = h = RATIO;
180 for (i = 0; i < 4; ++i) {
181 a ^= b << 11;
182 d += a;
183 b += c;
184 b ^= c >>> 2;
185 e += b;
186 c += d;
187 c ^= d << 8;
188 f += c;
189 d += e;
190 d ^= e >>> 16;
191 g += d;
192 e += f;
193 e ^= f << 10;
194 h += e;
195 f += g;
196 f ^= g >>> 4;
197 a += f;
198 g += h;
199 g ^= h << 8;
200 b += g;
201 h += a;
202 h ^= a >>> 9;
203 c += h;
204 a += b;
205 }
206 for (i = 0; i < SIZE; i += 8) {
207 if (flag) {
208 a += results[i];
209 b += results[i + 1];
210 c += results[i + 2];
211 d += results[i + 3];
212 e += results[i + 4];
213 f += results[i + 5];
214 g += results[i + 6];
215 h += results[i + 7];
216 }
217 a ^= b << 11;
218 d += a;
219 b += c;
220 b ^= c >>> 2;
221 e += b;
222 c += d;
223 c ^= d << 8;
224 f += c;
225 d += e;
226 d ^= e >>> 16;
227 g += d;
228 e += f;
229 e ^= f << 10;
230 h += e;
231 f += g;
232 f ^= g >>> 4;
233 a += f;
234 g += h;
235 g ^= h << 8;
236 b += g;
237 h += a;
238 h ^= a >>> 9;
239 c += h;
240 a += b;
241 memory[i] = a;
242 memory[i + 1] = b;
243 memory[i + 2] = c;
244 memory[i + 3] = d;
245 memory[i + 4] = e;
246 memory[i + 5] = f;
247 memory[i + 6] = g;
248 memory[i + 7] = h;
249 }
250 if (flag) {
251 for (i = 0; i < SIZE; i += 8) {
252 a += memory[i];
253 b += memory[i + 1];
254 c += memory[i + 2];
255 d += memory[i + 3];
256 e += memory[i + 4];
257 f += memory[i + 5];
258 g += memory[i + 6];
259 h += memory[i + 7];
260 a ^= b << 11;
261 d += a;
262 b += c;
263 b ^= c >>> 2;
264 e += b;
265 c += d;
266 c ^= d << 8;
267 f += c;
268 d += e;
269 d ^= e >>> 16;
270 g += d;
271 e += f;
272 e ^= f << 10;
273 h += e;
274 f += g;
275 f ^= g >>> 4;
276 a += f;
277 g += h;
278 g ^= h << 8;
279 b += g;
280 h += a;
281 h ^= a >>> 9;
282 c += h;
283 a += b;
284 memory[i] = a;
285 memory[i + 1] = b;
286 memory[i + 2] = c;
287 memory[i + 3] = d;
288 memory[i + 4] = e;
289 memory[i + 5] = f;
290 memory[i + 6] = g;
291 memory[i + 7] = h;
292 }
293 }
294 isaac();
295 count = SIZE;
296 }

References a, b, c, count, isaac(), memory, RATIO, results, and SIZE.

Referenced by IsaacCipher().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isaac()

void com.runehive.net.codec.IsaacCipher.isaac ( )

Generates 256 results.

Definition at line 116 of file IsaacCipher.java.

116 {
117 int i, j, x, y;
118 b += ++c;
119 for (i = 0, j = SIZE / 2; i < SIZE / 2; ) {
120 x = memory[i];
121 a ^= a << 13;
122 a += memory[j++];
123 memory[i] = y = memory[(x & MASK) >> 2] + a + b;
124 results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
125
126 x = memory[i];
127 a ^= a >>> 6;
128 a += memory[j++];
129 memory[i] = y = memory[(x & MASK) >> 2] + a + b;
130 results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
131
132 x = memory[i];
133 a ^= a << 2;
134 a += memory[j++];
135 memory[i] = y = memory[(x & MASK) >> 2] + a + b;
136 results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
137
138 x = memory[i];
139 a ^= a >>> 16;
140 a += memory[j++];
141 memory[i] = y = memory[(x & MASK) >> 2] + a + b;
142 results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
143 }
144 for (j = 0; j < SIZE / 2; ) {
145 x = memory[i];
146 a ^= a << 13;
147 a += memory[j++];
148 memory[i] = y = memory[(x & MASK) >> 2] + a + b;
149 results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
150
151 x = memory[i];
152 a ^= a >>> 6;
153 a += memory[j++];
154 memory[i] = y = memory[(x & MASK) >> 2] + a + b;
155 results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
156
157 x = memory[i];
158 a ^= a << 2;
159 a += memory[j++];
160 memory[i] = y = memory[(x & MASK) >> 2] + a + b;
161 results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
162
163 x = memory[i];
164 a ^= a >>> 16;
165 a += memory[j++];
166 memory[i] = y = memory[(x & MASK) >> 2] + a + b;
167 results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
168 }
169 }

References a, b, c, MASK, memory, results, SIZE, and SIZE_LOG.

Referenced by getKey(), and init().

Here is the caller graph for this function:

Member Data Documentation

◆ a

int com.runehive.net.codec.IsaacCipher.a
private

The accumulator.

Definition at line 76 of file IsaacCipher.java.

Referenced by init(), and isaac().

◆ b

int com.runehive.net.codec.IsaacCipher.b
private

The last result.

Definition at line 81 of file IsaacCipher.java.

Referenced by init(), and isaac().

◆ c

int com.runehive.net.codec.IsaacCipher.c
private

The counter.

Definition at line 86 of file IsaacCipher.java.

Referenced by init(), and isaac().

◆ count

int com.runehive.net.codec.IsaacCipher.count = 0
private

The count through the results.

Definition at line 61 of file IsaacCipher.java.

Referenced by getKey(), and init().

◆ MASK

final int com.runehive.net.codec.IsaacCipher.MASK = (SIZE - 1) << 2
staticprivate

For pseudorandom lookup.

Definition at line 56 of file IsaacCipher.java.

Referenced by isaac().

◆ memory

int com.runehive.net.codec.IsaacCipher.memory[] = new int[SIZE]
private

The internal memory state.

Definition at line 71 of file IsaacCipher.java.

Referenced by init(), and isaac().

◆ RATIO

final int com.runehive.net.codec.IsaacCipher.RATIO = 0x9e3779b9
staticprivate

The golden ratio.

Definition at line 41 of file IsaacCipher.java.

Referenced by init().

◆ results

int com.runehive.net.codec.IsaacCipher.results[] = new int[SIZE]
private

The results.

Definition at line 66 of file IsaacCipher.java.

Referenced by getKey(), init(), isaac(), and IsaacCipher().

◆ SIZE

final int com.runehive.net.codec.IsaacCipher.SIZE = 1 << SIZE_LOG
staticprivate

The size of the results and memory arrays.

Definition at line 51 of file IsaacCipher.java.

Referenced by getKey(), init(), and isaac().

◆ SIZE_LOG

final int com.runehive.net.codec.IsaacCipher.SIZE_LOG = 8
staticprivate

The log of the size of the results and memory arrays.

Definition at line 46 of file IsaacCipher.java.

Referenced by isaac().


The documentation for this class was generated from the following file: