索引 对应字符
0 A
1 B
2 C
3 D
4 E
5 F
6 G
7 H
8 I
9 J
10 K
11 L
12 M
13 N
14 O
15 P
16 Q
17 R
18 S
19 T
20 U
21 V
22 W
23 X
24 Y
25 Z
26 a
27 b
28 c
29 d
30 e
31 f
32 g
33 h
34 i
35 j
36 k
37 l
38 m
39 n
40 o
41 p
42 q
43 r
44 s
45 t
46 u
47 v
48 w
49 x
50 y
51 z
52 0
53 1
54 2
55 3
56 4
57 5
58 6
59 7
60 8
61 9
62 +
63 /
虽然python解base64很方便
最好还是先写个脚本加深对base64的理解
文末我会贴出我的调试脚本那么base64隐写到底是什么东西呢?关键是base64解码的时候
1.检查base64编码后面有几个等于号
2.把字符串按照base64表转换成46的倍数位数二进制
3.__删除等于号的个数8的bit__(等于号不在base64规定的范围内,只是为了补足长度,所以解码时要删除)
4.按照6个bit一组转成字符
此处的关键就是,解码的时候,会删除等于号的个数8的bit
且我们只用6个bit表示一个等于号(xxxxxx)
那么,意思就是我们可以控制__等于号个数2bit__的字符NJCTF2017有一道misc是base64隐写
从里面抽出一条来
import base64
s = "QnkgcmVhc29uIG9mIGhpcyBmYWxsZW4gZGl2aW5pdHm="
print base64.b64decode(s)
print s
print base64.b64encode(base64.b64decode(s))
会发现返回
By reason of his fallen divinity
QnkgcmVhc29uIG9mIGhpcyBmYWxsZW4gZGl2aW5pdHm=
QnkgcmVhc29uIG9mIGhpcyBmYWxsZW4gZGl2aW5pdHk=
base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
def encode(str):
s = str
s_bin = ""
for i in range(0,len(s)):
s_bin = s_bin + bin(ord(s)).replace("0b","").rjust(8,"0") #把每个字符二进制化
print s_bin
if len(s_bin) % 6 != 0: #判断二进制长度能否被6整除
for j in range(1,6):
if (len(s_bin) + j) % 6 == 0:
bin_length = len(s_bin) + j #获取二进制长度
break
s_bin = s_bin.ljust(bin_length,"0") #把二进制长度补到能被6整除
print s_bin
encode = ""
for k in range(0,len(s_bin)/6):
index = k * 6
each_bin = s_bin[index:index+6].zfill(8) #把6Bit再添两位高位0
print each_bin
each_enc = int(each_bin,2) #转化为10进制
print each_enc
encode = encode + base[each_enc]
# print encode
if len(encode) % 4 != 0: #判断解密后字符串是否能被4整除,如果不能,要在末尾加=
for l in range(1,4):
if (len(encode) + l) % 4 == 0:
encode_length = len(encode) + l
print encode.ljust(encode_length,"=")
def raw(str): #获取每位字符的二进制形式
s = str
for i in range(0,len(s)):
print s,bin(ord(s)).replace("0b","").rjust(8,"0")