defget_base64_diff_value(s1, s2): base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' res = 0 for i in xrange(len(s2)): #xrange() 函数用法与 range 完全相同,所不同的是生成的不是一个数组,而是一个生成器。 if s1[i] != s2[i]: return abs(base64chars.index(s1[i]) - base64chars.index(s2[i])) #index() 方法查找指定值的首次出现。 return res
defsolve_stego(): with open('ComeOn!.txt', 'rb') as f: file_lines = f.readlines() bin_str = '' for line in file_lines: steg_line = line.replace('\n', '') norm_line = line.replace('\n', '').decode('base64').encode('base64').replace('\n', '') diff = get_base64_diff_value(steg_line, norm_line) print diff pads_num = steg_line.count('=') if diff: bin_str += bin(diff)[2:].zfill(pads_num * 2) #zfill() 方法返回指定长度的字符串,原字符串右对齐,前面填充0。 else: bin_str += '0' * pads_num * 2 print goflag(bin_str)
#将文件列表重新排序(按文件原始数据末尾的数字) for i in range(36,0,-1): # print(i) for file in dir_list: if'.jpg'in file: f=open(file ,'rb') n1 = f.read() n2 = n1[-2:] # print() if i > 9: if str(i) in n2: # all_path.append(os.path.join(file)) all_path.insert(0,os.path.join(file)) # print(all_path) break else: if'd9'in n1.encode('hex')[-4:] and str(i) in n2: # print(file) all_path.insert(0,os.path.join(file)) break print(all_path)