bai-crypt-isaac 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +35 -0
- data/VERSION +1 -1
- data/crypt-isaac.gemspec +7 -9
- data/lib/crypt-isaac.rb +1 -158
- data/lib/crypt-isaac/crypt-isaac.rb +158 -0
- data/rakefile +17 -41
- data/test/crypt-isaac_test.rb +42 -45
- data/test/test_helper.rb +1 -3
- metadata +9 -9
- data/LICENSE +0 -14
- data/README.rdoc +0 -51
data/README.markdown
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
ISAAC is a cryptographically secure PRNG for generating high quality random numbers. Detailed information about the algorithm can be found at: http://burtleburtle.net/bob/rand/isaac.html
|
2
|
+
|
3
|
+
This is a pure Ruby implementation of the algorithm. It is reasonably fast for a pure Ruby implementation. On an 800Mhz PIII computer running Ruby 1.8.2, and while the machine is also serving as general desktop, the library seems to consistently generate between 15000 and 16000 random numbers per second.
|
4
|
+
|
5
|
+
Ruby uses the Mersenne Twister as its PRNG, and while this the Twister is a fast PRNG that produces highly random numbers, it is not strong for cryptographic purposes, nor is it suitable when one needs multiple independent streams of random numbers. Crypt::ISAAC is suitable for either purpose.
|
6
|
+
|
7
|
+
### Requirements
|
8
|
+
|
9
|
+
* Ruby 1.6
|
10
|
+
* Ruby 1.8
|
11
|
+
* Ruby 1.9
|
12
|
+
|
13
|
+
|
14
|
+
### Install
|
15
|
+
|
16
|
+
If you have never installed Crypt::ISAAC, you may run the test suite to confirm that it works with:
|
17
|
+
|
18
|
+
~$ rake test
|
19
|
+
|
20
|
+
|
21
|
+
### Usage
|
22
|
+
|
23
|
+
require 'crypt-isaac'
|
24
|
+
rng = Crypt::ISAAC.new
|
25
|
+
r1 = rng.rand() # returns a floating point between 0 and 1
|
26
|
+
r2 = rng.rand(1000) # returns an integer between 0 and 999
|
27
|
+
|
28
|
+
rand() should work identically to the Kernel.rand().
|
29
|
+
|
30
|
+
Enjoy it. Let me know if you find anything that can be improved or that needs to be fixed.
|
31
|
+
|
32
|
+
|
33
|
+
### License
|
34
|
+
|
35
|
+
The Crypt::ISAAC library is licensed with an MIT style licence. See the LICENSE file for details. As for the ISAAC algorithm itself, see: http://burtleburtle.net/bob/rand/isaac.html
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.3
|
data/crypt-isaac.gemspec
CHANGED
@@ -2,33 +2,31 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{crypt-isaac}
|
5
|
-
s.version = "0.9.
|
5
|
+
s.version = "0.9.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["beawesomeinstead"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-08-03}
|
10
10
|
s.email = %q{beawesomeinstead@yahoo.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
|
-
"
|
13
|
-
"README.rdoc"
|
12
|
+
"README.markdown"
|
14
13
|
]
|
15
14
|
s.files = [
|
16
15
|
".gitignore",
|
17
|
-
"
|
18
|
-
"README.rdoc",
|
16
|
+
"README.markdown",
|
19
17
|
"VERSION",
|
20
18
|
"crypt-isaac.gemspec",
|
21
19
|
"lib/crypt-isaac.rb",
|
20
|
+
"lib/crypt-isaac/crypt-isaac.rb",
|
22
21
|
"rakefile",
|
23
22
|
"test/crypt-isaac_test.rb",
|
24
23
|
"test/test_helper.rb"
|
25
24
|
]
|
26
|
-
s.has_rdoc = true
|
27
25
|
s.homepage = %q{http://github.com/bai/crypt-isaac}
|
28
26
|
s.rdoc_options = ["--charset=UTF-8"]
|
29
27
|
s.require_paths = ["lib"]
|
30
|
-
s.rubygems_version = %q{1.3.
|
31
|
-
s.summary = %q{Ruby implementation of the ISAAC PRNG}
|
28
|
+
s.rubygems_version = %q{1.3.5}
|
29
|
+
s.summary = %q{Pure-Ruby implementation of the ISAAC PRNG.}
|
32
30
|
s.test_files = [
|
33
31
|
"test/crypt-isaac_test.rb",
|
34
32
|
"test/test_helper.rb"
|
data/lib/crypt-isaac.rb
CHANGED
@@ -1,158 +1 @@
|
|
1
|
-
|
2
|
-
# ISAAC is a fast, strong random number generator. Details on the algorithm can be found
|
3
|
-
# here: http://burtleburtle.net/bob/rand/isaac.html
|
4
|
-
# This provides a consistent and capable algorithm for producing independent streams of quality random numbers.
|
5
|
-
class ISAAC
|
6
|
-
attr_accessor :randrsl, :randcnt
|
7
|
-
attr_accessor :mm, :aa, :bb, :cc
|
8
|
-
|
9
|
-
# When a Crypt::ISAAC object is created, it needs to be seeded for random number generation. If the system has a
|
10
|
-
# /dev/urandom file, that will be used to do the seeding by default. If false is explictly passed when creating the
|
11
|
-
# object, it will instead use /dev/random to generate its seeds. Be warned that this may make for SLOW
|
12
|
-
# initialization. If the requested source (/dev/urandom or /dev/random) do not exist, the system will fall back to
|
13
|
-
# a simplistic initialization mechanism using the builtin Mersenne Twister PRNG.
|
14
|
-
def initialize(noblock = true)
|
15
|
-
@mm = []
|
16
|
-
@randrsl = []
|
17
|
-
# Best initialization of the generator would be by pulling numbers from /dev/random.
|
18
|
-
rnd_source = noblock ? '/dev/urandom' : '/dev/random'
|
19
|
-
if (FileTest.exist? rnd_source)
|
20
|
-
File.open(rnd_source,'r') do |r|
|
21
|
-
256.times do |t|
|
22
|
-
z = r.read(4)
|
23
|
-
x = z.unpack('V')[0]
|
24
|
-
@randrsl[t] = x
|
25
|
-
end
|
26
|
-
end
|
27
|
-
else
|
28
|
-
# If urandom isn't available, the standard Ruby PRNG makes an adequate fallback.
|
29
|
-
256.times do |t|
|
30
|
-
@randrsl[t] = Kernel.rand(4294967295)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
randinit(true)
|
34
|
-
nil
|
35
|
-
end
|
36
|
-
|
37
|
-
# Works just like the standard rand() function. If called with an integer argument, rand() will return positive
|
38
|
-
# random number in the range of 0 to (argument - 1). If called without an integer argument, rand() returns a
|
39
|
-
# positive floating point number less than 1.
|
40
|
-
def rand(*num)
|
41
|
-
if (@randcnt == 1)
|
42
|
-
isaac
|
43
|
-
@randcnt = 256
|
44
|
-
end
|
45
|
-
@randcnt -= 1
|
46
|
-
if num[0].to_i > 0
|
47
|
-
@randrsl[@randcnt].modulo(num[0])
|
48
|
-
else
|
49
|
-
".#{@randrsl[@randcnt]}".to_f
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def isaac
|
54
|
-
i = 0
|
55
|
-
x = 0
|
56
|
-
y = 0
|
57
|
-
|
58
|
-
@cc += 1
|
59
|
-
@bb += @cc
|
60
|
-
@bb & 0xffffffff
|
61
|
-
|
62
|
-
while (i < 256) do
|
63
|
-
x = @mm[i]
|
64
|
-
@aa = (@mm[(i + 128) & 255] + (@aa^(@aa << 13)) ) & 0xffffffff
|
65
|
-
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
66
|
-
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
67
|
-
i += 1
|
68
|
-
|
69
|
-
x = @mm[i]
|
70
|
-
@aa = (@mm[(i+128)&255] + (@aa^(0x03ffffff & (@aa >> 6))) ) & 0xffffffff
|
71
|
-
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
72
|
-
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
73
|
-
i += 1
|
74
|
-
|
75
|
-
x = @mm[i]
|
76
|
-
@aa = (@mm[(i + 128)&255] + (@aa^(@aa << 2)) ) & 0xffffffff
|
77
|
-
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
78
|
-
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
79
|
-
i += 1
|
80
|
-
|
81
|
-
x = @mm[i]
|
82
|
-
@aa = (@mm[(i+128)&255] + (@aa^(0x0000ffff & (@aa >> 16))) ) & 0xffffffff
|
83
|
-
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
84
|
-
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
85
|
-
i += 1
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def randinit(flag)
|
90
|
-
i = 0
|
91
|
-
a = 0
|
92
|
-
b = 0
|
93
|
-
c = 0
|
94
|
-
d = 0
|
95
|
-
e = 0
|
96
|
-
f = 0
|
97
|
-
g = 0
|
98
|
-
@aa = @bb = @cc = 0
|
99
|
-
a = b = c = d = e = f = g = h = 0x9e3779b9
|
100
|
-
|
101
|
-
while (i < 4) do
|
102
|
-
a ^= b<<1; d += a; b += c
|
103
|
-
b ^= 0x3fffffff & (c>>2); e += b; c += d
|
104
|
-
c ^= d << 8; f += c; d += e
|
105
|
-
d ^= 0x0000ffff & (e >> 16); g += d; e += f
|
106
|
-
e ^= f << 10; h += e; f += g
|
107
|
-
f ^= 0x0fffffff & (g >> 4); a += f; g += h
|
108
|
-
g ^= h << 8; b += g; h += a
|
109
|
-
h ^= 0x007fffff & (a >> 9); c += h; a += b
|
110
|
-
i += 1
|
111
|
-
end
|
112
|
-
|
113
|
-
i = 0
|
114
|
-
while (i < 256) do
|
115
|
-
if (flag)
|
116
|
-
a+=@randrsl[i ].to_i; b+=@randrsl[i+1].to_i;
|
117
|
-
c+=@randrsl[i+2]; d+=@randrsl[i+3];
|
118
|
-
e+=@randrsl[i+4]; f+=@randrsl[i+5];
|
119
|
-
g+=@randrsl[i+6]; h+=@randrsl[i+7];
|
120
|
-
end
|
121
|
-
|
122
|
-
a^=b<<11; d+=a; b+=c;
|
123
|
-
b^=0x3fffffff & (c>>2); e+=b; c+=d;
|
124
|
-
c^=d<<8; f+=c; d+=e;
|
125
|
-
d^=0x0000ffff & (e>>16); g+=d; e+=f;
|
126
|
-
e^=f<<10; h+=e; f+=g;
|
127
|
-
f^=0x0fffffff & (g>>4); a+=f; g+=h;
|
128
|
-
g^=h<<8; b+=g; h+=a;
|
129
|
-
h^=0x007fffff & (a>>9); c+=h; a+=b;
|
130
|
-
@mm[i]=a;@mm[i+1]=b; @mm[i+2]=c; @mm[i+3]=d;
|
131
|
-
@mm[i+4]=e; @mm[i+5]=f; @mm[i+6]=g; @mm[i+7]=h;
|
132
|
-
i += 8
|
133
|
-
end
|
134
|
-
|
135
|
-
if flag
|
136
|
-
i = 0
|
137
|
-
while (i < 256)
|
138
|
-
a+=@mm[i ]; b+=@mm[i+1]; c+=@mm[i+2]; d+=@mm[i+3];
|
139
|
-
e+=@mm[i+4]; f+=@mm[i+5]; g+=@mm[i+6]; h+=@mm[i+7];
|
140
|
-
a^=b<<11; d+=a; b+=c;
|
141
|
-
b^=0x3fffffff & (c>>2); e+=b; c+=d;
|
142
|
-
c^=d<<8; f+=c; d+=e;
|
143
|
-
d^=0x0000ffff & (e>>16); g+=d; e+=f;
|
144
|
-
e^=f<<10; h+=e; f+=g;
|
145
|
-
f^=0x0fffffff & (g>>4); a+=f; g+=h;
|
146
|
-
g^=h<<8; b+=g; h+=a;
|
147
|
-
h^=0x007fffff & (a>>9); c+=h; a+=b;
|
148
|
-
@mm[i ]=a; @mm[i+1]=b; @mm[i+2]=c; @mm[i+3]=d;
|
149
|
-
@mm[i+4]=e; @mm[i+5]=f; @mm[i+6]=g; @mm[i+7]=h;
|
150
|
-
i += 8
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
isaac()
|
155
|
-
@randcnt=256; # /* prepare to use the first set of results */
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
1
|
+
require 'crypt-isaac/crypt-isaac'
|
@@ -0,0 +1,158 @@
|
|
1
|
+
module Crypt
|
2
|
+
# ISAAC is a fast, strong random number generator. Details on the algorithm can be found
|
3
|
+
# here: http://burtleburtle.net/bob/rand/isaac.html
|
4
|
+
# This provides a consistent and capable algorithm for producing independent streams of quality random numbers.
|
5
|
+
class ISAAC
|
6
|
+
attr_accessor :randrsl, :randcnt
|
7
|
+
attr_accessor :mm, :aa, :bb, :cc
|
8
|
+
|
9
|
+
# When a Crypt::ISAAC object is created, it needs to be seeded for random number generation. If the system has a
|
10
|
+
# /dev/urandom file, that will be used to do the seeding by default. If false is explictly passed when creating the
|
11
|
+
# object, it will instead use /dev/random to generate its seeds. Be warned that this may make for SLOW
|
12
|
+
# initialization. If the requested source (/dev/urandom or /dev/random) do not exist, the system will fall back to
|
13
|
+
# a simplistic initialization mechanism using the builtin Mersenne Twister PRNG.
|
14
|
+
def initialize(noblock = true)
|
15
|
+
@mm = []
|
16
|
+
@randrsl = []
|
17
|
+
# Best initialization of the generator would be by pulling numbers from /dev/random.
|
18
|
+
rnd_source = noblock ? '/dev/urandom' : '/dev/random'
|
19
|
+
if (FileTest.exist? rnd_source)
|
20
|
+
File.open(rnd_source,'r') do |r|
|
21
|
+
256.times do |t|
|
22
|
+
z = r.read(4)
|
23
|
+
x = z.unpack('V')[0]
|
24
|
+
@randrsl[t] = x
|
25
|
+
end
|
26
|
+
end
|
27
|
+
else
|
28
|
+
# If urandom isn't available, the standard Ruby PRNG makes an adequate fallback.
|
29
|
+
256.times do |t|
|
30
|
+
@randrsl[t] = Kernel.rand(4294967295)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
randinit(true)
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
# Works just like the standard rand() function. If called with an integer argument, rand() will return positive
|
38
|
+
# random number in the range of 0 to (argument - 1). If called without an integer argument, rand() returns a
|
39
|
+
# positive floating point number less than 1.
|
40
|
+
def rand(*num)
|
41
|
+
if (@randcnt == 1)
|
42
|
+
isaac
|
43
|
+
@randcnt = 256
|
44
|
+
end
|
45
|
+
@randcnt -= 1
|
46
|
+
if num[0].to_i > 0
|
47
|
+
@randrsl[@randcnt].modulo(num[0])
|
48
|
+
else
|
49
|
+
".#{@randrsl[@randcnt]}".to_f
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def isaac
|
54
|
+
i = 0
|
55
|
+
x = 0
|
56
|
+
y = 0
|
57
|
+
|
58
|
+
@cc += 1
|
59
|
+
@bb += @cc
|
60
|
+
@bb & 0xffffffff
|
61
|
+
|
62
|
+
while (i < 256) do
|
63
|
+
x = @mm[i]
|
64
|
+
@aa = (@mm[(i + 128) & 255] + (@aa^(@aa << 13)) ) & 0xffffffff
|
65
|
+
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
66
|
+
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
67
|
+
i += 1
|
68
|
+
|
69
|
+
x = @mm[i]
|
70
|
+
@aa = (@mm[(i+128)&255] + (@aa^(0x03ffffff & (@aa >> 6))) ) & 0xffffffff
|
71
|
+
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
72
|
+
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
73
|
+
i += 1
|
74
|
+
|
75
|
+
x = @mm[i]
|
76
|
+
@aa = (@mm[(i + 128)&255] + (@aa^(@aa << 2)) ) & 0xffffffff
|
77
|
+
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
78
|
+
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
79
|
+
i += 1
|
80
|
+
|
81
|
+
x = @mm[i]
|
82
|
+
@aa = (@mm[(i+128)&255] + (@aa^(0x0000ffff & (@aa >> 16))) ) & 0xffffffff
|
83
|
+
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
84
|
+
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
85
|
+
i += 1
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def randinit(flag)
|
90
|
+
i = 0
|
91
|
+
a = 0
|
92
|
+
b = 0
|
93
|
+
c = 0
|
94
|
+
d = 0
|
95
|
+
e = 0
|
96
|
+
f = 0
|
97
|
+
g = 0
|
98
|
+
@aa = @bb = @cc = 0
|
99
|
+
a = b = c = d = e = f = g = h = 0x9e3779b9
|
100
|
+
|
101
|
+
while (i < 4) do
|
102
|
+
a ^= b<<1; d += a; b += c
|
103
|
+
b ^= 0x3fffffff & (c>>2); e += b; c += d
|
104
|
+
c ^= d << 8; f += c; d += e
|
105
|
+
d ^= 0x0000ffff & (e >> 16); g += d; e += f
|
106
|
+
e ^= f << 10; h += e; f += g
|
107
|
+
f ^= 0x0fffffff & (g >> 4); a += f; g += h
|
108
|
+
g ^= h << 8; b += g; h += a
|
109
|
+
h ^= 0x007fffff & (a >> 9); c += h; a += b
|
110
|
+
i += 1
|
111
|
+
end
|
112
|
+
|
113
|
+
i = 0
|
114
|
+
while (i < 256) do
|
115
|
+
if (flag)
|
116
|
+
a+=@randrsl[i ].to_i; b+=@randrsl[i+1].to_i;
|
117
|
+
c+=@randrsl[i+2]; d+=@randrsl[i+3];
|
118
|
+
e+=@randrsl[i+4]; f+=@randrsl[i+5];
|
119
|
+
g+=@randrsl[i+6]; h+=@randrsl[i+7];
|
120
|
+
end
|
121
|
+
|
122
|
+
a^=b<<11; d+=a; b+=c;
|
123
|
+
b^=0x3fffffff & (c>>2); e+=b; c+=d;
|
124
|
+
c^=d<<8; f+=c; d+=e;
|
125
|
+
d^=0x0000ffff & (e>>16); g+=d; e+=f;
|
126
|
+
e^=f<<10; h+=e; f+=g;
|
127
|
+
f^=0x0fffffff & (g>>4); a+=f; g+=h;
|
128
|
+
g^=h<<8; b+=g; h+=a;
|
129
|
+
h^=0x007fffff & (a>>9); c+=h; a+=b;
|
130
|
+
@mm[i]=a;@mm[i+1]=b; @mm[i+2]=c; @mm[i+3]=d;
|
131
|
+
@mm[i+4]=e; @mm[i+5]=f; @mm[i+6]=g; @mm[i+7]=h;
|
132
|
+
i += 8
|
133
|
+
end
|
134
|
+
|
135
|
+
if flag
|
136
|
+
i = 0
|
137
|
+
while (i < 256)
|
138
|
+
a+=@mm[i ]; b+=@mm[i+1]; c+=@mm[i+2]; d+=@mm[i+3];
|
139
|
+
e+=@mm[i+4]; f+=@mm[i+5]; g+=@mm[i+6]; h+=@mm[i+7];
|
140
|
+
a^=b<<11; d+=a; b+=c;
|
141
|
+
b^=0x3fffffff & (c>>2); e+=b; c+=d;
|
142
|
+
c^=d<<8; f+=c; d+=e;
|
143
|
+
d^=0x0000ffff & (e>>16); g+=d; e+=f;
|
144
|
+
e^=f<<10; h+=e; f+=g;
|
145
|
+
f^=0x0fffffff & (g>>4); a+=f; g+=h;
|
146
|
+
g^=h<<8; b+=g; h+=a;
|
147
|
+
h^=0x007fffff & (a>>9); c+=h; a+=b;
|
148
|
+
@mm[i ]=a; @mm[i+1]=b; @mm[i+2]=c; @mm[i+3]=d;
|
149
|
+
@mm[i+4]=e; @mm[i+5]=f; @mm[i+6]=g; @mm[i+7]=h;
|
150
|
+
i += 8
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
isaac()
|
155
|
+
@randcnt=256; # /* prepare to use the first set of results */
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
data/rakefile
CHANGED
@@ -1,56 +1,32 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
|
3
6
|
|
4
7
|
begin
|
5
8
|
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
9
|
+
Jeweler::Tasks.new do |gemspec|
|
10
|
+
gemspec.name = "crypt-isaac"
|
11
|
+
gemspec.summary = %q(Pure-Ruby implementation of the ISAAC PRNG.)
|
12
|
+
gemspec.email = "beawesomeinstead@yahoo.com"
|
13
|
+
gemspec.homepage = "http://github.com/bai/crypt-isaac"
|
14
|
+
gemspec.authors = ["beawesomeinstead"]
|
13
15
|
end
|
14
|
-
|
15
16
|
rescue LoadError
|
16
|
-
puts "Jeweler
|
17
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
test.verbose = true
|
20
|
+
Rake::TestTask.new do |t|
|
21
|
+
t.libs << 'lib'
|
22
|
+
t.pattern = 'test/**/*_test.rb'
|
23
|
+
t.verbose = false
|
24
24
|
end
|
25
25
|
|
26
|
-
begin
|
27
|
-
require 'rcov/rcovtask'
|
28
|
-
Rcov::RcovTask.new do |test|
|
29
|
-
test.libs << 'test'
|
30
|
-
test.pattern = 'test/**/*_test.rb'
|
31
|
-
test.verbose = true
|
32
|
-
end
|
33
|
-
rescue LoadError
|
34
|
-
task :rcov do
|
35
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
task :default => :test
|
41
|
-
|
42
|
-
require 'rake/rdoctask'
|
43
26
|
Rake::RDocTask.new do |rdoc|
|
44
|
-
if File.exist?('VERSION.yml')
|
45
|
-
config = YAML.load(File.read('VERSION.yml'))
|
46
|
-
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
-
else
|
48
|
-
version = ""
|
49
|
-
end
|
50
|
-
|
51
27
|
rdoc.rdoc_dir = 'rdoc'
|
52
|
-
rdoc.title =
|
28
|
+
rdoc.title = 'Jeweler'
|
29
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
53
30
|
rdoc.rdoc_files.include('README*')
|
54
31
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
32
|
end
|
56
|
-
|
data/test/crypt-isaac_test.rb
CHANGED
@@ -1,62 +1,59 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
3
|
class CryptIsaacTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
context "The Crypt:ISAAC object" do
|
5
|
+
setup do
|
6
|
+
assert_nothing_raised("Failed to create a Crypt::ISAAC object.") do
|
7
|
+
@generator = Crypt::ISAAC.new
|
8
|
+
end
|
7
9
|
end
|
8
|
-
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
should "be the proper type" do
|
12
|
+
assert_kind_of(Crypt::ISAAC, @generator, "The created object is not a Crypt::ISAAC or subclass thereof.")
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
should "generate an integer random number" do
|
16
|
+
assert_nothing_raised("Failed while generating an integer random number.") do
|
17
|
+
mynum = @generator.rand(1000000)
|
18
|
+
assert_kind_of(Integer, mynum, "The generator failed to return an integer number in response to @generator.rand(1000000).")
|
19
|
+
assert((mynum >= 0), "The generator returned a number that is less than 0 (#{mynum}).")
|
20
|
+
assert((mynum < 1000000), "The generator returned a number that is greater than or equal to 1000000 (#{mynum}).")
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
should "generate a floating point random number" do
|
25
|
+
assert_nothing_raised("Failed while generating a floating point random number.") do
|
26
|
+
mynum = @generator.rand()
|
27
|
+
assert_kind_of(Float, mynum, "The generator failed to return a floating point number in response to @generator.rand().")
|
28
|
+
assert((mynum >= 0), "The generator returned a number that is less than 0 (#{mynum}).")
|
29
|
+
assert((mynum < 1), "The generator returned a number that is greater than or equal to 1 (#{mynum}).")
|
30
|
+
end
|
29
31
|
end
|
30
|
-
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
x = @generator.rand(4294967295)
|
39
|
-
print [x].pack('V').unpack('H8') if count % 1000 == 0
|
40
|
-
if (count % 7000) == 0
|
41
|
-
print "\n"
|
42
|
-
else
|
43
|
-
print " " if count % 1000 == 0
|
33
|
+
should "be able to generate 100,000 random numbers" do
|
34
|
+
count = 0
|
35
|
+
assert_nothing_raised("Failed on iteration #{count} while trying to generate 100000 random numbers.") do
|
36
|
+
100000.times do
|
37
|
+
count += 1
|
38
|
+
@generator.rand(4294967295)
|
44
39
|
end
|
45
40
|
end
|
46
|
-
puts "\n100000 numbers generated"
|
47
41
|
end
|
48
42
|
end
|
49
43
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
44
|
+
context "Two Crypt:ISAAC objects" do
|
45
|
+
setup do
|
46
|
+
@generator1 = Crypt::ISAAC.new
|
47
|
+
@generator2 = Crypt::ISAAC.new
|
48
|
+
end
|
49
|
+
|
50
|
+
should "be able to generate numbers simultaneously" do
|
51
|
+
assert_nothing_raised("Failed to pull numbers from two independent streams.") do
|
52
|
+
assert((@generator1 != @generator2), "The generators are the same. This should not happen.")
|
53
|
+
1000.times do
|
54
|
+
@generator1.rand(4294967295)
|
55
|
+
@generator2.rand(4294967295)
|
56
|
+
end
|
60
57
|
end
|
61
58
|
end
|
62
59
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bai-crypt-isaac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- beawesomeinstead
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-03 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -20,20 +20,20 @@ executables: []
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
-
|
24
|
-
- README.rdoc
|
23
|
+
- README.markdown
|
25
24
|
files:
|
26
25
|
- .gitignore
|
27
|
-
-
|
28
|
-
- README.rdoc
|
26
|
+
- README.markdown
|
29
27
|
- VERSION
|
30
28
|
- crypt-isaac.gemspec
|
31
29
|
- lib/crypt-isaac.rb
|
30
|
+
- lib/crypt-isaac/crypt-isaac.rb
|
32
31
|
- rakefile
|
33
32
|
- test/crypt-isaac_test.rb
|
34
33
|
- test/test_helper.rb
|
35
|
-
has_rdoc:
|
34
|
+
has_rdoc: false
|
36
35
|
homepage: http://github.com/bai/crypt-isaac
|
36
|
+
licenses:
|
37
37
|
post_install_message:
|
38
38
|
rdoc_options:
|
39
39
|
- --charset=UTF-8
|
@@ -54,10 +54,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
requirements: []
|
55
55
|
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.
|
57
|
+
rubygems_version: 1.3.5
|
58
58
|
signing_key:
|
59
59
|
specification_version: 3
|
60
|
-
summary: Ruby implementation of the ISAAC PRNG
|
60
|
+
summary: Pure-Ruby implementation of the ISAAC PRNG.
|
61
61
|
test_files:
|
62
62
|
- test/crypt-isaac_test.rb
|
63
63
|
- test/test_helper.rb
|
data/LICENSE
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 beawesomeinstead
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
4
|
-
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
5
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
6
|
-
persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
-
|
8
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
9
|
-
Software.
|
10
|
-
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
12
|
-
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
13
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
14
|
-
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
Crypt::ISAAC README
|
2
|
-
============
|
3
|
-
|
4
|
-
ISAAC is a cryptographically secure PRNG for generating high quality random numbers. Detailed information about the
|
5
|
-
algorithm can be found at: http://burtleburtle.net/bob/rand/isaac.html
|
6
|
-
|
7
|
-
This is a pure Ruby implementation of the algorithm. It is reasonably fast for a pure Ruby implementation. On an 800Mhz
|
8
|
-
PIII computer running Ruby 1.8.2, and while the machine is also serving as general desktop, the library seems to
|
9
|
-
consistently generate between 15000 and 16000 random numbers per second.
|
10
|
-
|
11
|
-
Ruby uses the Mersenne Twister as its PRNG, and while this the Twister is a fast PRNG that produces highly random
|
12
|
-
numbers, it is not strong for cryptographic purposes, nor is it suitable when one needs multiple independent streams of
|
13
|
-
random numbers. Crypt::ISAAC is suitable for either purpose.
|
14
|
-
|
15
|
-
|
16
|
-
Requirements
|
17
|
-
------------
|
18
|
-
|
19
|
-
* Ruby 1.6
|
20
|
-
* Ruby 1.8
|
21
|
-
* Ruby 1.9
|
22
|
-
|
23
|
-
|
24
|
-
Install
|
25
|
-
-------
|
26
|
-
|
27
|
-
If you have never installed Crypt::ISAAC, you may run the testsuite to confirm that it works with:
|
28
|
-
|
29
|
-
# rake test
|
30
|
-
|
31
|
-
|
32
|
-
Usage
|
33
|
-
-----
|
34
|
-
|
35
|
-
require 'crypt-isaac'
|
36
|
-
|
37
|
-
rng = Crypt::ISAAC.new
|
38
|
-
|
39
|
-
r1 = rng.rand() # returns a floating point between 0 and 1
|
40
|
-
r2 = rng.rand(1000) # returns an integer between 0 and 999
|
41
|
-
|
42
|
-
rand() should work identically to the Kernel.rand().
|
43
|
-
|
44
|
-
Enjoy it. Let me know if you find anything that can be improved or that needs to be fixed.
|
45
|
-
|
46
|
-
|
47
|
-
License
|
48
|
-
-------
|
49
|
-
|
50
|
-
The Crypt::ISAAC library is licensed with an MIT style licence. See the LICENSE file for details. As for the ISAAC
|
51
|
-
algorithm itself, see: http://burtleburtle.net/bob/rand/isaac.html
|