polybius-square 0.0.1 → 0.1.0

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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in polybius-square.gemspec
4
4
  gemspec
5
+
6
+ gem 'rspec'
@@ -0,0 +1,21 @@
1
+ module PolybiusSquare
2
+ class AlphaList
3
+
4
+ attr_reader :list
5
+
6
+ def initialize(options={})
7
+ offset = options[:offset]
8
+ dropped = options[:dropped]
9
+
10
+ @list = %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
+ @list.delete(dropped)
12
+
13
+ if offset
14
+ shifted = list.shift(offset)
15
+ @list = list + shifted
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,15 @@
1
+ module PolybiusSquare
2
+ class ConverterEngine
3
+ def initialize(encoded_string)
4
+
5
+ list = %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 ]
6
+
7
+ list.each do |dropped_letter|
8
+ (1..26).each do |offset|
9
+ PolybiusSquare::PolybiusSquareProcessor.new(:encoded_string => encoded_string, :list_offset => offset, :dropped_char => dropped_letter).process
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ require 'alpha_list'
2
+ require 'polybius_square'
3
+ require 'polybius_square_processor'
4
+ require 'converter_engine'
5
+
6
+ module PolybiusSquare
7
+ class PolybiusSquare
8
+
9
+ def initialize(alpha_list)
10
+ @alpha_grid = {}
11
+ count = 0
12
+
13
+ (1..5).each do |row|
14
+ (1..5).each do |col|
15
+
16
+ key = row.to_s + col.to_s
17
+ value = alpha_list[count]
18
+
19
+ @alpha_grid.merge!({key => value})
20
+ count += 1
21
+ end
22
+ end
23
+ end
24
+
25
+ def value_at(position)
26
+ @alpha_grid["#{position}"]
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ module PolybiusSquare
2
+ class PolybiusSquare
3
+
4
+ def initialize(alpha_list)
5
+ @alpha_grid = {}
6
+ count = 0
7
+
8
+ (1..5).each do |row|
9
+ (1..5).each do |col|
10
+
11
+ key = row.to_s + col.to_s
12
+ value = alpha_list[count]
13
+
14
+ @alpha_grid.merge!({key => value})
15
+ count += 1
16
+ end
17
+ end
18
+ end
19
+
20
+ def value_at(position)
21
+ @alpha_grid["#{position}"]
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module PolybiusSquare
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ module PolybiusSquare
2
+ class PolybiusSquareProcessor
3
+
4
+ def self.process(options={})
5
+ encoded_string = options[:encoded_string] || ""
6
+ list_offset = options[:list_offset].to_i || 0
7
+ dropped_char = options[:dropped_char].to_s || ''
8
+
9
+ alpha_list = AlphaList.new(:offset => list_offset, :dropped => dropped_char)
10
+ alpha_grid = PolybiusSquare.new(alpha_list.list)
11
+
12
+ sentence = ''
13
+ encoded_string.split(' ').each do |line|
14
+ numbers = line.split("-")
15
+ word = ""
16
+ numbers.each do |number|
17
+ word += alpha_grid.value_at(number)
18
+ end
19
+ sentence += word + " "
20
+ end
21
+
22
+ return sentence.strip!
23
+ end
24
+ end
25
+ end
@@ -1,15 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'polybius-square/version'
4
+ require 'polybius_square/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "polybius-square"
8
- gem.version = Polybius::Square::VERSION
8
+ gem.version = PolybiusSquare::VERSION
9
9
  gem.authors = ["Nathan Wise"]
10
10
  gem.email = ["nathanwise@gmail.com"]
11
- gem.description = %q{Polybius Square encoder/decoder}
12
- gem.summary = %q{Allows creation of Polybius Squares for encoding and decoding messages.}
11
+ gem.description = %q{Polybius Square decoder}
12
+ gem.summary = %q{Allows creation of Polybius Squares for decoding messages.}
13
13
  gem.homepage = ""
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe PolybiusSquare::AlphaList do
4
+
5
+ subject { PolybiusSquare::AlphaList }
6
+ let (:offset) { 5 }
7
+
8
+ context "When initialzed with no parameters" do
9
+ it "creates a list of letters" do
10
+ subject.new.list.should == %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
+ end
13
+
14
+ context "When initialized with and \"offset\" parameter" do
15
+ it "creates a list of letters starting at the position of the offset parameter" do
16
+ subject.new(:offset => offset).list.should == %w[ f g h i j k l m n o p q r s t u v w x y z a b c d e]
17
+ end
18
+ end
19
+
20
+ context "When initialized with a \"dropped\" parameter" do
21
+ it "creates a list of letters without the dropped parameter" do
22
+ subject.new(:dropped => 'f').list.include?('f').should_not be_true
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "PolybiusSquare::PolybiusSquareProcessor" do
4
+
5
+ subject { PolybiusSquare::PolybiusSquareProcessor }
6
+
7
+ describe ".process" do
8
+ it "should convert the \"encoded_string\" parameter succesfully" do
9
+ subject.process(:encoded_string => "53-24-34").should == 'win'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe PolybiusSquare::PolybiusSquare do
4
+
5
+ subject { PolybiusSquare::PolybiusSquare }
6
+
7
+ let(:list) { PolybiusSquare::AlphaList.new.list }
8
+
9
+ describe "Initialization" do
10
+ it "assigns the lettes in list to a 5x5 grid" do
11
+ grid = subject.new(list)
12
+
13
+ grid.value_at("11").should == 'a'
14
+ grid.value_at("12").should == 'b'
15
+ grid.value_at("13").should == 'c'
16
+ grid.value_at("14").should == 'd'
17
+ grid.value_at("15").should == 'e'
18
+ grid.value_at("21").should == 'f'
19
+ grid.value_at("22").should == 'g'
20
+ grid.value_at("23").should == 'h'
21
+ grid.value_at("24").should == 'i'
22
+ grid.value_at("25").should == 'j'
23
+ grid.value_at("31").should == 'k'
24
+ grid.value_at("32").should == 'l'
25
+ grid.value_at("33").should == 'm'
26
+ grid.value_at("34").should == 'n'
27
+ grid.value_at("35").should == 'o'
28
+ grid.value_at("41").should == 'p'
29
+ grid.value_at("42").should == 'q'
30
+ grid.value_at("43").should == 'r'
31
+ grid.value_at("44").should == 's'
32
+ grid.value_at("45").should == 't'
33
+ grid.value_at("51").should == 'u'
34
+ grid.value_at("52").should == 'v'
35
+ grid.value_at("53").should == 'w'
36
+ grid.value_at("54").should == 'x'
37
+ grid.value_at("55").should == 'y'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ require 'polybius_square'
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polybius-square
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-10-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: Polybius Square encoder/decoder
14
+ description: Polybius Square decoder
15
15
  email:
16
16
  - nathanwise@gmail.com
17
17
  executables: []
@@ -19,13 +19,22 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
+ - .rspec
22
23
  - Gemfile
23
24
  - LICENSE.txt
24
25
  - README.md
25
26
  - Rakefile
26
- - lib/polybius-square.rb
27
- - lib/polybius-square/version.rb
27
+ - lib/alpha_list.rb
28
+ - lib/converter_engine.rb
29
+ - lib/polybius_square.rb
30
+ - lib/polybius_square/polybius_square.rb
31
+ - lib/polybius_square/version.rb
32
+ - lib/polybius_square_processor.rb
28
33
  - polybius-square.gemspec
34
+ - spec/alpha_list_spec.rb
35
+ - spec/polybius_square_processor_spec.rb
36
+ - spec/polybius_square_spec.rb
37
+ - spec/spec_helper.rb
29
38
  homepage: ''
30
39
  licenses: []
31
40
  post_install_message:
@@ -49,5 +58,9 @@ rubyforge_project:
49
58
  rubygems_version: 1.8.24
50
59
  signing_key:
51
60
  specification_version: 3
52
- summary: Allows creation of Polybius Squares for encoding and decoding messages.
53
- test_files: []
61
+ summary: Allows creation of Polybius Squares for decoding messages.
62
+ test_files:
63
+ - spec/alpha_list_spec.rb
64
+ - spec/polybius_square_processor_spec.rb
65
+ - spec/polybius_square_spec.rb
66
+ - spec/spec_helper.rb
@@ -1,7 +0,0 @@
1
- require "polybius-square/version"
2
-
3
- module Polybius
4
- module Square
5
- # Your code goes here...
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- module Polybius
2
- module Square
3
- VERSION = "0.0.1"
4
- end
5
- end