Class: RouterCrypt::JunOS
- Inherits:
-
Object
- Object
- RouterCrypt::JunOS
- Defined in:
- lib/junos/decrypt.rb,
lib/junos/common.rb,
lib/junos/crypt.rb
Defined Under Namespace
Classes: InvalidPW
Constant Summary collapse
- ENCODE =
[ [ 1, 4, 32 ], [ 1, 16, 32 ], [ 1, 8, 32 ], [ 1, 64 ], [ 1, 32 ], [ 1, 4, 16, 128 ], [ 1, 32, 64 ], ]
- EXTRA =
{}
- KEY =
%w( QzF3n6/9CAtpu0O B1IREhcSyrleKvMW8LXx 7N-dVbwsY2g4oaJZGUDj iHkq.mPf5T )- KEYCHAR =
KEY.join.each_char.to_a
- CHARKEY =
{}
Class Method Summary collapse
-
.crypt(plaintext, *opts) ⇒ String
Encrypts JunOS $9$ style passwords.
-
.decrypt(e_pw) ⇒ String
Decrypts JunOS $9$ style passwords.
Class Method Details
.crypt(plaintext, *opts) ⇒ String
Encrypts JunOS $9$ style passwords. This is reimplementation of CPAN Crypt::Juniper (by Kevin Brintnall, <kbrint at rufus.net>) ”juniper_crypt’ function
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/junos/crypt.rb', line 8 def crypt (plaintext, *opts) salt = opts[0] ? opts[0][0] : randc(1) rand = randc(EXTRA[salt]) prev = salt crypt="$9$" crypt<<salt crypt<<rand plaintext.chars.each_with_index do |p, pos| encode = ENCODE[ pos % ENCODE.length] crypt<< gap_encode(p, prev, encode) prev = crypt[crypt.size-1] end crypt end |
.decrypt(e_pw) ⇒ String
Decrypts JunOS $9$ style passwords. This is reimplementation of CPAN Crypt::Juniper (by Kevin Brintnall, <kbrint at rufus.net>) ”juniper_decrypt’ function
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/junos/decrypt.rb', line 8 def decrypt e_pw e_pw = e_pw[3..-1] if e_pw['$9$'] d_pw = '' prev = nibble e_pw, 1 nibble e_pw, EXTRA[prev] while e_pw.size > 0 decode = ENCODE[d_pw.size % ENCODE.size] gaps = nibble(e_pw, decode.size).each_char.map do |e| g = gap e, prev prev = e g end d_pw += gap_decode gaps, decode end d_pw end |