python下hashids使用示例:
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
官网地址 http://hashids.org/python/
可下载离线安装,也可以用python安装工具安装(pip install hashids)
'''
from hashids import Hashids
print("hello , hashids is starting...");
#Hashids def __init__(self, salt='', min_length=0, alphabet=ALPHABET):
#默认 hashids = Hashids()
#自定义salt hashids = Hashids(salt='helloworld')
#自定义长度 hashids = Hashids(min_length=16) 每次加密一个id,那么长度是可控的,一次多个长度就不是固定的了
#自定义字符序列 hashids = Hashids(alphabet='abcdefghijklmnopqrstuvwxyz')
hashids = Hashids(salt='helloworld',min_length=6,alphabet='abcdefghijklmnopqrstuvwxyz0123456789')
hashStr = hashids.encrypt(123,11)
ints = hashids.decrypt(hashStr)
print u'加密后:'+hashStr
print u'解密后:',
print ','.join(str(i) for i in ints)