python

关注公众号 jb51net

关闭
首页 > 脚本专栏 > python > Python加解密 编码解码 进制转换

Python实现加解密,编码解码和进制转换(最全版)

作者:小木_.

这篇文章主要为大家详细介绍了Python实现加解密、编码解码、进制转换、字符串转换的最全版操作方法,文中的示例代码讲解详细,大家可以收藏一下

请先安装这几个模块

# Python 3.11.0
import hashlib
import binascii
import google_crc32c
import zlib
import base64
import urllib.parse
import opencc
import time
from Crypto.Cipher import AES
# 安装方法如下
# 打开cmd 输入如下代码回车即可
 
pip install hashlib
pip install binascii
pip install google_crc32c
pip install zlib
pip install base64
pip install urllib.parse
pip install opencc
# 安装 Crypto.Cipher
pip install pycryptodome

一、加密(不含解密)

1、MD4

import hashlib
def md4_encrypt(string):
    md4 = hashlib.new('md4')
    md4.update(string.encode('utf-8'))
    return md4.hexdigest()
# 输入
print(md4_encrypt("你好"))
# 输出:a7f1196539fd1f85f754ffd185b16e6e

2、MD5

import hashlib
def md5_encrypt(string):
    md5 = hashlib.md5()
    md5.update(string.encode('utf-8'))
    return md5.hexdigest()
# 输入
print(md5_encrypt("你好"))
# 输出:7eca689f0d3389d9dea66ae112e5cfd7

3、blake2b

import hashlib
def blake2b_encrypt(string):
    blake2b = hashlib.blake2b()
    blake2b.update(string.encode('utf-8'))
    return blake2b.hexdigest()
# 输入
print(blake2b_encrypt("你好"))
# 输出:8eadb63a9f823c4e8eac400247995c69ab714dd54cc33bbf0583e269e3aa9077ad8c0069ffb2fec634a1dd913196c0e459f987a1e5d3c9997e9fd556b38604a4

4、blake2s

import hashlib
def blake2s_encrypt(string):
    blake2s = hashlib.blake2s()
    blake2s.update(string.encode('utf-8'))
    return blake2s.hexdigest()
# 输入
print(blake2s_encrypt("你好"))
# 输出:b834cce099cfa370b999ebfa3bb8a6a87fa09b45a1a83d038d8957cbb88c9896

5、SHA1

import hashlib
def sha1_encrypt(string):
    sha1 = hashlib.sha1()
    sha1.update(string.encode('utf-8'))
    return sha1.hexdigest()
# 输入
print(sha1_encrypt("你好"))
# 输出:440ee0853ad1e99f962b63e459ef992d7c211722

6、SHA224

import hashlib
def sha224_encrypt(string):
    sha224 = hashlib.sha224()
    sha224.update(string.encode('utf-8'))
    return sha224.hexdigest()
# 输入
print(sha224_encrypt("你好"))
# 输出:e91f006ed4e0882de2f6a3c96ec228a6a5c715f356d00091bce842b5

7、SHA256

import hashlib
def sha256_encrypt(string):
    sha256 = hashlib.sha256()
    sha256.update(string.encode('utf-8'))
    return sha256.hexdigest()
# 输入
print(sha256_encrypt("你好"))
# 输出:670d9743542cae3ea7ebe36af56bd53648b0a1126162e78d81a32934a711302e

8、SHA384

import hashlib
def sha384_encrypt(string):
    sha384 = hashlib.sha384()
    sha384.update(string.encode('utf-8'))
    return sha384.hexdigest()
# 输入
print(sha384_encrypt("你好"))
# 输出:05f076c7d180e91d80a56d70b226fca01e2353554c315ac1e8caaaeca2ce0dc0d9d84e206a2bf1143a0ae1b9be9bcfa8

9、SHA512

import hashlib
def sha512_encrypt(string):
    sha512 = hashlib.sha512()
    sha512.update(string.encode('utf-8'))
    return sha512.hexdigest()
# 输入
print(sha512_encrypt("你好"))
# 输出:5232181bc0d9888f5c9746e410b4740eb461706ba5dacfbc93587cecfc8d068bac7737e92870d6745b11a25e9cd78b55f4ffc706f73cfcae5345f1b53fb8f6b5

10、SHA3_224

import hashlib
def sha3_224_encrypt(string):
    sha3_224 = hashlib.sha3_224()
    sha3_224.update(string.encode('utf-8'))
    return sha3_224.hexdigest()
# 输入
print(sha3_224_encrypt("你好"))
# 输出:d6e2200b43a6997075692b6dde5ca9f91cae1d15f72546d3c9a9d8c4

11、SHA3_256

import hashlib
def sha3_256_encrypt(string):
    sha3_256 = hashlib.sha3_256()
    sha3_256.update(string.encode('utf-8'))
    return sha3_256.hexdigest()
# 输入
print(sha3_224_encrypt("你好"))
# 输出:0100e69a7157f3a814a3cf6895f4fccd6b610b9947224b2aaa7aa11dd0dca833

12、SHA3_384

import hashlib
def sha3_384_encrypt(string):
    sha3_384 = hashlib.sha3_384()
    sha3_384.update(string.encode('utf-8'))
    return sha3_384.hexdigest()
# 输入
print(sha3_384_encrypt("你好"))
# 输出:bdc0b2e622a1d79abae4cabbf86bd88192dead3b90c8332ac4bac08e9a2c06d5c685f46101ac0c14980849f39a7b0ebf

13、SHA3_512

import hashlib
def sha3_512_encrypt(string):
    sha3_512 = hashlib.sha3_512()
    sha3_512.update(string.encode('utf-8'))
    return sha3_512.hexdigest()
# 输入
print(sha3_512_encrypt("你好"))
# 输出:d673e4b36755b938359fa394cf920b4430a34f447ea5cb10485d9d46a7d6682eef6d7459b4dac9019d908e08a1e7aaab3accde4f59e862dbb99f906d85e5c66d

14、shake_128

import hashlib
def shake_128_encrypt(data):
    data = data.encode('utf-8')
    shake_128 = hashlib.shake_128()
    shake_128.update(data)
    return shake_128.hexdigest(32)
# 输入
print(shake_128_encrypt("你好"))
# 输出:2c8206e6e29e0e3c9d64e9455629cd354548a15761d3bafcb941769ed4649538

15、shake_256

import hashlib
def shake_256_encrypt(data):
    data = data.encode('utf-8')
    shake_256 = hashlib.shake_256()
    shake_256.update(data)
    return shake_256.hexdigest(32)
# 输入
print(shake_256_encrypt("你好"))
# 输出:d13a972c4c06e0cbb67af0af4b1a92d296b709e36cccbeed30db6c9d2853cd1c

16、crc32 十进制

import binascii
def crc32_10(data):
    return binascii.crc32(data.encode()) & 0xffffffff
# 输入
print(crc32_10("你好"))
# 输出:1352841281

17、crc32 十六进制

import binascii
def crc32_16(data):
    return hex(binascii.crc32(data.encode()) & 0xffffffff)
# 输入
print(crc32_16("你好"))
# 输出:0x50a2b841

18、CRC32C十进制

import google_crc32c
def crc32c_10(data):
    return google_crc32c.value(data.encode())
# 输入
print(crc32c_10("你好"))
# 输出:1383944972

19、CRC32C十六进制

import google_crc32c
def crc32c_16(data):
    return hex(google_crc32c.value(data.encode()))
# 输入
print(crc32c_16("你好"))
# 输出:0x527d530c

20、Adler32十进制

import zlib
def adler32_10(data):
    return zlib.adler32(data.encode()) & 0xffffffff
# 输入
print(adler32_10("你好"))
# 输出:272958601

21、Adler32十六进制

import zlib
def adler32_16(data):
    return hex(zlib.adler32(data.encode()) & 0xffffffff)
# 输入
print(adler32_16("你好"))
# 输出:0x10450489

二、加密&解密

1、IDEA 加密解密

# IDEA【加密算法】
def IDEA_encrypt(string, key):   # string要加密的字符串  key只能为数字,5位数内
    result = ''
    for i in range(len(string)):
        result += chr(ord(string[i]) + int(key))
    return result
# 输入
print(IDEA_encrypt("你好",443322))
# 输出:񱌚񱴷
# IDEA【解密算法】
def IDEA_decrypt(string, key):   # string要加密的字符串  key只能为数字,5位数内
    result = ''
    for i in range(len(string)):
        result += chr(ord(string[i]) - int(key))
    return result
# 输入
print(IDEA_decrypt("񱌚񱴷",443322))
# 输出:你好

2、ASCLL 加密解密

# ASCLL【加密】
def decrypt_ASCLL(string):
    result = ""
    for char in string:
        result += chr(ord(char) + 1000)
    return result
# 输入
print(decrypt_ASCLL('你好'))
# 输出:午嵥
# ASCLL【解密】
def encrypt_ASCLL(string):
    result = ""
    for char in string:
        result += chr(ord(char) - 1000)
    return result
# 输入
print(encrypt_ASCLL('午嵥'))
# 输出:你好

3、AES_ECB 加密解密

# AES 【ECB加密】
# AES 【加密】 加密模式(不可改):ECB  key(默认):0000000000000000   填充模式(默认):NoPadding  子集编码(默认):UTF-8    字节(不可改):128字节
from Crypto.Cipher import AES
import base64
def AES_ECB_encode(data,key=b'0000000000000000',paddingMode='NoPadding',characterSet='UTF-8'):
    '''
    # data:加解密内容【解密】
    # key:密钥,长度为16字节或32字节
    # paddingMode:填充模式,默认为NoPadding  可选【NoPadding,ZeroPadding,PKCS5Padding,PKCS7Padding】
    # characterSet:编码,默认为UTF-8  可选【UTF-8,UTF-16_LE,GBK】
    '''
    # 检测密钥的长度是否是16或32字节长度
    if len(key) in [16,32]:
        data = data.encode(characterSet)
        AESS = AES.new(key, AES.MODE_ECB)
        enData = ''
        if paddingMode == 'NoPadding':
            if len(data) % 16 == 0:
                enData = AESS.encrypt(data)  # AES加密
            else:
                if len(data) % 16 != 0:
                    data += b'\x00'
                    while len(data) % 16 != 0:
                        data += b'\x00'
                    data = data
                enData = AESS.encrypt(data)  # AES加密
        if paddingMode == 'ZeroPadding':
            if len(data) % 16 != 0:
                data += b'\x00'
                while len(data) % 16 != 0:
                    data += b'\x00'
                data = data
            enData = AESS.encrypt(data)  # AES加密
        if paddingMode in ['PKCS5Padding','PKCS7Padding']:
            needSize = 16 - len(data) % 16
            if needSize == 0:
                needSize = 16
            data = data + needSize.to_bytes(1, 'little') * needSize
            enData = AESS.encrypt(data)  # AES加密
        return base64.b64encode(enData).decode()
    else:
        return '密钥或iv字节长度错误!!!'
# 输入
print(AES_ECB_encode('你好 Abc',key=b'1234567890123456',paddingMode='PKCS5Padding'))
# 输出:3ZJEr/p5lexy81r+IRGGoQ==
# AES 【ECB解密】
# AES 【解密】 加密模式(不可改):ECB  key(默认):0000000000000000   填充模式(默认):NoPadding  子集编码(默认):UTF-8    字节(不可改):128字节
from Crypto.Cipher import AES
import base64
def AES_ECB_decode(data,key=b'0000000000000000',paddingMode='NoPadding',characterSet='UTF-8'):
    '''
    # data:加解密内容【解密】
    # key:密钥,长度为16字节或32字节
    # paddingMode:填充模式,默认为NoPadding  可选【NoPadding,ZeroPadding,PKCS5Padding,PKCS7Padding】
    # characterSet:编码,默认为UTF-8  可选【UTF-8,UTF-16_LE,GBK】
    '''
    if len(key) in [16, 32]:
        data = base64.b64decode(data.encode(characterSet))
        data = AES.new(key, AES.MODE_ECB).decrypt(data)
        if paddingMode in ['NoPadding','ZeroPadding']:
            data = data[:-1]
            while len(data) % 16 != 0:
                data = data.rstrip(b'\x00')
                if data[-1] != b"\x00":
                    break
        if paddingMode in ['PKCS5Padding','PKCS7Padding']:
            paddingSize = data[-1]
            data = data.rstrip(paddingSize.to_bytes(1, 'little'))
        return data.decode(characterSet)
    else:
        return '密钥或iv字节长度错误!!!'
# 输入
print(AES_ECB_decode('3ZJEr/p5lexy81r+IRGGoQ==',key=b'1234567890123456',paddingMode='PKCS5Padding'))
# 输出:你好 Abc

4、AES_CBC 加密解密

# AES 【CBC加密】
# AES 【加密】 加密模式(不可改):CBC  key/iv(默认):0000000000000000   填充模式(默认):NoPadding  子集编码(默认):UTF-8    字节(不可改):128字节
from Crypto.Cipher import AES
import base64
def AES_CBC_encode(data,key=b'0000000000000000',iv=b'0000000000000000',paddingMode='NoPadding',characterSet='UTF-8'):
    '''
    # data:加解密内容【解密】
    # key:密钥,长度为16字节或32字节
    # iv:偏移量,长度为16字节
    # paddingMode:填充模式,默认为NoPadding  可选【NoPadding,ZeroPadding,PKCS5Padding,PKCS7Padding】
    # characterSet:编码,默认为UTF-8  可选【UTF-8,UTF-16_LE,GBK】
    '''
    # 检测密钥的长度是否是16或32字节长度,iv偏移量的字节长度是否是16字节
    if (len(key) in [16,32]) and (len(iv) in [16]) == True:
        data = data.encode(characterSet)
        AESS = AES.new(key, AES.MODE_CBC, iv)
        enData = ''
        if paddingMode == 'NoPadding':
            if len(data) % 16 == 0:
                enData = AESS.encrypt(data)  # AES加密
            else:
                if len(data) % 16 != 0:
                    data += b'\x00'
                    while len(data) % 16 != 0:
                        data += b'\x00'
                    data = data
                enData = AESS.encrypt(data)  # AES加密
        if paddingMode == 'ZeroPadding':
            if len(data) % 16 != 0:
                data += b'\x00'
                while len(data) % 16 != 0:
                    data += b'\x00'
                data = data
            enData = AESS.encrypt(data)  # AES加密
        if paddingMode in ['PKCS5Padding','PKCS7Padding']:
            needSize = 16 - len(data) % 16
            if needSize == 0:
                needSize = 16
            data = data + needSize.to_bytes(1, 'little') * needSize
            enData = AESS.encrypt(data)  # AES加密
        return base64.b64encode(enData).decode()
    else:
        return '密钥或iv字节长度错误!!!'
# 输入
print(AES_CBC_encode('你好 Abc',key=b'1234567890123456',paddingMode='PKCS5Padding'))
# 输出:VzrFG9/TsFTW+yup4/tr4g==
# AES 【CBC解密】
# AES 【解密】 加密模式(不可改):CBC  key/iv(默认):0000000000000000   填充模式(默认):NoPadding  子集编码(默认):UTF-8    字节(不可改):128字节
from Crypto.Cipher import AES
import base64
def AES_CBC_decode(data,key=b'0000000000000000',iv=b'0000000000000000',paddingMode='NoPadding',characterSet='UTF-8'):
    '''
    # data:加解密内容【解密】
    # key:密钥,长度为16字节或32字节
    # iv:偏移量,长度为16字节
    # paddingMode:填充模式,默认为NoPadding  可选【NoPadding,ZeroPadding,PKCS5Padding,PKCS7Padding】
    # characterSet:编码,默认为UTF-8  可选【UTF-8,UTF-16_LE,GBK】
    '''
    if (len(key) in [16, 32]) and (len(iv) in [16]) == True:
        data = base64.b64decode(data.encode(characterSet))
        data = AES.new(key, AES.MODE_CBC, iv).decrypt(data)
        if paddingMode in ['NoPadding','ZeroPadding']:
            data = data[:-1]
            while len(data) % 16 != 0:
                data = data.rstrip(b'\x00')
                if data[-1] != b"\x00":
                    break
        if paddingMode in ['PKCS5Padding','PKCS7Padding']:
            paddingSize = data[-1]
            data = data.rstrip(paddingSize.to_bytes(1, 'little'))
        return data.decode(characterSet)
    else:
        return '密钥或iv字节长度错误!!!'
# 输入
print(AES_CBC_decode('VzrFG9/TsFTW+yup4/tr4g==',key=b'1234567890123456',paddingMode='PKCS5Padding'))
# 输出:你好 Abc

5、AES_CFB 加密解密

# AES 【CFB加密】
# AES 【加密】 加密模式(不可改):CFB  key/iv(默认):0000000000000000     块大小(bits)(默认):16   填充模式(默认):NoPadding  子集编码(默认):UTF-8    字节(不可改):128字节
from Crypto.Cipher import AES
import base64
def AES_CFB_encode(data,key=b'0000000000000000',iv=b'0000000000000000',segment_size=16,paddingMode='NoPadding',characterSet='UTF-8'):
    '''
    # data:加解密内容【解密】
    # key:密钥,长度为16字节或32字节
    # iv:偏移量,长度为16字节
    # segment_size:块大小(bits)  默认为 8    最小值为 8   最大值为128  只能是8的倍数,如:8,16,24,32,40,48,56,64...
    # paddingMode:填充模式,默认为NoPadding  可选【NoPadding,ZeroPadding,PKCS5Padding,PKCS7Padding】
    # characterSet:编码,默认为UTF-8  可选【UTF-8,UTF-16_LE,GBK】
    '''
    # 检测密钥的长度是否是16或32字节长度
    if (len(key) in [16,32]) and (len(iv) in [16]) == True:
        data = data.encode(characterSet)
        AESS = AES.new(key, AES.MODE_CFB,iv,segment_size=segment_size)
        enData = ''
        if paddingMode == 'NoPadding':
            if len(data) % 2 == 0:
                enData = AESS.encrypt(data)  # AES加密
            else:
                if len(data) % 2 != 0:
                    data += b'\x00'
                    while len(data) % 2 != 0:
                        data += b'\x00'
                    data = data
                enData = AESS.encrypt(data)  # AES加密
        if paddingMode == 'ZeroPadding':
            if len(data) % 16 != 0:
                data += b'\x00'
                while len(data) % 16 != 0:
                    data += b'\x00'
                data = data
            enData = AESS.encrypt(data)  # AES加密
        if paddingMode in ['PKCS5Padding','PKCS7Padding']:
            needSize = 16 - len(data) % 16
            if needSize == 0:
                needSize = 16
            data = data + needSize.to_bytes(1, 'little') * needSize
            enData = AESS.encrypt(data)  # AES加密
        return base64.b64encode(enData).decode()
    else:
        return '密钥或iv字节长度错误!!!'
# 输入
print(AES_CFB_encode('你好 Abc',key=b'1234567890123456',iv=b'1111111111111111',paddingMode='NoPadding'))
# 输出:QiLUCMq9uwxjUw==
# AES 【CFB解密】
# AES 【解密】 加密模式(不可改):CFB  key/iv(默认):0000000000000000    块大小(bits)(默认):16   填充模式(默认):NoPadding  子集编码(默认):UTF-8    字节(不可改):128字节
from Crypto.Cipher import AES
import base64
def AES_CFB_decode(data,key=b'0000000000000000',iv=b'0000000000000000',segment_size=16,paddingMode='NoPadding',characterSet='UTF-8'):
    '''
    # data:加解密内容【解密】
    # key:密钥,长度为16字节或32字节
    # iv:偏移量,长度为16字节
    # segment_size:块大小(bits)  默认为 8    最小值为 8   最大值为128  只能是8的倍数,如:8,16,24,32,40,48,56,64...
    # paddingMode:填充模式,默认为NoPadding  可选【NoPadding,ZeroPadding,PKCS5Padding,PKCS7Padding】
    # characterSet:编码,默认为UTF-8  可选【UTF-8,UTF-16_LE,GBK】
    '''
    if (len(key) in [16,32]) and (len(iv) in [16]) == True:
        data = base64.b64decode(data.encode(characterSet))
        data = AES.new(key, AES.MODE_CFB,iv,segment_size=segment_size).decrypt(data)
        if paddingMode in ['NoPadding']:
            while len(data) % 2 != 0:
                data = data.rstrip(b'\x00')
                if data != b"\x00":
                    break
        if paddingMode in ['ZeroPadding']:
            data = data[:-1]
            while len(data) % 16 != 0:
                data = data.rstrip(b'\x00')
                if data[-1] != b"\x00":
                    break
        if paddingMode in ['PKCS5Padding','PKCS7Padding']:
            paddingSize = data[-1]
            data = data.rstrip(paddingSize.to_bytes(1, 'little'))
        return data.decode(characterSet)
    else:
        return '密钥或iv字节长度错误!!!'
# 输入
print(AES_CFB_decode('QiLUCMq9uwxjUw==',key=b'1234567890123456',iv=b'1111111111111111',paddingMode='NoPadding'))
# 输出:你好 Abc

6、DES_CBC 加密解密

# DES 【CBC加密】
# DES 【加密】 加密模式(不可改):CBC  key/iv(默认):00000000     块大小(bits)(默认):16   填充模式(默认):NoPadding  子集编码(默认):UTF-8
from Crypto.Cipher import DES
import base64
def DES_CBC_encode(data,key=b'00000000',iv=b'00000000',paddingMode='NoPadding',characterSet='UTF-8'):
    '''
    # data:加解密内容【解密】
    # key:密钥,长度为8字节
    # iv:偏移量,长度为8字节
    # paddingMode:填充模式,默认为NoPadding  可选【NoPadding,ZeroPadding,PKCS5Padding,PKCS7Padding】
    # characterSet:编码,默认为UTF-8  可选【UTF-8,UTF-16_LE,GBK】
    '''
    if [(len(key)),len(iv)] == [8,8]:
        DESS = DES.new(key, DES.MODE_CBC,iv)
        data = data.encode(characterSet)
        enData = ''
        if paddingMode in ['NoPadding','ZeroPadding']:
            if len(data) % 16 != 0:
                data += b'\x00'
                while len(data) % 16 != 0:
                    data += b'\x00'
                data = data
            enData = DESS.encrypt(data)  # DES加密
        if paddingMode in ['PKCS5Padding','PKCS7Padding']:
            needSize = 16 - len(data) % 16
            if needSize == 0:
                needSize = 16
            data = data + needSize.to_bytes(1, 'little') * needSize
            enData = DESS.encrypt(data)  # DES加密
        return base64.b64encode(enData).decode()
    else:
        return '密钥或iv字节长度错误!!!'
# 输入
print(DES_CBC_encode('你好 Abc',key=b'12345678',iv=b'88888888',paddingMode='ZeroPadding'))
# 输出:4jaMYjQEe5FW1JJyDhCliQ==
# DES 【CBC解密】
# DES 【解密】 加密模式(不可改):CBC  key/iv(默认):00000000     块大小(bits)(默认):16   填充模式(默认):NoPadding  子集编码(默认):UTF-8
from Crypto.Cipher import DES
import base64
def DES_CBC_decode(data,key=b'00000000',iv=b'00000000',paddingMode='NoPadding',characterSet='UTF-8'):
    '''
    # data:加解密内容【解密】
    # key:密钥,长度为8字节
    # iv:偏移量,长度为8字节
    # paddingMode:填充模式,默认为NoPadding  可选【NoPadding,ZeroPadding,PKCS5Padding,PKCS7Padding】
    # characterSet:编码,默认为UTF-8  可选【UTF-8,UTF-16_LE,GBK】
    '''
    if [(len(key)),len(iv)] == [8,8]:
        data = base64.b64decode(data.encode(characterSet))
        data = DES.new(key, DES.MODE_CBC, iv).decrypt(data)
        if paddingMode in ['NoPadding','ZeroPadding']:
            data = data[:-1]
            while len(data) % 16 != 0:
                data = data.rstrip(b'\x00')
                if data[-1] != b"\x00":
                    break
        if paddingMode in ['PKCS5Padding', 'PKCS7Padding']:
            paddingSize = data[-1]
            data = data.rstrip(paddingSize.to_bytes(1, 'little'))
        return data.decode(characterSet)
    else:
        return '密钥或iv字节长度错误!!!'
# 输入
print(DES_CBC_decode('4jaMYjQEe5FW1JJyDhCliQ==',key=b'12345678',iv=b'88888888',paddingMode='ZeroPadding'))
# 输出:你好 Abc

三、编码&解码

1、base64 编码解码(文字)

# base64 【编码】
import base64
def base64_encode(str):
    return base64.b64encode(str.encode('utf-8')).decode('utf-8')
# 输入
print(base64_encode("你好"))
# 输出:5L2g5aW9

# base64 【解码】
import base64
def base64_decode(str):
    return base64.b64decode(str).decode('utf-8')
# 输入
print(base64_decode("5L2g5aW9"))
# 输出:你好

2、base64 编码解码(文件)

# base64 【编码】
import base64
def base64_encode_file(file_name):
    with open(file_name, 'rb') as f:
        return base64.b64encode(f.read()).decode('utf-8')
# 输入
print(base64_encode_file("1.txt"))
# 输出:/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABkAAD/4QMbaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA3LjEtYzAwMCA3OS5jY2Y4NGUwLCAyMDIyLzA2LzIyLTIyOjEzOjI2ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpDQjkzRDc0NDhENzExMUVEODI5QkFGQTc4NzM0QjcxRiIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpDQjkzRDc0MzhENzExMUVEODI5QkFGQTc4NzM0QjcxRiIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgMjAyMSBXaW5kb3dzIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9IjJFQ0Y3OEY5OEY3MjIxRUMzREU3ODE0MDQyMDNCMjM1IiBzdFJlZjpkb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Pw8p73+72/QdJn0HCjYb5wevubD42/Cr4w+9ttfnF5r6A8T6O+Kyx7R+8/nv9R+Z+vvE+N8o/c9Xr9f9LvfQE7X37qXx3hj5M/Fj7MXs4yfe/037TeiPt4fCVJ9Y+SeQf8AM3016h8R4fwX/H/DdnT/AG3d+gaJUj5p+xd4/jN7S/E32BjP7F/pj0b5F6M+PS56T9S+cf1L5N689P8AT9Z/uOl1u/8Ao976BZtGPkN0v5Avy++I/wAnvhrXb389Oeket7k/CiUPVnyI9K/0z6O8163R8L+x8B4zpfk7foCk4W/it8LpB+FHx2+5d8LYK+RHtB5r6Z9f+z7o+KvnXn/9DeTeB7nZ4P8AT6ff8b+PZ9Bz0/8A2ifeE/8Agd92T4uf+kfvP77/AA+/9sfF+g//AA3yb/o+g//Z
# base64 【解码】
import base64
def base64_decode_file(base64_data):
    img_data = base64.b64decode(base64_data)
    with open('1.jpg', 'wb') as f:
        f.write(img_data)
# 输入
base64_decode_file("/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABkAAD/4QMbaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA3LjEtYzAwMCA3OS5jY2Y4NGUwLCAyMDIyLzA2LzIyLTIyOjEzOjI2ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZ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+bAWD3lpv8gPsG/AeWfj77c+nPOPTTe+Kfo32796/IvOPX3r3ueN/ZdXwXW88/3u5+t9Bwb8cf9xn7Fuj7U3yB+JXvLI3lHpv2I8p9ZeLI+ou57jf8T8f4Xwfi/CfsPE9/ufn6n0B7GP71bw5nqfKTpeHH6vh/if4jp9LfqeG8J+78R3O3p9H9Xv8AZ3Pzdn0DI/4/vzE/t47Ofb87nzl+Xch+lPcv0P5F648fX/1p0fW/9NeG9rvFf98fn8263d/DofQGY7vuadr7+978evtH+oLJ/JfxXtz0PajzpgfD3r+1P/NPxvuN0+3y3991O74//S+g0jnT+WXxULfGv4+/bV+Gsk++Pu96M9H+adBifGjoeov638m8R0fC+Xfpdbp+L/0/oJ17dz7i38dfs+Nfc+LtjOn1/AeuO98WGn3Pj32/q+m+l3ur0Pw8p73+72/QdJn0HCjYb5wevubD42/Cr4w+9ttfnF5r6A8T6O+Kyx7R+8/nv9R+Z+vvE+N8o/c9Xr9f9LvfQE7X37qXx3hj5M/Fj7MXs4yfe/037TeiPt4fCVJ9Y+SeQf8AM3016h8R4fwX/H/DdnT/AG3d+gaJUj5p+xd4/jN7S/E32BjP7F/pj0b5F6M+PS56T9S+cf1L5N689P8AT9Z/uOl1u/8Ao976BZtGPkN0v5Avy++I/wAnvhrXb389Oeket7k/CiUPVnyI9K/0z6O8163R8L+x8B4zpfk7foCk4W/it8LpB+FHx2+5d8LYK+RHtB5r6Z9f+z7o+KvnXn/9DeTeB7nZ4P8AT6ff8b+PZ9Bz0/8A2ifeE/8Agd92T4uf+kfvP77/AA+/9sfF+g//AA3yb/o+g//Z")
# 输出:(是一个jpg图片文件)

3、ASCLL码 编码解码

# ASCLL【编码】 
def ASCLL_encode(string):
    result = []
    for a in string:
        result = result + [ord(a)]
    return result
# 输入
print(ASCLL_encode('你好'))
# 输出(列表):[20320, 22909]
# ASCLL【解码】 
def ASCLL_decode(string):
    result = ""
    for a in eval(string):
        result = result + chr(a)
    return result
# 输入(列表)
print(ASCLL_decode('[20320, 22909]'))
# 输出:你好

4、Unicode编码解码

# Unicode 【编码】 (仅对中文有效)
def str_to_unicode(str_data):
    return str_data.encode('unicode_escape').decode('utf-8')
# 输入
print(str_to_unicode('你好'))
# 输出:\u4f60\u597d
# Unicode 【解码】
def unicode_to_str(unicode_str):
    return unicode_str
# 输入
print(unicode_to_str('\u4f60\u597d'))
# 输出:你好

5、UTF-8编码解码

# UTF-8 【编码】
def utf8_encode(str_data):
    return str_data.encode('utf-8')
# 输入
print(utf8_encode('你好'))
# 输出:b'\xe4\xbd\xa0\xe5\xa5\xbd'
# UTF-8 【解码】
# 输入
print(b'\xe4\xbd\xa0\xe5\xa5\xbd'.decode('utf-8'))
# 输出:你好

6、URL 编码解码

# 方法一
# URL 【编码】 (仅对中文有效)
import urllib.parse
def URL_encode(url):
    return urllib.parse.quote(url)
# 输入
print(URL_encode('你好'))
# 输出:%E4%BD%A0%E5%A5%BD
# 方法二
# URL 【编码】 (对所有字符串有效)
def URL_encode(url):
    return ''.join([hex(ord(c)).replace('0x', '%') for c in url])
# 输入
print(URL_encode('http://www.baidu.com'))
# 输出:%68%74%74%70%3a%2f%2f%77%77%77%2e%62%61%69%64%75%2e%63%6f%6d
# URL 【解码】
import urllib.parse
def URL_decode(url):
    return urllib.parse.unquote(url)
# 输入
print(URL_decode('%E4%BD%A0%E5%A5%BD'))
# 输出:你好

7、摩斯密码 编码解码

# 摩斯密码字典  【必备 必须添加】(后续会更新更多)
# 摩斯密码会把正常的英文都统一为大写,输出会变为大写
# !!!!加解密有限制,只能对 【英文和数字】 进行加解密。字典需更新
MORSE_CODE_DICT = {
    'A':'.-','B':'-...','C':'-.-.','D':'-..',
    'E':'.','F':'..-.','G':'--.','H':'....',
    'I':'..', 'J':'.---', 'K':'-.-',
    'L':'.-..', 'M':'--', 'N':'-.','O':'---', 'P':'.--.', 'Q':'--.-',
    'R':'.-.', 'S':'...', 'T':'-',
    'U':'..-', 'V':'...-', 'W':'.--',
    'X':'-..-', 'Y':'-.--', 'Z':'--..',
    '1':'.----', '2':'..---', '3':'...--',
    '4':'....-', '5':'.....', '6':'-....',
    '7':'--...', '8':'---..', '9':'----.',
    '0':'-----', ', ':'--..--', '.':'.-.-.-',
    '?':'..--..', '/':'-..-.', '-':'-....-',
    '(':'-.--.', ')':'-.--.-',' ':' '}
# 摩斯密码【加密】 (通用版)  与互联网上的相匹配,可以通用,前提是字典要齐全
# 这个加密包不含空格,原本含有空格的字符串会被替换为无(不含空格的加密)
def morse_encode(message):
    cipher = ''
    set = 0
    for letter in message.replace(' ','').upper():
        if set == 1:
            cipher += '/'
        if letter != ' ':
            cipher += MORSE_CODE_DICT[letter]
            set = 1
    return cipher
# 输入
print(morse_encode('abc'))
# 输出:.-/-.../-.-.
# 摩斯密码【解密】 (通用版)  与互联网上的相匹配,可以通用,前提是字典要齐全
# (不含空格的解密)
def decode_morse_code(code):
    code = code.replace('/',' ')
    # 将摩斯密码字符串按空格分割
    code_list = code.split(' ')
    # 定义解密后的字符串
    decode_str = ''
    # 遍历摩斯密码字符串列表
    for code_str in code_list:
        # 将摩斯密码字符串从字典中取出对应的字符
        decode_str += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT.values()).index(code_str)]
    # 返回解密后的字符串
    return decode_str
# 输入
print(decode_morse_code('.-/-.../-.-.'))
# 输出:ABC
# 摩斯密码【加密】 (修改版 私用)  加密后的摩斯密码只能通过下面的那个脚本进行解密
# 这个加密包含空格,原本含有空格的字符串都会加密(加密含空格)
def morses_encode(message):
    cipher = ''
    set = 0
    for letter in message.upper():
        if set != 0:
            cipher += '/'
        if letter != ' ':
            cipher += MORSE_CODE_DICT[letter]
            set += 1
        else:
            set = 0
            cipher += '&/'
    return cipher
# 输入
print(morses_encode('ab c'))
# 输出:.-/-.../&/-.-.
# 摩斯密码【解密】 (修改版 私用)  也可以用于互联网的加解密,可以通用,前提是字典要齐全
# (解密含空格)可通用
def decodes_morse_code(code):
    code = code.replace('/',' ')
    # 将摩斯密码字符串按空格分割
    code_list = code.split(' ')
    # 定义解密后的字符串
    decode_str = ''
    # 遍历摩斯密码字符串列表
    for code_str in code_list:
        if code_str == '&':
            decode_str += ' '
        else:
            # 将摩斯密码字符串从字典中取出对应的字符
            decode_str += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT.values()).index(code_str)]
    # 返回解密后的字符串
    return decode_str
# 输入
print(decodes_morse_code('.-/-.../&/-.-.'))
# 输出:AB C

8、hexstr 编码解码

<code class="language-plaintext hljs"># hexstr 【编码】
import binascii
def hexstr_encode(data):
    return binascii.b2a_hex(data.encode()).decode()
# 输入
print(hexstr_encode('你好'))
# 输出:e4bda0e5a5bd</code>
<code class="language-plaintext hljs"># hexstr 【解码】
import binascii
def encode_hexstr(data):
    return binascii.a2b_hex(data).decode()
# 输入
print(encode_hexstr('e4bda0e5a5bd'))
# 输出:你好</code>

四、字符串转换

1、中文&繁体

# 简体转繁体
import opencc
def convert_opencc(text):
    return opencc.OpenCC('s2t').convert(text)
# 输入
print(convert_opencc('线类'))
# 输出:線類
# 繁体转简体
import opencc
def opencc_convert(text):
    return opencc.OpenCC('t2s').convert(text)
# 输入
print(opencc_convert('線類'))
# 输出:线类

2、字符串 大写&小写

# 字符串转大写
def exchange_upper(str):
    return str.upper()
# 输入
print(exchange_upper('abc'))
# 输出:ABC
# 字符串转小写
def exchange_lower(str):
    return str.lower()
# 输入
print(exchange_lower('ABC'))
# 输出:abc

3、字符串 全角&半角

# 半角转全角
def strB2Q(ustring):
    """半角转全角"""
    rstring = ""
    for uchar in ustring:
        inside_code=ord(uchar)
        if inside_code == 32:    # 半角空格直接转化
            inside_code = 12288
        elif inside_code >= 32 and inside_code <= 126:   # 半角字符(除空格)根据关系转化
            inside_code += 65248
        rstring += chr(inside_code)
    return rstring
# 输入
print(strB2Q('123abc'))
# 输出:123abc
# 全角转半角
def strQ2B(ustring):
    """全角转半角"""
    rstring = ""
    for uchar in ustring:
        inside_code = ord(uchar)
        if inside_code == 12288:   # 全角空格直接转换
            inside_code = 32
        elif (inside_code >= 65281 and inside_code <= 65374):  # 全角字符(除空格)根据关系转化
            inside_code -= 65248
        rstring += chr(inside_code)
    return rstring
# 输入
print(strQ2B('123abc'))
# 输出:123abc

4、时间戳 & 日期

# 日期转时间戳
import time
def Unix_time(times):
    # 转换为时间戳,将"%Y-%m-%d %H:%M:%S"转换为 1672989181字符串
    return int(time.mktime(time.strptime(times, '%Y-%m-%d %H:%M:%S')))
# 输入
print(Unix_time('2023-01-01 15:12:07'))
# 输出:1672557127
# 时间戳转日期
import time
def time_Unix(times):
    # 转换为其他日期格式,如:"%Y-%m-%d %H:%M:%S"
    return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(times))
# 输入
print(time_Unix('1672557127'))
# 输出:2023-01-01 15:12:07

5、颜色 HEX & RGB & CMYK

# HEX 转 RGB(元组)
def hex_to_rgb(hex_color):
    hex_color = hex_color.lstrip('#')
    lv = len(hex_color)
    return tuple(int(hex_color[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
# 输入
print(hex_to_rgb('#FFFFFF'))
# 输出(元组):(255, 255, 255)
# RGB(元组) 转 HEX
def rgb_to_hex(rgb_color):
    return '#%02x%02x%02x' % rgb_color
# 输入(元组)
print(rgb_to_hex((255, 255, 255))) 
# 输出:#FFFFFF
# RGB(元组) 转 CMYK(元组)
def rgb_to_cmyk(rgb):
    r = rgb[0] / 255.0
    g = rgb[1] / 255.0
    b = rgb[2] / 255.0
    c = 1 - r
    m = 1 - g
    y = 1 - b
    k = min(c, m, y)
    c = (c - k) / (1 - k)
    m = (m - k) / (1 - k)
    y = (y - k) / (1 - k)
    cmyk = (c, m, y, k)
    return cmyk
# 输入(元组)
print(rgb_to_cmyk((198, 254, 234))) 
# 输出(元组):(0.2204724409448819, 0.0, 0.07874015748031502, 0.0039215686274509665)
#  CMYK(元组) 转 RGB(元组)
def cmyk_to_rgb(cmyk):
    c = cmyk[0]
    m = cmyk[1]
    y= cmyk[2]
    k = cmyk[3]
    r = int(255 * (1 - c) * (1 - k))
    g = int(255 * (1 - m) * (1 - k))
    b = int(255 * (1 - y) * (1 - k))
    rgb = (r, g, b)
    return rgb
# 输入(元组)
print(cmyk_to_rgb((0.2204724409448819, 0.0, 0.07874015748031502, 0.0039215686274509665))) 
# 输出(元组):(198, 254, 234)

五、进制转换

1、【2进制】 转 4进制、8进制、10进制、16进制、32进制

# 2进制 转 4进制
def binary_to_quaternary(binary):
    # 将2进制转换为10进制
    decimal = int(binary, 2)
    # 将10进制转换为4进制
    quaternary = ''
    while decimal != 0:
        remainder = decimal % 4
        decimal = decimal // 4
        quaternary = str(remainder) + quaternary
    return quaternary
# 输入
print(binary_to_quaternary('1101110110111')) 
# 输出:1232313
# 2进制 转 8进制
# 输入
print(oct(int('1101110110111',2)))  # 2进制 转 8进制
# 输出:0o15667
# 2进制 转 10进制
# 输入
print(str(int('1101110110111',2)))  # 2进制 转 10进制
# 输出:7095
# 2进制 转 16进制
# 输入
print(hex(int('1101110110111',2)))  # 2进制 转 16进制
# 输出:0x1bb7
# 2进制 转 32进制
def binary_to_base32(binary):
    # 定义一个字典,用于存储2进制到32进制的映射关系
    base32_dict = {
        '00000': '0',
        '00001': '1',
        '00010': '2',
        '00011': '3',
        '00100': '4',
        '00101': '5',
        '00110': '6',
        '00111': '7',
        '01000': '8',
        '01001': '9',
        '01010': 'A',
        '01011': 'B',
        '01100': 'C',
        '01101': 'D',
        '01110': 'E',
        '01111': 'F',
        '10000': 'G',
        '10001': 'H',
        '10010': 'I',
        '10011': 'J',
        '10100': 'K',
        '10101': 'L',
        '10110': 'M',
        '10111': 'N',
        '11000': 'O',
        '11001': 'P',
        '11010': 'Q',
        '11011': 'R',
        '11100': 'S',
        '11101': 'T',
        '11110': 'U',
        '11111': 'V'
    }
    binary = (5 - len(binary) % 5) * '0' + binary
    # 将2进制字符串转换为列表
    binary_list = list(binary)
    # 将2进制列表转换为5位2进制字符串的列表
    binary_list_5 = [binary_list[i:i+5] for i in range(0, len(binary_list), 5)]
    # 将2进制字符串列表转换为32进制字符串
    base32_str = ''
    for binary_str in binary_list_5:
        base32_str += base32_dict[''.join(binary_str)]
    return base32_str
# 输入
print(binary_to_base32('1101110110111'))
# 输出:6TN

2、【4进制】 转 2进制、8进制、10进制、16进制、32进制

# 4进制 转 2进制
# 输入
print(bin(int('1101110110111',4)))   
# 输出:0b1010001010100010100010101
# 4进制 转 8进制
# 输入
print(oct(int('1101110110111',4)))   
# 输出:0o121242425
# 4进制 转 10进制
# 输入
print(str(int('1101110110111',4)))   
# 输出:21316885
# 4进制 转 16进制
# 输入
print(hex(int('1101110110111',4)))   
# 输出:0x1454515
# 4进制 转 32进制
def binary_to_base32(binary):
    # 4进制 转 2进制
    binary = bin(int(binary,4))
    if binary[0:][:2] == '0b':
        binary = binary.replace('0b','')
    # 2进制 转 32进制
    # 定义一个字典,用于存储2进制到32进制的映射关系
    base32_dict = {
        '00000': '0',
        '00001': '1',
        '00010': '2',
        '00011': '3',
        '00100': '4',
        '00101': '5',
        '00110': '6',
        '00111': '7',
        '01000': '8',
        '01001': '9',
        '01010': 'A',
        '01011': 'B',
        '01100': 'C',
        '01101': 'D',
        '01110': 'E',
        '01111': 'F',
        '10000': 'G',
        '10001': 'H',
        '10010': 'I',
        '10011': 'J',
        '10100': 'K',
        '10101': 'L',
        '10110': 'M',
        '10111': 'N',
        '11000': 'O',
        '11001': 'P',
        '11010': 'Q',
        '11011': 'R',
        '11100': 'S',
        '11101': 'T',
        '11110': 'U',
        '11111': 'V'
    }
    binary = (5 - len(binary) % 5) * '0' + binary
    # 将2进制字符串转换为列表
    binary_list = list(binary)
    # 将2进制列表转换为5位2进制字符串的列表
    binary_list_5 = [binary_list[i:i+5] for i in range(0, len(binary_list), 5)]
    # 将2进制字符串列表转换为32进制字符串
    base32_str = ''
    for binary_str in binary_list_5:
        base32_str += base32_dict[''.join(binary_str)]
    return base32_str
# 输入
print(binary_to_base32('11011101101111011'))
# 输出:52KA5A5

3、【8进制】 转 2进制、4进制、10进制、16进制、32进制

# 8进制 转 2进制
# 输入
print(bin(int('1101110110111',8)))   
# 输出:0b1001000001001001000001001000001001001
# 8进制 转 4进制
def binary_to_quaternary(binary):
    # 将8进制转换为10进制
    decimal = int(binary,8)
    # 将10进制转换为4进制
    quaternary = ''
    while decimal != 0:
        remainder = decimal % 4
        decimal = decimal // 4
        quaternary = str(remainder) + quaternary
    return quaternary
 
# 输入
print(binary_to_quaternary('1101110110111'))  
# 输出:1020021020021001021
# 8进制 转 10进制
# 输入
print(str(int('1101110110111',8)))   
# 输出:77462540361
# 8进制 转 16进制 
# 输入
print(hex(int('1101110110111',8)))   
# 输出:0x1209209049
# 8进制 转 32进制
def binary_to_base32(binary):
    # 8进制 转 2进制
    binary = bin(int(binary,8))
    if binary[0:][:2] == '0b':
        binary = binary.replace('0b','')
    # 2进制 转 32进制
    # 定义一个字典,用于存储2进制到32进制的映射关系
    base32_dict = {
        '00000': '0',
        '00001': '1',
        '00010': '2',
        '00011': '3',
        '00100': '4',
        '00101': '5',
        '00110': '6',
        '00111': '7',
        '01000': '8',
        '01001': '9',
        '01010': 'A',
        '01011': 'B',
        '01100': 'C',
        '01101': 'D',
        '01110': 'E',
        '01111': 'F',
        '10000': 'G',
        '10001': 'H',
        '10010': 'I',
        '10011': 'J',
        '10100': 'K',
        '10101': 'L',
        '10110': 'M',
        '10111': 'N',
        '11000': 'O',
        '11001': 'P',
        '11010': 'Q',
        '11011': 'R',
        '11100': 'S',
        '11101': 'T',
        '11110': 'U',
        '11111': 'V'
    }
    binary = (5 - len(binary) % 5) * '0' + binary
    # 将2进制字符串转换为列表
    binary_list = list(binary)
    # 将2进制列表转换为5位2进制字符串的列表
    binary_list_5 = [binary_list[i:i+5] for i in range(0, len(binary_list), 5)]
    # 将2进制字符串列表转换为32进制字符串
    base32_str = ''
    for binary_str in binary_list_5:
        base32_str += base32_dict[''.join(binary_str)]
    return base32_str
# 输入
print(binary_to_base32('1101110110111'))
# 输出:284I1429

4、【10进制】 转 2进制、4进制、8进制、16进制、32进制

# 10进制 转 2进制
# 输入
print(bin(int('1101110110111',10)))   
# 输出:0b1001000001001001000001001000001001001
# 10进制 转 4进制
def dec2four(num):
    # 定义一个空列表,用于存放转换后的四进制数
    four_list = []
    num = int(num)
    # 循环,直到num为0
    while num != 0:
        # 将num除以4的余数添加到列表中
        four_list.append(num % 4)
        # 将num除以4,得到新的num
        num = num // 4
    # 将列表中的数字反转
    four_list.reverse()
    # 将列表中的数字转换为字符串
    four_str = ''.join(str(i) for i in four_list)
    # 返回转换后的四进制数
    return four_str
 
# 输入
print(dec2four('1101110110111'))
# 输出:100001133101232132133
# 10进制 转 8进制
# 输入
print(oct(int('1101110110111',10)))   
# 输出:0o20013721563637
# 10进制 转 16进制
# 输入
print(hex(int('1101110110111',10)))   
# 输出:0x1005f46e79f
# 10进制 转 32进制
def binary_to_base32(num, b = 32):
    num = int(num)
    return ((num == 0) and "0") or (binary_to_base32(num // b, b).lstrip("0") + "0123456789abcdefghijklmnopqrstuvwxyz"[num % b])
# 输入
print(binary_to_base32('1101110110111'))  
# 输出:101fkdpsv

5、【16进制】 转 2进制、4进制、8进制、10进制、32进制

# 16进制 转 2进制
# 输入
print(bin(int('1241241243',16)))
# 输出:0b1001001000001001001000001001001000011
# 16进制 转 4进制
def binary_to_quaternary(binary):
    # 将16进制转换为10进制
    decimal = int(binary, 16)
    # 将10进制转换为4进制
    quaternary = ''
    while decimal != 0:
        remainder = decimal % 4
        decimal = decimal // 4
        quaternary = str(remainder) + quaternary
    return quaternary
# 输入
print(binary16_to_quaternary('1241241243'))
# 输出:1021001021001021003
# 16进制 转 8进制
# 输入
print(oct(int('1241241243',16)))   
# 输出:0o1110111011103
# 16进制 转 10进制 
# 输入
print(str(int('1241241243',16)))   
# 输出:78402294339
# 16进制 转 32进制
def binary_to_base32(binary):
    # 16进制 转 2进制
    binary = bin(int(binary,16))
    if binary[0:][:2] == '0b':
        binary = binary.replace('0b','')
    # 2进制 转 32进制
    # 定义一个字典,用于存储2进制到32进制的映射关系
    base32_dict = {
        '00000': '0',
        '00001': '1',
        '00010': '2',
        '00011': '3',
        '00100': '4',
        '00101': '5',
        '00110': '6',
        '00111': '7',
        '01000': '8',
        '01001': '9',
        '01010': 'A',
        '01011': 'B',
        '01100': 'C',
        '01101': 'D',
        '01110': 'E',
        '01111': 'F',
        '10000': 'G',
        '10001': 'H',
        '10010': 'I',
        '10011': 'J',
        '10100': 'K',
        '10101': 'L',
        '10110': 'M',
        '10111': 'N',
        '11000': 'O',
        '11001': 'P',
        '11010': 'Q',
        '11011': 'R',
        '11100': 'S',
        '11101': 'T',
        '11110': 'U',
        '11111': 'V'
    }
    binary = (5 - len(binary) % 5) * '0' + binary
    # 将2进制字符串转换为列表
    binary_list = list(binary)
    # 将2进制列表转换为5位2进制字符串的列表
    binary_list_5 = [binary_list[i:i+5] for i in range(0, len(binary_list), 5)]
    # 将2进制字符串列表转换为32进制字符串
    base32_str = ''
    for binary_str in binary_list_5:
        base32_str += base32_dict[''.join(binary_str)]
    return base32_str
# 输入
print(binary16_to_base32('1241241243'))
# 输出:290I84I3

6、【32进制】 转 2进制、4进制、8进制、10进制、16进制

# 32进制 转 2进制
# 输入
print(bin(int('123456789',32)))   
# 输出:0b10001000011001000010100110001110100001001
# 32进制 转 4进制
def binary_to_quaternary(binary):
    # 将32进制转换为10进制
    decimal = int(binary, 32)
    # 将10进制转换为4进制
    quaternary = ''
    while decimal != 0:
        remainder = decimal % 4
        decimal = decimal // 4
        quaternary = str(remainder) + quaternary
    return quaternary
# 输入
print(binary_to_quaternary('123456789'))
# 输出:101003020110301310021
# 32进制 转 8进制
# 输入
print(oct(int('123456789',32)))   
# 输出:0o21031024616411
# 32进制 转 10进制
# 输入
print(str(int('123456789',32)))   
# 输出:1171591994633
# 32进制 转 16进制 
# 输入
print(hex(int('123456789',32)))   
# 输出:0x110c8531d09

以上就是Python实现加解密,编码解码和进制转换(最全版)的详细内容,更多关于Python加解密 编码解码 进制转换的资料请关注脚本之家其它相关文章!

您可能感兴趣的文章:
阅读全文