Python实现加解密,编码解码和进制转换(最全版)
小木_. 人气:0请先安装这几个模块
# 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)) # 输出:
加载全部内容
- 猜你喜欢
- 用户评论