rot 0.2.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 kazuyoshi tlacaelel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,128 @@
1
+ = rot
2
+
3
+ Enables you to easily encrypt and decrypt from one alphabet to another, while being agnostinc and letting you define the translations..
4
+ it gives you the flexibility to use it for and with anything.
5
+
6
+ require 'rubygems'
7
+ require 'rot'
8
+
9
+ rot13_mappings = {"6"=>"6",
10
+ "V"=>"I",
11
+ "K"=>"X",
12
+ "v"=>"i",
13
+ "k"=>"x",
14
+ "7"=>"7",
15
+ "W"=>"J",
16
+ "L"=>"Y",
17
+ "A"=>"N",
18
+ "w"=>"j",
19
+ "l"=>"y",
20
+ "a"=>"n",
21
+ "8"=>"8",
22
+ "X"=>"K",
23
+ "M"=>"Z",
24
+ "B"=>"O",
25
+ "x"=>"k",
26
+ "m"=>"z",
27
+ "b"=>"o",
28
+ "9"=>"9",
29
+ "Y"=>"L",
30
+ "N"=>"A",
31
+ "C"=>"P",
32
+ "y"=>"l",
33
+ "n"=>"a",
34
+ "c"=>"p",
35
+ "Z"=>"M",
36
+ "O"=>"B",
37
+ "D"=>"Q",
38
+ "z"=>"m",
39
+ "o"=>"b",
40
+ "d"=>"q",
41
+ "P"=>"C",
42
+ "E"=>"R",
43
+ "p"=>"c",
44
+ "e"=>"r",
45
+ "1"=>"1",
46
+ "Q"=>"D",
47
+ "F"=>"S",
48
+ "q"=>"d",
49
+ "f"=>"s",
50
+ "2"=>"2",
51
+ "R"=>"E",
52
+ "G"=>"T",
53
+ "r"=>"e",
54
+ "g"=>"t",
55
+ "3"=>"3",
56
+ "S"=>"F",
57
+ "H"=>"U",
58
+ "s"=>"f",
59
+ "h"=>"u",
60
+ "4"=>"4",
61
+ "T"=>"G",
62
+ "I"=>"V",
63
+ "t"=>"g",
64
+ "i"=>"v",
65
+ "5"=>"5",
66
+ "U"=>"H",
67
+ "J"=>"W",
68
+ "u"=>"h",
69
+ "j"=>"w",
70
+ " "=>" "
71
+ }
72
+
73
+ # Handle unknown chars like this.
74
+ unknown = '?'
75
+
76
+ # this defines how chars should be parsed
77
+ encryption_tokenizer, decryption_tokenizer = /./, /./
78
+
79
+ rot = Rot.new rot13_mappings, unknown, encryption_tokenizer, decryption_tokenizer
80
+
81
+ puts rot.encrypt('This is a rot13 string') #=> "Guvf vf n ebg13 fgevat"
82
+ puts rot.decrypt('Guvf vf n ebg13 fgevat') #=> "This is a rot13 string"
83
+
84
+ # Now lets do a different thing!
85
+
86
+ mappings = {
87
+ '#' => 'd',
88
+ '!' => 'i',
89
+ '7' => 'f',
90
+ '"' => 'e',
91
+ '%' => 'r',
92
+ '&' => 'n',
93
+ '=' => 't',
94
+ }
95
+
96
+ rot.mappings = mappings
97
+
98
+ puts rot.encrypt('different') #=> '#!77"%"&='
99
+ puts rot.decrypt('#!77"%"&=') #=> 'different'
100
+
101
+ # Now something complex
102
+ complex = {
103
+ '<img src="d.jpg"/>' => 'd',
104
+ '<img src="i.jpg"/>' => 'i',
105
+ '<img src="f.jpg"/>' => 'f',
106
+ '<img src="e.jpg"/>' => 'e',
107
+ '<img src="r.jpg"/>' => 'r',
108
+ '<img src="n.jpg"/>' => 'n',
109
+ '<img src="t.jpg"/>' => 't',
110
+ '<img src="T.jpg"/>' => 'T',
111
+ '<img src="h.jpg"/>' => 'h',
112
+ '<img src="space.jpg"/>' => ' ',
113
+ '<img src="dot.jpg"/>' => '.',
114
+ }
115
+
116
+ rot.mappings = complex
117
+ rot.encryption_tokenizer = /./
118
+ rot.decryption_tokenizer = /<[^\>]+>/
119
+
120
+ puts rot.encrypt('different')
121
+ # => <img src="d.jpg"/><img src="i.jpg"/><img src="f.jpg"/><img src="f.jpg"/><img src="e.jpg"/><img src="r.jpg"/><img src="e.jpg"/><img src="n.jpg"/><img src="t.jpg"/>
122
+
123
+ puts rot.decrypt('<img src="T.jpg"/><img src="h.jpg"/><img src="e.jpg"/><img src="space.jpg"/><img src="e.jpg"/><img src="n.jpg"/><img src="d.jpg"/><img src="dot.jpg"/>')
124
+ # => The end.
125
+
126
+ == Copyright
127
+
128
+ Copyright (c) 2011 kazuyoshi tlacaelel. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rot"
8
+ gem.version = '0.2.0'
9
+ gem.summary = %Q{Simply translate from one alphabet to another.}
10
+ gem.description = %Q{Simple tool to help translating from one alphabet to another.}
11
+ gem.email = "kazu.dev@gmail.com"
12
+ gem.homepage = "http://github.com/ktlacaelel/rot"
13
+ gem.authors = ["kazuyoshi tlacaelel"]
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rot #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/lib/rot.rb ADDED
@@ -0,0 +1,20 @@
1
+ class Rot
2
+
3
+ attr_accessor :mappings, :unknown_mapping, :encryption_tokenizer, :decryption_tokenizer
4
+
5
+ def initialize mappings, unknown_mapping, encryption_tokenizer, decryption_tokenizer
6
+ @mappings = mappings
7
+ @unknown_mapping = unknown_mapping
8
+ @encryption_tokenizer = encryption_tokenizer
9
+ @decryption_tokenizer = decryption_tokenizer
10
+ end
11
+
12
+ def decrypt word
13
+ word.scan(@decryption_tokenizer).map { |char| @mappings[char] || @unknown_mapping } * ''
14
+ end
15
+
16
+ def encrypt word
17
+ word.scan(@encryption_tokenizer).map { |char| @mappings.invert[char] || @unknown_mapping } * ''
18
+ end
19
+
20
+ end
data/rot.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rot}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kazuyoshi tlacaelel"]
12
+ s.date = %q{2012-03-29}
13
+ s.description = %q{Simple tool to help translating from one alphabet to another.}
14
+ s.email = %q{kazu.dev@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/rot.rb",
26
+ "rot.gemspec",
27
+ "test/helper.rb",
28
+ "test/test_rot.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/ktlacaelel/rot}
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.7}
33
+ s.summary = %q{Simply translate from one alphabet to another.}
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
41
+ else
42
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
43
+ end
44
+ else
45
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
46
+ end
47
+ end
48
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rot'
8
+
9
+ class Test::Unit::TestCase
10
+ end
data/test/test_rot.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRot < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rot
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - kazuyoshi tlacaelel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-29 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Simple tool to help translating from one alphabet to another.
36
+ email: kazu.dev@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - lib/rot.rb
51
+ - rot.gemspec
52
+ - test/helper.rb
53
+ - test/test_rot.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/ktlacaelel/rot
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.7
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Simply translate from one alphabet to another.
88
+ test_files: []
89
+