base64深入理解与判断base32base16
Posted 李白你好
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了base64深入理解与判断base32base16相关的知识,希望对你有一定的参考价值。
加密原理
第一步:“M”、“a”、"n"对应的ASCII码值分别为77,97,110,对应的二进制值是01001101、01100001、01101110。如图第二三行所示,由此组成一个24位的二进制字符串。
第二步:如图红色框,将24位每6位二进制位一组分成四组,不足的补0。
第三步:在上面每一组前面补两个0,扩展成32个二进制位,此时变为四个字节:00010011、00010110、00000101、00101110。分别对应的值(Base64编码索引)为:19、22、5、46。
第四步:用上面的值在Base64编码表中进行查找,分别对应:T、W、F、u。因此“Man”Base64编码之后就变为:TWFu。
Base64、Base32和Base16的简单区别
- Base64,包含大写字母(A-Z),小写字母(a-z),数字(0-9)以及+/;
- Base32,只有大写字母(A-Z)和数字234567;
- Base16,只有16进制的数据,其范围是数字(0-9),字母(ABCDEF)。
python代码实现
#coding=utf-8
import base64
import re
basestring="NEU1NDREMzE0RTQ0NTUzMjRFNDQ2NzMxNEU2QTVBNDQ0RTU0NTkzMTRFN0E1NTc4NEQ3QTQxMzI0RjQ0NTI0MzRFNTQ2MzMyNTE2QTUyNDI0RTQ0NjMzMTREN0E1NTMyNEU0NDZCMzM0RjU0NTUzMDRFNkI0OTMzNEY0NDUyNDM0RTU0NEQ3QTRENDQ1NTMxNEQ3QTQ5MzE0RTZBNTEzMTRFN0E0RDMzNEY1NDU1N0E0RDdBNDUzMDUxNTQ1MTMxNEU1NDU5MzE0RTQ0NTI0MjRFNDU1NTMxNEU1NDRENzg0RTU0NTkzMDUxNTQ1MjQ2NEU1NDU1MzI0RTQ0NTUzMzRFNTQ1OTMxNEU2QTU2NDI0RTQ0NTEzMTREN0E1MTMxNEU2QTUxMzE0RDdBNTUzMDRFNkI0OTMxNTE1NDUyNDI0RTU0NTUzMjUxNTQ1MjQyNEU0NTU5MzE0RTQ0NTEzMTRFN0E0MTMwNTE3QTU1MzI0RTU0NTU3QTRGNTQ1NTMxNEU1N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0NDkzMTRFNDQ1NjQyNEU1NDQ5MzE0RDQ0NTUzMDREN0E0MTdBNEY1NDU1Nzc0RTU0NDU3QTUyNDQ0RTQ1"
while(1):
base64_flag=0
if(''in basestring):#flag形式
break
for i in basestring:
if(i.islower()):
basestring=base64.b64decode(basestring)#base64编码
print "base64 encode"
base64_flag=1
break
if(base64_flag):
continue
elif(re.match('^[G-Z]',basestring)):#base32编码
print "base32 encode"
basestring=base64.b32decode(basestring)
continue
else:
print "base16 encode"
basestring=base64.b16decode(basestring)#base16编码
continue
print basestring
以上是关于base64深入理解与判断base32base16的主要内容,如果未能解决你的问题,请参考以下文章