Advertisement
phillips321

netscreen.py

Jan 9th, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import hashlib
  3.  
  4. ## Origional Block
  5. def makepass(user, password):
  6.     b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  7.     middle = "Administration Tools"
  8.     s = "%s:%s:%s" % (user, middle, password)
  9.  
  10.     m = hashlib.md5(s).digest()
  11.    
  12.     #create pairs of characters from hash string
  13.     narray = []
  14.     for i in range(8):
  15.         n1 = ord(m[2*i])
  16.         n2 = ord(m[2*i+1])
  17.         #uses n1 as high byte and n2 as low byte of 16 bit number
  18.         narray.append( (n1<<8 & 0xff00) | (n2 & 0xff) )
  19.     print narray
  20.    
  21.     #takes 8x 16bit numbers from above to create triples of chars
  22.     res = ""
  23.     for i in narray:
  24.         p1 = i >> 12 & 0xf  #set to high4 bits of i
  25.         p2 = i >> 6  & 0x3f #set to bits value 6-12
  26.         p3 = i       & 0x3f #set to low 6 bits of i
  27.         print i, p1 , p2 , p3
  28.         print b64[p1],b64[p2], b64[p3]
  29.         res += b64[p1] + b64[p2] + b64[p3]
  30.    
  31.     for c, n in  zip("nrcstn", [0, 6, 12, 17, 23, 29]):
  32.         res = res[:n] + c + res[n:]
  33.     return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement