crypt-rot13 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.0.4 - 24-Sep-2009
2
+ * Fixed a packaging bug.
3
+ * Added the 'gem' task to the Rakefile.
4
+ * Some documentation updates.
5
+
1
6
  == 1.0.3 - 1-Aug-2009
2
7
  * Changed license to Artistic 2.0.
3
8
  * Some gemspec updates, including license update.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Install the crypt-rot13 library (non-gem)'
5
+ task :install do
6
+ dest = File.join(Config::CONFIG['sitelibdir'], 'crypt')
7
+ Dir.mkdir(dest) unless File.exists? dest
8
+ cp 'lib/crypt/rot13.rb', dest, :verbose => true
9
+ end
10
+
11
+ desc 'Build the crypt-rot13 gem'
12
+ task :gem do
13
+ spec = eval(IO.read('crypt-rot13.gemspec'))
14
+ Gem::Builder.new(spec).build
15
+ end
16
+
17
+ desc 'Install the crypt-rot13 library as a gem'
18
+ task :install_gem => [:gem] do
19
+ file = Dir["*.gem"].first
20
+ sh "gem install #{file}"
21
+ end
22
+
23
+ Rake::TestTask.new do |t|
24
+ t.warning = true
25
+ t.verbose = true
26
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'crypt-rot13'
5
+ gem.version = '1.0.4'
6
+ gem.author = 'Daniel J. Berger'
7
+ gem.license = 'Artistic 2.0'
8
+ gem.email = 'djberg96@gmail.com'
9
+ gem.homepage = 'http://www.rubyforge.org/projects/shards'
10
+ gem.summary = 'Character rotation encryption, i.e. Caesar Cipher'
11
+ gem.test_file = 'test/test_crypt_rot13.rb'
12
+ gem.has_rdoc = true
13
+ gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
14
+
15
+ gem.rubyforge_project = 'shards'
16
+ gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
17
+
18
+ gem.description = <<-EOF
19
+ The crypt-rot13 library provides an interface for a simple character
20
+ substitution cipher known as ROT13, a variation on the Caesar cipher.
21
+ EOF
22
+ end
@@ -0,0 +1,53 @@
1
+ # The Crypt module serves as a namespace only.
2
+ module Crypt
3
+
4
+ # The Rot13 class encapsulates methods governing character rotation.
5
+ class Rot13 < String
6
+
7
+ # The Rot13::Error class is raised if an illegal rotation value is used.
8
+ class Error < ArgumentError; end
9
+
10
+ # The version of the crypt-rot13 library.
11
+ VERSION = '1.0.4'
12
+
13
+ # Returns a new Rot13 object. The object is a string with the letters
14
+ # each rotated by +degree+.
15
+ #
16
+ # You cannot use a multiple of 26 as the degree or a Rot13::Error will
17
+ # be raised. So, your days of double rot13 encryption are over.
18
+ #
19
+ def initialize(str='', degree=13)
20
+ str = rotate_string(str, degree) unless str.empty?
21
+ super(str)
22
+ end
23
+
24
+ # Rotates the Crypt::Rot13 object by +degree+.
25
+ #
26
+ def rotate(degree)
27
+ rotate_string(self, degree)
28
+ end
29
+
30
+ private
31
+
32
+ def rotate_string(str, degree)
33
+ case degree.modulo(26)
34
+ when 0
35
+ raise Error, 'degree must not be a multiple of 26'
36
+ when 13
37
+ str = str.tr('a-zA-Z', 'n-za-mN-ZA-M')
38
+ else
39
+ str = str.unpack('C' * str.length).map!{ |e|
40
+ if e >= 97 && e <= 122
41
+ e = ((e - 97 + degree) % 26) + 97
42
+ elsif e >= 65 && e <= 90
43
+ e = ((e - 65 + degree) % 26) + 65
44
+ else
45
+ e = e
46
+ end
47
+ }.pack('C' * str.length)
48
+ end
49
+
50
+ str
51
+ end
52
+ end
53
+ end
@@ -22,7 +22,7 @@ class TC_Rot13 < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  def test_version
25
- assert_equal('1.0.3', Rot13::VERSION)
25
+ assert_equal('1.0.4', Rot13::VERSION)
26
26
  end
27
27
 
28
28
  def test_constructor
@@ -43,7 +43,7 @@ class TC_Rot13 < Test::Unit::TestCase
43
43
  end
44
44
 
45
45
  def test_string_class
46
- assert_kind_of(String,@r1)
46
+ assert_kind_of(String, @r1)
47
47
  end
48
48
 
49
49
  def test_return_value_default_degree
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypt-rot13
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-01 00:00:00 -06:00
12
+ date: 2009-09-24 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,10 +24,13 @@ extra_rdoc_files:
24
24
  - CHANGES
25
25
  - MANIFEST
26
26
  files:
27
- - test/test_crypt_rot13.rb
28
- - README
29
27
  - CHANGES
28
+ - crypt-rot13.gemspec
29
+ - lib/crypt/rot13.rb
30
30
  - MANIFEST
31
+ - Rakefile
32
+ - README
33
+ - test/test_crypt_rot13.rb
31
34
  has_rdoc: true
32
35
  homepage: http://www.rubyforge.org/projects/shards
33
36
  licenses: