test/affine_test.rb in bkerley-affine-0.2.2 vs test/affine_test.rb in bkerley-affine-0.2.3
- old
+ new
@@ -12,20 +12,20 @@
end
end
should 'encipher ITSCOOL correctly' do
# example from http://en.wikipedia.org/wiki/Affine_cipher
- plain = 'ITSCOOL'.split('').map{ |c| c[0] - 65}
+ plain = 'ITSCOOL'.unpack('CCCCCCC').map{ |c| c - 65}
coded = plain.map{ |c| @a.encipher c }
- check ='WZUSAAL'.split('').map{ |c| c[0] - 65}
+ check ='WZUSAAL'.unpack('CCCCCCC').map{ |c| c - 65}
assert_equal check, coded
end
should 'decipiher WZUSAAL correctly' do
# example from http://en.wikipedia.org/wiki/Affine_cipher
- check ='WZUSAAL'.split('').map{ |c| c[0] - 65}
+ check ='WZUSAAL'.unpack('CCCCCCC').map{ |c| c - 65}
coded = check.map{ |c| @a.decipher c }
- plain = 'ITSCOOL'.split('').map{ |c| c[0] - 65}
+ plain = 'ITSCOOL'.unpack('CCCCCCC').map{ |c| c - 65}
assert_equal plain, coded
end
end
context 'affine cipher 65182241782, 123235151 mod 2176782371' do
@@ -39,10 +39,10 @@
end
should 'pass a few random identity checks' do
# I'm not doing this by hand
1000.times do
r = rand(123235150)
- assert_equal r, @a.decipher(@a.encipher r)
+ assert_equal r, @a.decipher(@a.encipher(r))
end
end
end
end