Python101
加解密
import hashlib
# md5, sha1, sha224, sha256, sha384, sha512
s = 'hello world'
m = hashlib.md5()
m.update(s.encode('utf8'))
print(m.digest())
print(m.hexdigest())
# ripemd160, whirlpool
s = 'hello world'
m = hashlib.new('ripemd160', s.encode('utf8'))
print(m.digest())
print(m.hexdigest())import gmpy2
p = 168870409632549765296862502254899759857248288652407554850383477768823119986297924033151555409082356346297282197467254809081931208549224155851315637344747298357415893525472097154103238042019866682938382139834279447488738548244853184293595933654527554670457923545588565351501521501815389298997833861578226633099
q = 136505636991931352215759862754723380107419404176934963805672183755717752956589135238497377957828097441347957566489629211243389022288160648357324629288547621047463026266886900467398707294913322326802718447765393605735412855505214780439471729354761056917299208670362196028628829497574575055117449119342100056517
e = 65537
n = p * q
fn = (p - 1) * (q - 1)
d = gmpy2.invert(e, fn)
# encode
plain = "hello world"
cipher = gmpy2.powmod(int(plain.hex(),16), e, n)
print cipher
# decode
cipher = 17123126358168532314364171789745947147158203528255189528376034042576955961464108007241396193221317579386199055678187296416631757350036173529280264692509105557539380445658352098757386832691606291403716717255406122398828996166165137869000756490419628668837727171987655840934249710275220041791912411702429566338522067039808551028470065040909781794268938955092150084715883613062506445552253043511850366325327543440113474870896494812927181373067664361593089869517445577240126156141735331979758927134194252186254770372018574046630061371952143328299376196926784339615150604268752279279335534713614030849861471450015448322452
plaint = gmpy2.powmod(cipher, d, n)
s = '%x' % plaint
if len(s) % 2 != 0:
s = '0' + s
print(s)