Class: RuneRb::Network::ISAAC

Inherits:
Object
  • Object
show all
Defined in:
app/network/isaac.rb

Overview

An implementation of an ISAAC cipher used to generate random numbers for message interchange.

Since:

  • 0.9.3

Instance Method Summary collapse

Constructor Details

#initialize(seed) ⇒ ISAAC

Called when a new ISAAC Cipher is created.

Since:

  • 0.9.3


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/network/isaac.rb', line 7

def initialize(seed)
  @aa = 0
  @bb = 0
  @cc = 0
  @mm = []
  @randrsl = Array.new(256, 0)

  seed.each_with_index do |element, i|
    @randrsl[i] = element
  end

  randinit
end

Instance Method Details

#next_valueObject

Gets the next random value. If 256 cycles have occurred, the results array is regenerated.

Since:

  • 0.9.3


23
24
25
26
27
28
29
30
# File 'app/network/isaac.rb', line 23

def next_value
  if @randcnt.zero?
    isaac
    @randcnt = 256
  end
  @randcnt -= 1
  @randrsl[@randcnt].signed(:i)
end