tripcode 0.2.6 → 1.0.0

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: 71222108c69c621b27db58a7e3a5ac6cf6888d3d
4
- data.tar.gz: 01d0bca9bf89c0d12203dd3cc25bf31af62a41a5
3
+ metadata.gz: b92e292ca46ce259ea177295d6da4f2e132daaf8
4
+ data.tar.gz: dbed9b4b6843d3bb102cad6b2f3209c60d25a171
5
5
  SHA512:
6
- metadata.gz: 46792708df02ad312379aec2257d087d6101bf7a7940e364dcbde1695b12c9b380cef339e430c07d897124f69889d0490be6376c20900f009b52febe408064c2
7
- data.tar.gz: d7b7e815218a1ca214b2beb79e56d78e1464ff6865c07e0cacd05c3ca7b6d08cdbd361e5eeae2ff81909f73ed1e1281ab44334265e7c31540f290b141596d138
6
+ metadata.gz: 5e729f3fa6e6e9662929f94d4dc997fa9c24947a36d220b6b907597445010144e703dcd48eecbb77c2cd2b99d0184a6985271f19a88e8c368c5c2fb182b16449
7
+ data.tar.gz: 52a1b4b565f778a7dfc6b59c7b970c8381a05e46fc2912a809946ea94f783240e0f01aeeb15e70998579c6cfdf7300109b6e0b5e85a3a88218fdc7d0d7856d7e
data/README.md CHANGED
@@ -23,7 +23,12 @@ Or install it yourself as:
23
23
 
24
24
  ```ruby
25
25
  require 'tripcode'
26
- Tripcode.hash('github') # => lLf/rxkwgg
26
+
27
+ Tripcode.hash('github') # => lLf/rxkwg
28
+ Tripcode.secure('github') # => 'qhOg87mFbSndQap'
29
+ Tripcode.secure('github','secret') # => 'ND8xVvinnkdyYkC'
30
+ Tripcode.parse('User#password#password') # => ['User', 'ozOtJW9BFA', 'y65WdWQD6Zze1n3']
31
+ Tripcode.parse('User#password#password', 'secret') # => ["User", "ozOtJW9BFA", "XGgRxzLJkVB/xA/"]
27
32
  ```
28
33
 
29
34
  Or from the terminal
@@ -33,15 +38,12 @@ Or from the terminal
33
38
 
34
39
  ## Development
35
40
 
36
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
-
38
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`.
39
42
 
40
43
  ## Contributing
41
44
 
42
45
  Bug reports and pull requests are welcome on GitHub at https://github.com/justinjensen/tripcode.
43
46
 
44
-
45
47
  ## License
46
48
 
47
49
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/lib/tripcode.rb CHANGED
@@ -1,27 +1,46 @@
1
- require "tripcode/version"
1
+ require 'tripcode/version'
2
+ require 'digest/sha1'
3
+ require 'base64'
2
4
 
3
5
  module Tripcode
4
- def self.sjis(str)
5
- str.encode('shift_jis', 'utf-8', invalid: :replace, undef: :replace, replace: '')
6
+ def self.hash(password)
7
+ return "" if password.nil? || password.empty?
8
+ password = password.encode('SHIFT_JIS', 'UTF-8', undef: :replace)
9
+ password.gsub!('"', '"')
10
+ password.gsub!('&', '&')
11
+ password.gsub!('>', '>')
12
+ password.gsub!('<', '&lt;')
13
+ salt = (password.b + 'H.')[1..2]
14
+ salt.gsub!(/[^\.-z]/, '.')
15
+ salt.tr!(':;<=>?@[\\]^_`', 'ABCDEFGabcdef')
16
+ return password.crypt(salt)[-10..-1].strip
6
17
  end
7
18
 
8
- def self.escape(str)
9
- str.gsub(/[&<">]/, '&'=>'&amp;','<'=>'&lt;','"'=>'&quot;','>'=>'&gt;')
19
+ def self.secure(password, seed=SECRET)
20
+ return "" if password.nil? || password.empty?
21
+ seed = Base64::decode64(seed)
22
+ password = password.encode('SHIFT_JIS', 'UTF-8', undef: :replace)
23
+ secure_tripcode = Digest::SHA1.hexdigest(password.b+seed)
24
+ secure_tripcode = Base64::encode64([secure_tripcode].pack('H*'))
25
+ return secure_tripcode[0..14]
10
26
  end
11
27
 
12
- def self.salt(password)
13
- password = password.encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: '.')
14
- salt = (password[0..2] + 'H.')
15
- salt.gsub!('[^\.-z]', '.')
16
- salt.tr!(':;<=>?@[\\]^_`','ABCDEFGabcdef')
17
- return salt[1..2]
18
- end
19
-
20
- def self.hash(password)
21
- return "" if password.nil? || password.empty?
22
- password = Tripcode.sjis(password)
23
- password = Tripcode.escape(password)
24
- salt = Tripcode.salt(password)
25
- return password.crypt(salt)[-10..-1].strip
28
+ def self.parse(string, seed=SECRET)
29
+ name, tripcode, secure_tripcode = string.split('#')
30
+ tripcode = self.hash(tripcode)
31
+ secure_tripcode = self.secure(secure_tripcode, seed)
32
+ name = "" if name.nil?
33
+ return name, tripcode, secure_tripcode
26
34
  end
27
35
  end
36
+
37
+ SECRET = <<-EOS
38
+ FW6I5Es311r2JV6EJSnrR2+hw37jIfGI0FB0XU5+9lua9iCCrwgkZDVRZ+1PuClqC+78FiA6hhhX
39
+ U1oq6OyFx/MWYx6tKsYeSA8cAs969NNMQ98SzdLFD7ZifHFreNdrfub3xNQBU21rknftdESFRTUr
40
+ 44nqCZ0wyzVVDySGUZkbtyHhnj+cknbZqDu/wjhX/HjSitRbtotpozhF4C9F+MoQCr3LgKg+CiYH
41
+ s3Phd3xk6UC2BG2EU83PignJMOCfxzA02gpVHuwy3sx7hX4yvOYBvo0kCsk7B5DURBaNWH0srWz4
42
+ MpXRcDletGGCeKOz9Hn1WXJu78ZdxC58VDl20UIT9er5QLnWiF1giIGQXQMqBB+Rd48/suEWAOH2
43
+ H9WYimTJWTrK397HMWepK6LJaUB5GdIk56ZAULjgZB29qx8Cl+1K0JWQ0SI5LrdjgyZZUTX8LB/6
44
+ Coix9e6+3c05Pk6Bi1GWsMWcJUf7rL9tpsxROtq0AAQBPQ0rTlstFEziwm3vRaTZvPRboQfREta0
45
+ 9VA+tRiWfN3XP+1bbMS9exKacGLMxR/bmO5A57AgQF+bPjhif5M/OOJ6J/76q0JDHA==
46
+ EOS
@@ -1,3 +1,3 @@
1
1
  module Tripcode
2
- VERSION = "0.2.6"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tripcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler