123456789101112131415161718192021222324252627 |
- # conding: utf-8
- import string
- import base64
- import random
- def encodestr(s):
- salt1 = ''.join(random.sample(string.ascii_letters + string.digits, 5))
- salt2 = ''.join(random.sample(string.ascii_letters + string.digits, 8))
- ens = ''
- sens = base64.encodestring(s).strip()
- sens = sens.strip('=')
- for num, word in enumerate(sens):
- if num == 0:
- ens += salt1
- if num == len(sens) - 4 and len(sens) > 10:
- ens += salt2
- ens += word
- return ens
- def decodestr(s):
- dns = s[5:].replace(s[-12:-4],'') + '=='
- return base64.decodestring(dns)
- #print encodestr('6379')
- print decodestr('dHbR7NjM3OQ')
|