Caesar.rb 1.0.1
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/README.markdown +4 -0
- data/lib/caesar.rb +22 -0
- metadata +47 -0
data/README.markdown
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
A simple implementation of the Caesar cipher in 22 lines of Ruby.
|
2
|
+
|
3
|
+
puts Ceasar.encipher(72,"HELLO WORLD! THIS IS AN ENCRYPTED MESSAGE.") => "BYFFI QILFX! NBCM CM UH YHWSJNYX GYMMUAY."
|
4
|
+
puts Ceasar.decipher(72,"BYFFI QILFX! NBCM CM UH YHWSJNYX GYMMUAY.") => "HELLO WORLD! THIS IS AN ENCRYPTED MESSAGE."
|
data/lib/caesar.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Caesar
|
2
|
+
def self.encipher(shift, message)
|
3
|
+
apply_algorithm(:encipher, shift, message)
|
4
|
+
end
|
5
|
+
def self.decipher(shift, message)
|
6
|
+
apply_algorithm(:decipher, shift, message)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def self.apply_algorithm(direction, shift, message)
|
12
|
+
letters = %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}
|
13
|
+
shift = direction == :encipher ? shift : -shift
|
14
|
+
message.upcase.split(//).map do |letter|
|
15
|
+
if letters.include?(letter)
|
16
|
+
letters.rotate(shift)[letters.index(letter)]
|
17
|
+
else
|
18
|
+
letter
|
19
|
+
end
|
20
|
+
end.join
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Caesar.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Rafaloff
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-30 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple implementation of the Caesar Cipher in 22 lines of Ruby.
|
15
|
+
email:
|
16
|
+
- hello@ericrafaloff.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/caesar.rb
|
22
|
+
- README.markdown
|
23
|
+
homepage: http://github.com/ericr/caesar.rb
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.10
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: A simple implementation of the Caesar Cipher in 22 lines of Ruby.
|
47
|
+
test_files: []
|