huami 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +8 -0
  2. data/bin/huami +13 -0
  3. data/lib/huami.rb +50 -0
  4. metadata +48 -0
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
data/bin/huami ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'huami'
4
+
5
+ if ARGV.length != 1
6
+ Huami.usage()
7
+ exit(1)
8
+ end
9
+
10
+ key = ARGV[0]
11
+ password = ask("Enter password: ") { |q| q.echo = false }
12
+
13
+ puts Huami.huami(key, password)
data/lib/huami.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'highline/import'
3
+ require 'openssl'
4
+
5
+ class Huami
6
+
7
+ STR1 = "snow"
8
+ STR2 = "kise"
9
+ STR3 = "sunlovesnow1990090127xykab"
10
+
11
+ def self.huami(key, password)
12
+ md5one = md5_hmac(key, password)
13
+ md5two = md5_hmac(STR1, md5one)
14
+ md5three = md5_hmac(STR2, md5one)
15
+
16
+ # 转换大小写
17
+ rule = md5three.split('')
18
+ source = md5two.split('')
19
+ for i in (0..31)
20
+ if STR3.include? rule[i]
21
+ source[i] = source[i].upcase
22
+ end
23
+ end
24
+
25
+ # 保证首字符为字母
26
+ if is_digit(source[0])
27
+ code16 = "K" + source[1..15].join()
28
+ else
29
+ code16 = source[0..15].join()
30
+ end
31
+
32
+ return code16
33
+ end
34
+
35
+ def self.md5_hmac(key, password)
36
+ digest = OpenSSL::Digest::Digest.new('md5')
37
+ return OpenSSL::HMAC.hexdigest(digest, key, password)
38
+ end
39
+
40
+ def self.is_digit(string)
41
+ return string.strip =~ /^[0-9]$/
42
+ end
43
+
44
+ def self.usage
45
+ puts "Usage:"
46
+ puts "huami.rb KEY"
47
+ end
48
+
49
+ end
50
+
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huami
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Wei Zhu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-31 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Management of password in rememberable way.
15
+ email: yesmeck@gmail.com
16
+ executables:
17
+ - huami
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Rakefile
22
+ - lib/huami.rb
23
+ - bin/huami
24
+ homepage: http://yesmeck.com
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.12
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: Huami
48
+ test_files: []