12345678910111213141516171819202122232425262728293031323334 |
- # 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)
- if __name__ == "__main__":
- if len(sys.argv) != 3:
- print "usage: word_generater.py [decodestr]/[encodestr] [string]"
- if sys.argv[1] == "decodestr" :
- print decodestr(sys.argv[2])
- if sys.argv[1] == "encodestr" :
- print encodestr(sys.argv[2])
- #print encodestr('6379')
- #print decodestr('dHbR7NjM3OQ')
|