caesar_cipher 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format p
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in caesar_cipher.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ caesar_cipher (0.0.1)
5
+ methadone (~> 1.2.4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aruba (0.5.1)
11
+ childprocess (~> 0.3.6)
12
+ cucumber (>= 1.1.1)
13
+ rspec-expectations (>= 2.7.0)
14
+ builder (3.1.4)
15
+ childprocess (0.3.7)
16
+ ffi (~> 1.0, >= 1.0.6)
17
+ coderay (1.0.8)
18
+ cucumber (1.2.1)
19
+ builder (>= 2.1.2)
20
+ diff-lcs (>= 1.1.3)
21
+ gherkin (~> 2.11.0)
22
+ json (>= 1.4.6)
23
+ diff-lcs (1.1.3)
24
+ ffi (1.3.1)
25
+ gherkin (2.11.6)
26
+ json (>= 1.7.6)
27
+ growl (1.0.3)
28
+ guard (1.6.1)
29
+ listen (>= 0.6.0)
30
+ lumberjack (>= 1.0.2)
31
+ pry (>= 0.9.10)
32
+ thor (>= 0.14.6)
33
+ guard-bundler (1.0.0)
34
+ bundler (~> 1.0)
35
+ guard (~> 1.1)
36
+ guard-rspec (2.4.0)
37
+ guard (>= 1.1)
38
+ rspec (~> 2.11)
39
+ json (1.7.6)
40
+ listen (0.7.2)
41
+ lumberjack (1.0.2)
42
+ methadone (1.2.4)
43
+ bundler
44
+ method_source (0.8.1)
45
+ pry (0.9.11.4)
46
+ coderay (~> 1.0.5)
47
+ method_source (~> 0.8)
48
+ slop (~> 3.4)
49
+ rake (0.9.6)
50
+ rb-fsevent (0.9.3)
51
+ rdoc (3.12)
52
+ json (~> 1.4)
53
+ rspec (2.12.0)
54
+ rspec-core (~> 2.12.0)
55
+ rspec-expectations (~> 2.12.0)
56
+ rspec-mocks (~> 2.12.0)
57
+ rspec-core (2.12.2)
58
+ rspec-expectations (2.12.1)
59
+ diff-lcs (~> 1.1.3)
60
+ rspec-mocks (2.12.1)
61
+ slop (3.4.3)
62
+ thor (0.16.0)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ aruba
69
+ caesar_cipher!
70
+ growl
71
+ guard
72
+ guard-bundler
73
+ guard-rspec
74
+ rake (~> 0.9.2)
75
+ rb-fsevent (~> 0.9.1)
76
+ rdoc
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'bundler' do
5
+ watch('Gemfile')
6
+ # Uncomment next line if Gemfile contain `gemspec' command
7
+ watch(/^.+\.gemspec/)
8
+ end
9
+
10
+ guard 'rspec' do
11
+ watch(%r{^spec/.+_spec\.rb$})
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch('spec/spec_helper.rb') { "spec" }
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [2013] [Raul Gracia Lario]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ ![Caesar Cipher](http://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Caesar3.svg/800px-Caesar3.svg.png)
2
+ ### Installation
3
+ ```bash
4
+ $ gem install caesar_cipher
5
+ ```
6
+ ### Usage
7
+ ##### Ruby Script
8
+
9
+ ```ruby
10
+ require 'caesar_cipher'
11
+
12
+ # with default shift of 4
13
+ caesar = CaesarCipher::Caesar.new
14
+ caesar.cipher "hello" # returns "lipps"
15
+ caesar.decipher "asvph" # returns "world"
16
+
17
+ # with different shift
18
+ caesar = CaesarCipher::Caesar.new 8
19
+ caesar.cipher "hello" # returns "pmttw"
20
+ caesar.decipher "ewztl" # returns "world"
21
+ ```
22
+
23
+ ##### Command Line
24
+
25
+ ```bash
26
+ $ caesar_cipher --help
27
+ Usage: caesar_cipher [options] text
28
+
29
+ Is a simple Caesar Cipher ruby implementation
30
+
31
+ v0.0.1
32
+
33
+ Options:
34
+ -h, --help Show command line help
35
+ --version Show help/version info
36
+ -d, --decipher Decipher
37
+ -s, --shift SHIFT Shift
38
+ (default: 4)
39
+ -o, --output FILE Output File
40
+
41
+
42
+ $ caesar_cipher "hello" # returns "lipps"
43
+ $ caesar_cipher -d "asvph" # returns "world"
44
+ $ caesar_cipher -s 8 "hello" # returns "pmttw"
45
+ $ caesar_cipher -s 8 -d "ewztl" # returns "world"
46
+ ```
data/README.rdoc ADDED
@@ -0,0 +1,60 @@
1
+ = caesar_cipher - Is a simple Caesar Cipher ruby implementation
2
+
3
+ Author:: Raul Gracia (maliciousmind) (raulgracialario@gmail.com)
4
+ Copyright:: Copyright (c) 2013 Raul Gracia
5
+
6
+
7
+ License:: apache, see LICENSE.txt
8
+
9
+
10
+
11
+ Is a simple Caesar Cipher ruby implementation
12
+
13
+ == Links
14
+
15
+ * {Source on Github}[https://github.com/maliciousmind/caesar_cipher]
16
+
17
+ == Install
18
+ gem install caesar_cipher
19
+ == Examples
20
+ ==== Ruby Script
21
+
22
+ require 'caesar_cipher'
23
+
24
+ # with default shift of 4
25
+ caesar = CaesarCipher::Caesar.new
26
+ caesar.cipher "hello" # returns "lipps"
27
+ caesar.decipher "asvph" # returns "world"
28
+
29
+ # with different shift
30
+ caesar = CaesarCipher::Caesar.new 8
31
+ caesar.cipher "hello" # returns "pmttw"
32
+ caesar.decipher "ewztl" # returns "world"
33
+
34
+ ==== Command Line
35
+
36
+
37
+ $ caesar_cipher --help
38
+ Usage: caesar_cipher [options] text
39
+
40
+ Is a simple Caesar Cipher ruby implementation
41
+
42
+ v0.0.1
43
+
44
+ Options:
45
+ -h, --help Show command line help
46
+ --version Show help/version info
47
+ -d, --decipher Decipher
48
+ -s, --shift SHIFT Shift
49
+ (default: 4)
50
+ -o, --output FILE Output File
51
+
52
+
53
+ $ caesar_cipher "hello" # returns "lipps"
54
+ $ caesar_cipher -d "asvph" # returns "world"
55
+ $ caesar_cipher -s 8 "hello" # returns "pmttw"
56
+ $ caesar_cipher -s 8 -d "ewztl" # returns "world"
57
+
58
+
59
+ == Contributing
60
+
data/Rakefile ADDED
@@ -0,0 +1,66 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+
29
+ begin
30
+ require 'rspec/core/rake_task'
31
+ rescue LoadError
32
+ dump_load_path
33
+ raise
34
+ end
35
+
36
+ require 'cucumber'
37
+ require 'cucumber/rake/task'
38
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
39
+ require 'rdoc/task'
40
+
41
+ include Rake::DSL
42
+
43
+ Bundler::GemHelper.install_tasks
44
+
45
+
46
+ RSpec::Core::RakeTask.new do |t|
47
+ # Put spec opts in a file named .rspec in root
48
+ end
49
+
50
+
51
+ CUKE_RESULTS = 'results.html'
52
+ CLEAN << CUKE_RESULTS
53
+ Cucumber::Rake::Task.new(:features) do |t|
54
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
55
+ t.fork = false
56
+ end
57
+
58
+ Rake::RDocTask.new do |rd|
59
+
60
+ rd.main = "README.rdoc"
61
+
62
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
63
+ end
64
+
65
+ task :default => [:spec,:features]
66
+
data/bin/caesar_cipher ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'caesar_cipher'
6
+
7
+ class App
8
+ include Methadone::Main
9
+ include Methadone::CLILogging
10
+
11
+ main do |text|
12
+ caesar = CaesarCipher::Caesar.new options[:shift]
13
+ output = ""
14
+ if options[:decipher]
15
+ output = caesar.decipher text
16
+ else
17
+ output = caesar.cipher text
18
+ end
19
+ if options[:output]
20
+ File.open(options[:output], 'w') {|f| f.write(output) }
21
+ else
22
+ puts output
23
+ end
24
+ end
25
+
26
+ version CaesarCipher::VERSION
27
+ description "Is a simple Caesar Cipher ruby implementation"
28
+ arg :text
29
+
30
+ on("-d","--decipher","Decipher")
31
+ options[:shift] = 4
32
+ on("-s SHIFT","--shift","Shift",/\d+$/)
33
+ on("-o FILE", "--output", "Output File")
34
+
35
+ go!
36
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'caesar_cipher'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "caesar_cipher"
8
+ gem.version = CaesarCipher::VERSION
9
+ gem.authors = ["Raul Gracia"]
10
+ gem.email = ["raulgracialario@gmail.com"]
11
+ gem.description = %q{Is a simple Caesar Cipher ruby implementation}
12
+ gem.summary = %q{Simple Caesar Cipher}
13
+ gem.homepage = "http://maliciousmind.github.com/caesar_cipher/"
14
+ gem.license = "Apache"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency('rdoc')
23
+ gem.add_development_dependency('aruba')
24
+ gem.add_development_dependency('rake', '~> 0.9.2')
25
+ gem.add_development_dependency('guard')
26
+ gem.add_development_dependency('guard-bundler')
27
+ gem.add_development_dependency('guard-rspec')
28
+ gem.add_development_dependency('growl')
29
+ gem.add_development_dependency('rb-fsevent', '~> 0.9.1')
30
+ gem.add_dependency('methadone', '~> 1.2.4')
31
+ end
@@ -0,0 +1,13 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "caesar_cipher"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And the banner should document that this app takes options
11
+ And the following options should be documented:
12
+ |--version|
13
+ And the banner should document that this app takes no arguments
@@ -0,0 +1 @@
1
+ # Put your step definitions here
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end
@@ -0,0 +1,44 @@
1
+ module CaesarCipher
2
+ VERSION = "0.0.1"
3
+
4
+ class Caesar
5
+
6
+ attr_reader :shift
7
+
8
+ def initialize(shift=4)
9
+ @shift = shift
10
+ @alphabet = %w{a b c d e f g h i j k l m n o p q r s t u v w x y z}
11
+ end
12
+
13
+ def cipher(text, shift=@shift)
14
+ caesar_algorithm :cipher, text, shift
15
+ end
16
+
17
+ def decipher(text, shift=@shift)
18
+ caesar_algorithm :decipher, text, shift
19
+ end
20
+
21
+
22
+ def correct_case(old_char, new_char)
23
+ if old_char.downcase == old_char
24
+ new_char.downcase
25
+ else
26
+ new_char.upcase
27
+ end
28
+ end
29
+
30
+ def caesar_algorithm(method, text, shift)
31
+ shift = method == :cipher ? shift : -shift
32
+ text.split("").map do |c|
33
+ if @alphabet.include? c.downcase
34
+ pos = @alphabet.index(c.downcase)
35
+ correct_case c, @alphabet.rotate(shift)[pos]
36
+ else
37
+ c
38
+ end
39
+ end.join
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,100 @@
1
+ describe CaesarCipher do
2
+ it 'should have a version number' do
3
+ CaesarCipher::VERSION.should_not be_nil
4
+ end
5
+
6
+ context "should initialize" do
7
+ it "with a default shift value" do
8
+ caesar = CaesarCipher::Caesar.new
9
+ caesar.shift.should eq(4)
10
+ end
11
+ it "with a specific shift value" do
12
+ caesar = CaesarCipher::Caesar.new 6
13
+ caesar.shift.should eq(6)
14
+ caesar = CaesarCipher::Caesar.new 8
15
+ caesar.shift.should eq(8)
16
+ caesar = CaesarCipher::Caesar.new 10
17
+ caesar.shift.should eq(10)
18
+ end
19
+ end
20
+
21
+ context "should cipher" do
22
+ context "without a shift value" do
23
+ context "a text" do
24
+ it "with alphabet characters" do
25
+ test_cipher "my name is raul", "qc reqi mw veyp"
26
+ test_cipher "THIS IS A TEST", "XLMW MW E XIWX"
27
+ test_cipher "caesar cipher", "geiwev gmtliv"
28
+ end
29
+ it "with non alphabet characters" do
30
+ test_cipher "my_name.is/raul", "qc_reqi.mw/veyp"
31
+ test_cipher "MY_NAME.IS/RAUL", "QC_REQI.MW/VEYP"
32
+ end
33
+ end
34
+ end
35
+ context "with a different shift value" do
36
+ context "a text" do
37
+ it "with alphabet characters" do
38
+ test_cipher "my name is raul", "oa pcog ku tcwn", 2
39
+ test_cipher "THIS IS A TEST", "YMNX NX F YJXY", 5
40
+ test_cipher "caesar cipher", "kimaiz kqxpmz", 8
41
+ end
42
+ it "with non alphabet characters" do
43
+ test_cipher "my_name.is/raul", "oa_pcog.ku/tcwn", 2
44
+ test_cipher "MY_NAME.IS/RAUL", "UG_VIUM.QA/ZICT", 8
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ context "should decipher" do
51
+ context "without a shift value" do
52
+ context "a text" do
53
+ it "with alphabet characters" do
54
+ test_decipher "my name is raul", "qc reqi mw veyp"
55
+ test_decipher "THIS IS A TEST", "XLMW MW E XIWX"
56
+ test_decipher "caesar cipher", "geiwev gmtliv"
57
+ end
58
+ it "with non alphabet characters" do
59
+ test_decipher "my_name.is/raul", "qc_reqi.mw/veyp"
60
+ test_decipher "MY_NAME.IS/RAUL", "QC_REQI.MW/VEYP"
61
+ end
62
+ end
63
+ end
64
+ context "with a different shift value" do
65
+ context "a text" do
66
+ it "with alphabet characters" do
67
+ test_decipher "my name is raul", "oa pcog ku tcwn", 2
68
+ test_decipher "THIS IS A TEST", "YMNX NX F YJXY", 5
69
+ test_decipher "caesar cipher", "kimaiz kqxpmz", 8
70
+ end
71
+ it "with non alphabet characters" do
72
+ test_decipher "my_name.is/raul", "oa_pcog.ku/tcwn", 2
73
+ test_decipher "MY_NAME.IS/RAUL", "UG_VIUM.QA/ZICT", 8
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+
81
+ def test_cipher(text, text_chipered, shift=nil)
82
+ if shift.nil?
83
+ caesar = CaesarCipher::Caesar.new
84
+ else
85
+ caesar = CaesarCipher::Caesar.new shift
86
+ end
87
+ output = caesar.cipher text
88
+ output.should eq(text_chipered)
89
+ end
90
+
91
+
92
+ def test_decipher(text, text_chipered, shift=nil)
93
+ if shift.nil?
94
+ caesar = CaesarCipher::Caesar.new
95
+ else
96
+ caesar = CaesarCipher::Caesar.new shift
97
+ end
98
+ output = caesar.decipher text_chipered
99
+ output.should eq(text)
100
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'caesar_cipher'
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caesar_cipher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Raul Gracia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: aruba
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.9.2
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.9.2
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-bundler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: growl
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rb-fsevent
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 0.9.1
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 0.9.1
158
+ - !ruby/object:Gem::Dependency
159
+ name: methadone
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ~>
164
+ - !ruby/object:Gem::Version
165
+ version: 1.2.4
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: 1.2.4
174
+ description: Is a simple Caesar Cipher ruby implementation
175
+ email:
176
+ - raulgracialario@gmail.com
177
+ executables:
178
+ - caesar_cipher
179
+ extensions: []
180
+ extra_rdoc_files: []
181
+ files:
182
+ - .gitignore
183
+ - .rspec
184
+ - Gemfile
185
+ - Gemfile.lock
186
+ - Guardfile
187
+ - LICENSE.txt
188
+ - README.md
189
+ - README.rdoc
190
+ - Rakefile
191
+ - bin/caesar_cipher
192
+ - caesar_cipher.gemspec
193
+ - features/caesar_cipher.feature
194
+ - features/step_definitions/caesar_cipher_steps.rb
195
+ - features/support/env.rb
196
+ - lib/caesar_cipher.rb
197
+ - spec/lib/caesar_cipher_spec.rb
198
+ - spec/spec_helper.rb
199
+ homepage: http://maliciousmind.github.com/caesar_cipher/
200
+ licenses:
201
+ - Apache
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ none: false
208
+ requirements:
209
+ - - ! '>='
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
212
+ required_rubygems_version: !ruby/object:Gem::Requirement
213
+ none: false
214
+ requirements:
215
+ - - ! '>='
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ requirements: []
219
+ rubyforge_project:
220
+ rubygems_version: 1.8.23
221
+ signing_key:
222
+ specification_version: 3
223
+ summary: Simple Caesar Cipher
224
+ test_files:
225
+ - features/caesar_cipher.feature
226
+ - features/step_definitions/caesar_cipher_steps.rb
227
+ - features/support/env.rb
228
+ - spec/lib/caesar_cipher_spec.rb
229
+ - spec/spec_helper.rb
230
+ has_rdoc: