c7decrypt 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/c7decrypt.rb +41 -6
  2. metadata +12 -4
data/lib/c7decrypt.rb CHANGED
@@ -32,11 +32,25 @@ class C7Decrypt
32
32
  pw_bytes = pw.scan(/../)
33
33
  vt_index = pw_bytes.first.hex - 1
34
34
  pw_bytes.each_with_index do |byte,i|
35
- r += (byte.hex^VT_TABLE[(i + vt_index) % 53]).chr
35
+ r += (byte.hex^VT_TABLE[(i + vt_index) % 53]).chr
36
36
  end
37
37
  return r.slice(1..-1).rstrip
38
38
  end
39
39
 
40
+ # The Encryption Method for Cisco Type-7 Encrypted Strings
41
+ # @param [String] the plaintext password
42
+ # @param [String] the seed for the encryption used
43
+ # @return [String] the encrypted password
44
+ def encrypt(plain_text, seed = 2)
45
+ etext = "%02d" % seed
46
+ pt_chars = plain_text.scan(/./)
47
+ pt_chars.each_with_index do |char,i|
48
+ tmp = char.ord ^ VT_TABLE[(i + seed)]
49
+ etext += ("%02X" % tmp)
50
+ end
51
+ return etext
52
+ end
53
+
40
54
  # A helper method to decrypt an arracy of Cisco Type-7 Encrypted Strings
41
55
  # @param [Array>String] an array of Cisco Type-7 Encrypted Strings
42
56
  # @return [Array>String] an array of Decrypted Strings
@@ -44,6 +58,13 @@ class C7Decrypt
44
58
  pw_array.collect {|pw| decrypt(pw)}
45
59
  end
46
60
 
61
+ # A helper method to encrypt an arracy of passwords
62
+ # @param [Array>String] an array of plain-text passwords
63
+ # @return [Array>String] an array of encrypted passwords
64
+ def encrypt_array(pt_array, seed = 2)
65
+ pt_array.collect {|pw| encrypt(pw, seed)}
66
+ end
67
+
47
68
  # This method scans a raw config file for type 7 passwords and decrypts them
48
69
  # @param [String] a string of the config file path that contains Cisco Type-7 Encrypted Strings
49
70
  # @return [Array>String] an array of Decrypted Strings
@@ -59,20 +80,34 @@ class C7Decrypt
59
80
  TYPE_7_REGEXES.collect {|regex| string.scan(regex)}.flatten.uniq
60
81
  end
61
82
 
62
- # A short-hand version of the descrypt method
63
- # @param [String] the Cisco Type-7 Encrypted String
64
- # @return [String] the Decrypted String
83
+ # A short-hand version of the decrypt method
84
+ # @param [String] the password hash
85
+ # @return [String] the plaintest password
65
86
  def d(pw)
66
87
  decrypt(pw)
67
88
  end
68
89
 
90
+ # A short-hand version of the encrypt method
91
+ # @param [String] the plaintext password
92
+ # @return [String] the password hash
93
+ def e(pt, seed = 2)
94
+ encrypt(pt, seed)
95
+ end
96
+
69
97
  # A short-hand version of the descrypt_array method
70
- # @param [Array>String] an array of Cisco Type-7 Encrypted Strings
71
- # @return [Array>String] an array of Decrypted Strings
98
+ # @param [Array>String] an array of password hashes
99
+ # @return [Array>String] an array of plaintext passwords
72
100
  def d_a(pw_array)
73
101
  decrypt_array(pw_array)
74
102
  end
75
103
 
104
+ # A short-hand version of the descrypt_array method
105
+ # @param [Array>String] an array of Cisco Type-7 Encrypted Strings
106
+ # @return [Array>String] an array of Decrypted Strings
107
+ def e_a(pt_array, seed = 2)
108
+ encrypt_array(pt_array, seed)
109
+ end
110
+
76
111
  # A short-hand version of the decrypt_config method
77
112
  # @param [String] a string of the config file path that contains Cisco Type-7 Encrypted Strings
78
113
  # @return [Array>String] an array of Decrypted Strings
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c7decrypt
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 13
4
5
  prerelease:
5
- version: 0.0.8
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 9
10
+ version: 0.0.9
6
11
  platform: ruby
7
12
  authors:
8
13
  - Jonathan Claudius
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2012-11-01 00:00:00 Z
18
+ date: 2012-11-05 00:00:00 Z
14
19
  dependencies: []
15
20
 
16
21
  description: A library for decoding Cisco Type 7 passwords
@@ -36,7 +41,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
41
  requirements:
37
42
  - - ">="
38
43
  - !ruby/object:Gem::Version
39
- hash: 2947470372204740121
44
+ hash: 3
40
45
  segments:
41
46
  - 0
42
47
  version: "0"
@@ -45,11 +50,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
50
  requirements:
46
51
  - - ">="
47
52
  - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
48
56
  version: "0"
49
57
  requirements: []
50
58
 
51
59
  rubyforge_project:
52
- rubygems_version: 1.8.24
60
+ rubygems_version: 1.8.10
53
61
  signing_key:
54
62
  specification_version: 3
55
63
  summary: Ruby based Cisco Type 7 Password Decryptor