email-vigenere 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 76a7e01160b0145c629284cadf8aaa52e3eb492a
4
+ data.tar.gz: 47c3223efa9d67ea459250ae17db83088508e73f
5
+ SHA512:
6
+ metadata.gz: 197fa3bb649dd665d2dde4d9453aa66280290aa1c2145ff6afd6ecfad4f892a6f87256f02da92760f93ff5b579511e1b7709fbb3551db4ab18b4348068e404a4
7
+ data.tar.gz: 84b4e599408a7ac5db4b65a5092345e4ca0c42628e3e780e549d94d2427ac1c62f64cb5c3a2040f7da6e28306a687cde48efd2c26115903ed6cb52bfbd2fa316
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ group :test do
2
+ gem 'rspec'
3
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Volodymyr Shatsky
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # vigenere
data/lib/vigenere.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'vigenere/version'
2
+ require 'vigenere/email_cipher'
@@ -0,0 +1,97 @@
1
+ module VIGENERE
2
+ class EmailCipher
3
+ def initialize(args = {})
4
+ @alphabet = []
5
+
6
+ # TODO: Add any characters that need to work here
7
+ @alphabet.concat(('a'..'z').to_a)
8
+ @alphabet.concat(('A'..'Z').to_a)
9
+ @alphabet.concat(('0'..'9').to_a)
10
+ @alphabet.concat(['&','*','+','-','/','=','?','^','_','`','~','.'])
11
+ @key = args[:key]
12
+ end
13
+
14
+ def cycle(length)
15
+ @key.chars.cycle.inject('') do |str, char|
16
+ return str if str.length == length
17
+ str + char
18
+ end
19
+ end
20
+
21
+ def alpha_encode(str)
22
+ str = str.gsub('a','a0')
23
+ str = str.gsub('@','a1')
24
+ str = str.gsub('&','a2')
25
+ str = str.gsub('*','a3')
26
+ str = str.gsub('+','a4')
27
+ str = str.gsub('-','a5')
28
+ str = str.gsub('/','a6')
29
+ str = str.gsub('=','a7')
30
+ str = str.gsub('?','a8')
31
+ str = str.gsub('^','a9')
32
+ str = str.gsub('_','aa')
33
+ str = str.gsub('`','ab')
34
+ str = str.gsub('~','ac')
35
+ str = str.gsub('.','ad')
36
+ str
37
+ end
38
+
39
+ def alpha_decode(str)
40
+ decoded = ''
41
+ escaping = false
42
+ escaped = false
43
+ str.chars.each_with_index do |char, i|
44
+ if escaping then
45
+ decoded << 'a' if char == '0'
46
+ decoded << '@' if char == '1'
47
+ decoded << '&' if char == '2'
48
+ decoded << '*' if char == '3'
49
+ decoded << '+' if char == '4'
50
+ decoded << '-' if char == '5'
51
+ decoded << '/' if char == '6'
52
+ decoded << '=' if char == '7'
53
+ decoded << '?' if char == '8'
54
+ decoded << '^' if char == '9'
55
+ decoded << '_' if char == 'a'
56
+ decoded << '`' if char == 'b'
57
+ decoded << '~' if char == 'c'
58
+ decoded << '.' if char == 'd'
59
+ escaping = false
60
+ elsif char == 'a' then
61
+ escaping = true
62
+ else
63
+ decoded << char
64
+ end
65
+ end
66
+ decoded
67
+ end
68
+
69
+ def encode(str)
70
+ encoded = ''
71
+ str = alpha_encode str
72
+ cycled_key = cycle (str.length)
73
+ str.chars.each_with_index do |char, i|
74
+ cipher_index = @alphabet.find_index(cycled_key[i])
75
+ char_index = @alphabet.find_index(char)
76
+ enc_char_index = (char_index + cipher_index) % @alphabet.length
77
+ enc_char = @alphabet[enc_char_index]
78
+ encoded << enc_char
79
+ end
80
+ alpha_encode encoded
81
+ end
82
+
83
+ def decode(str)
84
+ cycled_key = cycle str.length
85
+ decoded = ''
86
+ str = alpha_decode str
87
+ str.chars.each_with_index do |char, i|
88
+ cipher_index = @alphabet.find_index(cycled_key[i])
89
+ char_index = @alphabet.find_index(char)
90
+ dec_char_index = (char_index - cipher_index) % @alphabet.length
91
+ dec_char = @alphabet[dec_char_index]
92
+ decoded << dec_char
93
+ end
94
+ alpha_decode decoded
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,3 @@
1
+ module VIGENERE
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,78 @@
1
+ require_relative '../lib/vigenere/email_cipher'
2
+
3
+ RSpec.describe VIGENERE::EmailCipher do
4
+
5
+ def encode_trivial str
6
+ VIGENERE::EmailCipher.new(key: 'aaaaa').encode(str)
7
+ end
8
+
9
+ def decode_trivial str
10
+ VIGENERE::EmailCipher.new(key: 'aaaaa').decode(str)
11
+ end
12
+
13
+ def encode str
14
+ VIGENERE::EmailCipher.new(key: 'hello').encode(str)
15
+ end
16
+
17
+ def decode str
18
+ VIGENERE::EmailCipher.new(key: 'hello').decode(str)
19
+ end
20
+
21
+ describe 'cycle' do
22
+ it 'should cycle until the given length' do
23
+ expect(VIGENERE::EmailCipher.new(key: 'hello').cycle(5)).to eq('hello')
24
+ expect(VIGENERE::EmailCipher.new(key: 'hello').cycle(20)).to eq('hellohellohellohello')
25
+ expect(VIGENERE::EmailCipher.new(key: 'hello').cycle(3)).to eq('hel')
26
+ expect(VIGENERE::EmailCipher.new(key: 'hello').cycle(6)).to eq('helloh')
27
+ end
28
+ end
29
+
30
+ describe 'encode' do
31
+ it 'should return a different string' do
32
+ expect(encode 'hello').not_to eq('hello')
33
+ expect(encode 'world').not_to eq('world')
34
+ end
35
+
36
+ it 'should give back the original with a trivial key' do
37
+ expect(encode_trivial 'hello').to eq('hello')
38
+ end
39
+
40
+ it 'should not return 2 consecutive dots' do
41
+ # because that is not valid in the local part of an email address
42
+ expect(encode_trivial 'some..dots').not_to include('..')
43
+ end
44
+
45
+ it 'should not return starting or ending with a dot' do
46
+ # because that is not valid in the local part of an email address
47
+ expect(encode_trivial '.somedots.').not_to start_with('.')
48
+ expect(encode_trivial '.somedots.').not_to end_with('.')
49
+ end
50
+
51
+ it 'should give back the original when trivially decoded with dots' do
52
+ expect(decode_trivial encode_trivial 'some..dots').to eq('some..dots')
53
+ expect(decode_trivial encode_trivial '.somedots.').to eq('.somedots.')
54
+ end
55
+
56
+ it 'should give back the original when trivially decoded with dots and ampersands' do
57
+ expect(decode_trivial encode_trivial 'some&.&&.&dots').to eq('some&.&&.&dots')
58
+ end
59
+
60
+ it 'should give back the original when decoded' do
61
+ expect(decode encode 'hello').to eq('hello')
62
+ expect(decode encode 'world').to eq('world')
63
+ end
64
+
65
+ it 'should work for strings longer than the key' do
66
+ expect(decode encode 'helloworldfoobar').to eq('helloworldfoobar')
67
+ end
68
+
69
+ it 'should work with dots' do
70
+ expect(decode encode 'hello.world').to eq('hello.world')
71
+ end
72
+
73
+ it 'should work with an encoded at sign' do
74
+ expect(decode encode '&a@hello.com').to eq('&a@hello.com')
75
+ expect(decode encode 'hello@&a.com').to eq('hello@&a.com')
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,78 @@
1
+ require 'vigenere'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+
24
+
25
+ # rspec-mocks config goes here. You can use an alternate test double
26
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
27
+ config.mock_with :rspec do |mocks|
28
+ # Prevents you from mocking or stubbing a method that does not exist on
29
+ # a real object. This is generally recommended, and will default to
30
+ # `true` in RSpec 4.
31
+ mocks.verify_partial_doubles = true
32
+ end
33
+
34
+ # These two settings work together to allow you to limit a spec run
35
+ # to individual examples or groups you care about by tagging them with
36
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
37
+ # get run.
38
+ config.filter_run :focus
39
+ config.run_all_when_everything_filtered = true
40
+
41
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
42
+ # For more details, see:
43
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
44
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
45
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
46
+ config.disable_monkey_patching!
47
+
48
+ # This setting enables warnings. It's recommended, but in some cases may
49
+ # be too noisy due to issues in dependencies.
50
+ config.warnings = false
51
+
52
+ # Many RSpec users commonly either run the entire suite or an individual
53
+ # file, and it's useful to allow more verbose output when running an
54
+ # individual spec file.
55
+ if config.files_to_run.one?
56
+ # Use the documentation formatter for detailed output,
57
+ # unless a formatter has already been configured
58
+ # (e.g. via a command-line flag).
59
+ config.default_formatter = 'doc'
60
+ end
61
+
62
+ # Print the 10 slowest examples and example groups at the
63
+ # end of the spec run, to help surface which specs are running
64
+ # particularly slow.
65
+ config.profile_examples = 10
66
+
67
+ # Run specs in random order to surface order dependencies. If you find an
68
+ # order dependency and want to debug it, you can fix the order by providing
69
+ # the seed, which is printed after each run.
70
+ # --seed 1234
71
+ config.order = :random
72
+
73
+ # Seed global randomization in this process using the `--seed` CLI option.
74
+ # Setting this allows you to use `--seed` to deterministically reproduce
75
+ # test failures related to randomization by passing the same `--seed` value
76
+ # as the one that triggered the failure.
77
+ Kernel.srand config.seed
78
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email-vigenere
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fundbase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Easily Encode/Decode text with Vigenere Cipher
14
+ email:
15
+ - support@fundbase.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".ruby-version"
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - lib/vigenere.rb
27
+ - lib/vigenere/email_cipher.rb
28
+ - lib/vigenere/version.rb
29
+ - spec/email_cipher_spec.rb
30
+ - spec/spec_helper.rb
31
+ homepage: https://github.com/Fundbase/vigenere
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.4.6
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Encoding/Decoding text with Vigenere Cipher
55
+ test_files:
56
+ - spec/email_cipher_spec.rb
57
+ - spec/spec_helper.rb