email-vigenere 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76a7e01160b0145c629284cadf8aaa52e3eb492a
4
- data.tar.gz: 47c3223efa9d67ea459250ae17db83088508e73f
3
+ metadata.gz: 6ef0d5cc0f2b9a98587bea279b8808c2b2a0071a
4
+ data.tar.gz: 702dc01e676d9d1840f9c64f18cc251f4b68c28a
5
5
  SHA512:
6
- metadata.gz: 197fa3bb649dd665d2dde4d9453aa66280290aa1c2145ff6afd6ecfad4f892a6f87256f02da92760f93ff5b579511e1b7709fbb3551db4ab18b4348068e404a4
7
- data.tar.gz: 84b4e599408a7ac5db4b65a5092345e4ca0c42628e3e780e549d94d2427ac1c62f64cb5c3a2040f7da6e28306a687cde48efd2c26115903ed6cb52bfbd2fa316
6
+ metadata.gz: 529530cd099fab6a1e3b1c2223f3cd2e0a54178629cc16f4d66e351d387542b1a903af5784ad604c6c71a7ef159f5efc26b2272010dd83a7a48c8c6fc8c63495
7
+ data.tar.gz: adf34e28bd552cc239eb7fb3710fa0fb49c66cca6dcf3563b02e068e43bf6ac7e5a6f0b0e6ea0c3ed055b6708a197f14b3e899c3868a5a8498a6aeaca0c83272
data/README.md CHANGED
@@ -1 +1,43 @@
1
1
  # vigenere
2
+
3
+ This is a simple gem for encoding email addresses with a vigenere cipher in a way that can be decoded later.
4
+
5
+ It can create an email address that contains an encoded version of the from and to email addresses. Then it can also parse such an address to later retrieve the original from and to addresses.
6
+
7
+ The key tells how much to rotate each letter by, so the trivial key 'a' (or 'aaaa', etc.) will not rotate at all and the encoded version will match the original.
8
+
9
+ ## Encoding
10
+
11
+ Use the ```encode``` method to encode with the cipher.
12
+
13
+ ```
14
+ VIGENERE::EmailCipher.new(key: 'foo').encode('hello')
15
+ ```
16
+
17
+ ## Decoding
18
+
19
+ Use ```decode``` to decode an encoded string to get the original
20
+
21
+ ```
22
+ VIGENERE::EmailCipher.new(key: 'foo').decode('mszqC')
23
+ ```
24
+
25
+ ## Encoding a pair of email addresses
26
+
27
+ Use ```create_email_address``` to create an email address that contains the original 2 email addresses encoded with the vigenere cipher. It takes the from address, the to address, and the domain as arguments.
28
+
29
+ ```
30
+ VIGENERE::EmailCipher.new(key: 'foo').create_email_address('test@example.com','test2@example.com','proxydomain.com')
31
+ ```
32
+
33
+ This will generate ```ysGyoa7jLo5ADqsoiqCr_ysGya8o6sLfa6AuzsfrqtA@proxydomain.com```
34
+
35
+ ## Getting the original pair of email addresses back
36
+
37
+ Then when we have an encoded email address like this, we can parse it for the original addresses with ```parse```
38
+
39
+ ```
40
+ VIGENERE::EmailCipher.new(key: 'foo').parse('ysGyoa7jLo5ADqsoiqCr_ysGya8o6sLfa6AuzsfrqtA@proxydomain.com')
41
+ ```
42
+
43
+ This will return a hash like this: ```{:from=>"test@example.com", :to=>"test2@example.com"}```
@@ -93,5 +93,27 @@ module VIGENERE
93
93
  end
94
94
  alpha_decode decoded
95
95
  end
96
+
97
+ def split_addresses str
98
+ from = str[0, str.index('_')]
99
+ to = str[str.index('_')+1, str.length]
100
+
101
+ addresses = { from: from, to: to }
102
+ end
103
+
104
+ def parse email_address
105
+ encoded_addresses_string = email_address[0, email_address.index('@')]
106
+
107
+ encoded_addresses = split_addresses encoded_addresses_string
108
+
109
+ from_addr = decode(encoded_addresses[:from])
110
+ to_addr = decode(encoded_addresses[:to])
111
+
112
+ {from: from_addr, to: to_addr}
113
+ end
114
+
115
+ def create_email_address(from, to, domain)
116
+ "#{encode(from)}_#{encode(to)}@#{domain}"
117
+ end
96
118
  end
97
119
  end
@@ -1,3 +1,3 @@
1
1
  module VIGENERE
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -2,6 +2,10 @@ require_relative '../lib/vigenere/email_cipher'
2
2
 
3
3
  RSpec.describe VIGENERE::EmailCipher do
4
4
 
5
+ def vigenere_key
6
+ '239^83&.7t7988J*'
7
+ end
8
+
5
9
  def encode_trivial str
6
10
  VIGENERE::EmailCipher.new(key: 'aaaaa').encode(str)
7
11
  end
@@ -15,9 +19,32 @@ RSpec.describe VIGENERE::EmailCipher do
15
19
  end
16
20
 
17
21
  def decode str
22
+ puts "key foo hello: #{VIGENERE::EmailCipher.new(key: 'foo').parse('ysGyoa7jLo5ADqsoiqCr_ysGya8o6sLfa6AuzsfrqtA@proxydomain.com')}"
18
23
  VIGENERE::EmailCipher.new(key: 'hello').decode(str)
19
24
  end
20
25
 
26
+ def encoded args={}
27
+ key = vigenere_key
28
+ key = args[:key] if args[:key] != nil
29
+ from = 'abc@def.com'
30
+ from = args[:from] if args[:from] != nil
31
+ to = 'ghi@jkl.com'
32
+ to = args[:to] if args[:to] != nil
33
+ ec = VIGENERE::EmailCipher.new(key: key)
34
+ "#{ec.encode(from)}_#{ec.encode(to)}@gofundbase.com"
35
+ end
36
+
37
+ def encoded_reply_address args={}
38
+ key = vigenere_key
39
+ key = args[:key] if args[:key] != nil
40
+ from = 'abc@def.com'
41
+ from = args[:from] if args[:from] != nil
42
+ to = 'ghi@jkl.com'
43
+ to = args[:to] if args[:to] != nil
44
+ ec = VIGENERE::EmailCipher.new(key: key)
45
+ "#{ec.encode(to)}_#{ec.encode(from)}@gofundbase.com"
46
+ end
47
+
21
48
  describe 'cycle' do
22
49
  it 'should cycle until the given length' do
23
50
  expect(VIGENERE::EmailCipher.new(key: 'hello').cycle(5)).to eq('hello')
@@ -75,4 +102,37 @@ RSpec.describe VIGENERE::EmailCipher do
75
102
  expect(decode encode 'hello@&a.com').to eq('hello@&a.com')
76
103
  end
77
104
  end
105
+
106
+ describe 'create email address' do
107
+ it 'should come up with a new email address for the receiver to reply to the sender' do
108
+ ec = VIGENERE::EmailCipher.new(key: vigenere_key)
109
+ expect(ec.create_email_address('ghi@jkl.com', 'abc@def.com', 'gofundbase.com')).to eq(encoded_reply_address)
110
+ end
111
+
112
+ it 'should be parsed correctly' do
113
+ ec = VIGENERE::EmailCipher.new(key: vigenere_key)
114
+ reply_addr = ec.create_email_address('ghi@jkl.com', 'abc@def.com', 'gofundbase.com')
115
+ expect(ec.parse(reply_addr)).to eq(from: 'ghi@jkl.com', to: 'abc@def.com')
116
+ end
117
+
118
+ it 'should work with underscores' do
119
+ ec = VIGENERE::EmailCipher.new(key: vigenere_key)
120
+ reply_addr = ec.create_email_address('gh_i@jk_l.com', 'a_bc@de_f.com', 'gofundbase.com')
121
+ expect(ec.parse(reply_addr)).to eq(from: 'gh_i@jk_l.com', to: 'a_bc@de_f.com')
122
+ end
123
+
124
+ it 'should work with dashes' do
125
+ ec = VIGENERE::EmailCipher.new(key: vigenere_key)
126
+ reply_addr = ec.create_email_address('gh-i@jk-l.com', 'a-bc@de-f.com', 'gofundbase.com')
127
+ expect(ec.parse(reply_addr)).to eq(from: 'gh-i@jk-l.com', to: 'a-bc@de-f.com')
128
+ end
129
+ end
130
+
131
+ describe 'parse email address' do
132
+ it 'should derive the original email addresses' do
133
+ expected = {from: 'abc@def.com', to: 'ghi@jkl.com'}
134
+ ec = VIGENERE::EmailCipher.new(key: vigenere_key)
135
+ expect(ec.parse(encoded)).to eq(expected)
136
+ end
137
+ end
78
138
  end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vigenere/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'email-vigenere'
8
+ spec.version = VIGENERE::VERSION
9
+ spec.authors = ['Fundbase']
10
+ spec.email = ['support@fundbase.com']
11
+ spec.summary = %q{ Encoding/Decoding text with Vigenere Cipher}
12
+ spec.description = %q{Easily Encode/Decode text with Vigenere Cipher}
13
+ spec.homepage = 'https://github.com/Fundbase/vigenere'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email-vigenere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fundbase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-29 00:00:00.000000000 Z
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Easily Encode/Decode text with Vigenere Cipher
14
14
  email:
@@ -28,6 +28,7 @@ files:
28
28
  - lib/vigenere/version.rb
29
29
  - spec/email_cipher_spec.rb
30
30
  - spec/spec_helper.rb
31
+ - vigenere.gemspec
31
32
  homepage: https://github.com/Fundbase/vigenere
32
33
  licenses:
33
34
  - MIT
@@ -48,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
49
  version: '0'
49
50
  requirements: []
50
51
  rubyforge_project:
51
- rubygems_version: 2.4.6
52
+ rubygems_version: 2.2.2
52
53
  signing_key:
53
54
  specification_version: 4
54
55
  summary: Encoding/Decoding text with Vigenere Cipher