c7decrypt 0.1.6 → 0.1.7

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.
Files changed (2) hide show
  1. data/lib/c7decrypt.rb +37 -15
  2. metadata +6 -3
data/lib/c7decrypt.rb CHANGED
@@ -27,29 +27,51 @@ class C7Decrypt
27
27
  # The Decryption Method for Cisco Type-7 Encrypted Strings
28
28
  # @param [String] the Cisco Type-7 Encrypted String
29
29
  # @return [String] the Decrypted String
30
- def decrypt(pw)
31
- r = ""
32
- pw_bytes = pw.scan(/../)
33
- vt_index = pw_bytes.first.to_i - 1
34
- pw_bytes.each_with_index do |byte,i|
35
- r += (byte.hex^VT_TABLE[(i + vt_index) % 53]).chr
30
+ def decrypt(e_text)
31
+ d_text = ""
32
+ seed = nil
33
+
34
+ e_text.scan(/../).each_with_index do |char,i|
35
+ if i == 0
36
+ seed = char.to_i - 1
37
+ else
38
+ d_text += decrypt_char(char, i, seed)
39
+ end
36
40
  end
37
- return r.slice(1..-1).rstrip
41
+
42
+ return d_text
38
43
  end
39
44
 
40
45
  # The Encryption Method for Cisco Type-7 Encrypted Strings
41
46
  # @param [String] the plaintext password
42
47
  # @param [String] the seed for the encryption used
43
48
  # @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 = nil
49
- tmp = char.unpack('C')[0] ^ VT_TABLE[((i + seed) % 53)]
50
- etext += ("%02X" % tmp)
49
+ def encrypt(d_text, seed = 2)
50
+ e_text = sprintf("%02d", seed)
51
+
52
+ d_text.each_char.each_with_index do |d_char,i|
53
+ e_text += encrypt_char(d_char, i, seed)
51
54
  end
52
- return etext
55
+
56
+ return e_text
57
+ end
58
+
59
+ # The method for encrypting a single character
60
+ # @param [String] the plain text char
61
+ # @param [Integer] the index of the char in plaintext string
62
+ # @param [Integer] the seed used in the encryption process
63
+ # @return [String] the string of the encrypted char
64
+ def encrypt_char(char, i, seed)
65
+ sprintf("%02X", char.unpack('C')[0] ^ VT_TABLE[(i + seed) % 53])
66
+ end
67
+
68
+ # The method for decrypting a single character
69
+ # @param [String] the encrypted char
70
+ # @param [Integer] the index of the char pair in encrypted string
71
+ # @param [Integer] the seed used in the decryption process
72
+ # @return [String] the string of the decrypted char
73
+ def decrypt_char(char, i, seed)
74
+ (char.hex^VT_TABLE[(i + seed) % 53]).chr
53
75
  end
54
76
 
55
77
  # A helper method to decrypt an arracy of Cisco Type-7 Encrypted Strings
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: c7decrypt
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.6
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jonathan Claudius
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-01-23 00:00:00 Z
13
+ date: 2013-02-05 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: A library for decoding Cisco Type 7 passwords
@@ -36,6 +36,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
+ hash: -365620009767347237
40
+ segments:
41
+ - 0
39
42
  version: "0"
40
43
  required_rubygems_version: !ruby/object:Gem::Requirement
41
44
  none: false
@@ -46,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
49
  requirements: []
47
50
 
48
51
  rubyforge_project:
49
- rubygems_version: 1.8.24
52
+ rubygems_version: 1.8.25
50
53
  signing_key:
51
54
  specification_version: 3
52
55
  summary: Ruby based Cisco Type 7 Password Decryptor