10进制和38,64进制互转,URL的ID的转换成38或64位的,让地址看起来更短。可使的地方很多,如短链接生成.
#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'Randy' def encode_b38(n): table = '0123456789abcdefghijklmnopqrstuvwxyz-_' result = [] temp = n if 0 == temp: result.append('0') else: while 0 < temp: result.append(table[temp % 38]) temp /= 38 return ''.join([x for x in reversed(result)]) def decode_b38(str): table = {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15, "g": 16, "h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22, "n": 23, "o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30, "v": 31, "w": 32, "x": 33, "y": 34, "z": 35, "-": 36, "_": 37} result = 0 for i in xrange(len(str)): result *= 38 result += table[str[i]] return result print encode_b38(123) # 39 print encode_b38(8456789) # 424j3 print decode_b38('1l7yex') # 123456789
#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'Randy' def encode_b64(n): table = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_' result = [] temp = n if 0 == temp: result.append('0') else: while 0 < temp: result.append(table[temp % 64]) temp /= 64 return ''.join([x for x in reversed(result)]) def decode_b64(str): table = {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15, "g": 16, "h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22, "n": 23, "o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30, "v": 31, "w": 32, "x": 33, "y": 34, "z": 35, "A": 36, "B": 37, "C": 38, "D": 39, "E": 40, "F": 41, "G": 42, "H": 43, "I": 44, "J": 45, "K": 46, "L": 47, "M": 48, "N": 49, "O": 50, "P": 51, "Q": 52, "R": 53, "S": 54, "T": 55, "U": 56, "V": 57, "W": 58, "X": 59, "Y": 60, "Z": 61, "-": 62, "_": 63} result = 0 for i in xrange(len(str)): result *= 64 result += table[str[i]] return result print encode_b64(123) # 1X print encode_b64(12345678789459) # 2PFPPjJj print decode_b64('7mYQl') # 123456789
stat -c "%a %n" file , 755, 644
ModuleNotFoundError: No module named 'MySQLdb', ...
Ubuntu18.04下使用pyenv安装python报错:BUILD FAILED (Ubun ...
dell提供了工具远程查看服务器硬件状态,可以修改硬件的参数,可以远程连接过去直接修改,就不需要 ...
启动报undefined symbol: EVP_CIPHER_CTX_cleanup错误。op ...
ubuntu开启crontab日志记录及解决No MTA installed, discardi ...
暂时还没有评论,第一个来评论吧!