word_generater.py 667 B

123456789101112131415161718192021222324252627
  1. # conding: utf-8
  2. import string
  3. import base64
  4. import random
  5. def encodestr(s):
  6. salt1 = ''.join(random.sample(string.ascii_letters + string.digits, 5))
  7. salt2 = ''.join(random.sample(string.ascii_letters + string.digits, 8))
  8. ens = ''
  9. sens = base64.encodestring(s).strip()
  10. sens = sens.strip('=')
  11. for num, word in enumerate(sens):
  12. if num == 0:
  13. ens += salt1
  14. if num == len(sens) - 4 and len(sens) > 10:
  15. ens += salt2
  16. ens += word
  17. return ens
  18. def decodestr(s):
  19. dns = s[5:].replace(s[-12:-4],'') + '=='
  20. return base64.decodestring(dns)
  21. #print encodestr('6379')
  22. print decodestr('dHbR7NjM3OQ')