Top Level Namespace

Includes:
Contracts

Defined Under Namespace

Modules: IOS7Crypt Classes: String

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.testObject



85
86
87
88
# File 'lib/ios7crypt.rb', line 85

def self.test
  prop_reversible = -> s { s == s.encrypt.decrypt }
  RubyCheck.for_all(prop_reversible, [:gen_str])
end

Instance Method Details

#mainObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ios7crypt.rb', line 90

def main
  mode = :usage

  password = ''
  hash = ''

  opts = GetoptLong.new(
    ['--help', '-h', GetoptLong::NO_ARGUMENT],
    ['--encrypt', '-e', GetoptLong::REQUIRED_ARGUMENT],
    ['--decrypt', '-d', GetoptLong::REQUIRED_ARGUMENT],
    ['--test', '-t', GetoptLong::NO_ARGUMENT]
  )

  opts.each do |option, value|
    case option
    when '--help'
      usage
    when '--encrypt'
      mode = :encrypt
      password = value
    when '--decrypt'
      mode = :decrypt
      hash = value
    when '--test'
      mode = :test
    else
      usage
    end
  end

  case mode
  when :usage
    usage
  when :encrypt
    puts password.encrypt
  when :decrypt
    puts hash.decrypt
  when :test
    test
  else
    usage
  end
end

#usageObject

Author

Andrew Pennebaker

Copyright

Copyright 2007 - 2013 Andrew Pennebaker

Synopsis

ios7crypt: encrypts and decrypts passwords with Cisco IOS7 algorithm



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ios7crypt.rb', line 10

def usage
  puts "#{$PROGRAM_NAME} [OPTIONS]

--help, -h:
    show help

--encrypt, -e <password>
    prints out the encrypted password as a hash

--decrypt, -d <hash>
    prints out the decrypted hash as a password

--test, -t
    runs unit tests"

  exit
end