bkerley-affine 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -0
- data/VERSION.yml +1 -1
- data/affine.gemspec +2 -2
- data/lib/affine/cipher.rb +1 -1
- data/test/affine_test.rb +5 -5
- metadata +2 -2
data/Rakefile
CHANGED
data/VERSION.yml
CHANGED
data/affine.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{affine}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Bryce Kerley"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-16}
|
10
10
|
s.email = %q{bkerley@brycekerley.net}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
data/lib/affine/cipher.rb
CHANGED
@@ -41,7 +41,7 @@ module Affine
|
|
41
41
|
#
|
42
42
|
# == Argument
|
43
43
|
# [+ciphertext+] a single positive integer between 0 and the +modulus+
|
44
|
-
#
|
44
|
+
# for the cipher
|
45
45
|
def decipher(ciphertext)
|
46
46
|
raise RangeError.new(ciphertext, @modulus) if ciphertext > @modulus
|
47
47
|
(@a_inv * (ciphertext - @b_key)) % @modulus
|
data/test/affine_test.rb
CHANGED
@@ -14,16 +14,16 @@ class AffineTest < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
should 'encipher ITSCOOL correctly' do
|
16
16
|
# example from http://en.wikipedia.org/wiki/Affine_cipher
|
17
|
-
plain = 'ITSCOOL'.
|
17
|
+
plain = 'ITSCOOL'.unpack('CCCCCCC').map{ |c| c - 65}
|
18
18
|
coded = plain.map{ |c| @a.encipher c }
|
19
|
-
check ='WZUSAAL'.
|
19
|
+
check ='WZUSAAL'.unpack('CCCCCCC').map{ |c| c - 65}
|
20
20
|
assert_equal check, coded
|
21
21
|
end
|
22
22
|
should 'decipiher WZUSAAL correctly' do
|
23
23
|
# example from http://en.wikipedia.org/wiki/Affine_cipher
|
24
|
-
check ='WZUSAAL'.
|
24
|
+
check ='WZUSAAL'.unpack('CCCCCCC').map{ |c| c - 65}
|
25
25
|
coded = check.map{ |c| @a.decipher c }
|
26
|
-
plain = 'ITSCOOL'.
|
26
|
+
plain = 'ITSCOOL'.unpack('CCCCCCC').map{ |c| c - 65}
|
27
27
|
assert_equal plain, coded
|
28
28
|
end
|
29
29
|
end
|
@@ -41,7 +41,7 @@ class AffineTest < Test::Unit::TestCase
|
|
41
41
|
# I'm not doing this by hand
|
42
42
|
1000.times do
|
43
43
|
r = rand(123235150)
|
44
|
-
assert_equal r, @a.decipher(@a.encipher
|
44
|
+
assert_equal r, @a.decipher(@a.encipher(r))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bkerley-affine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce Kerley
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|