#原宽高检测脚本 import zlib import struct filename = '1.png' with open(filename, 'rb') as f: all_b = f.read() crc32key = int(all_b[29:33].hex(),16) data = bytearray(all_b[12:29]) n = 4095 for w in range(n): width = bytearray(struct.pack('>i', w)) for h in range(n): height = bytearray(struct.pack('>i', h)) for x in range(4): data[x+4] = width[x] data[x+8] = height[x] crc32result = zlib.crc32(data) if crc32result == crc32key: print("宽为:",end="") print(width) print("高为:",end="") print(height)
def get_base64_diff_value(s1, s2): base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' res = 0 for i in xrange(len(s2)): if s1[i] != s2[i]: return abs(base64chars.index(s1[i]) - base64chars.index(s2[i])) return res
def solve_stego(): with open('flag.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) else: bin_str += '0' * pads_num * 2 print goflag(bin_str)
def goflag(bin_str): res_str = '' for i in xrange(0, len(bin_str), 8): res_str += chr(int(bin_str[i:i + 8], 2)) return res_str
#!/usr/bin/env python import base64 import re def baseDec(text, type): if type == 1: return base64.b16decode(text) elif type == 2: return base64.b32decode(text) elif type == 3: return base64.b64decode(text) elif type == 4: return base64.b85decode(text) else: pass def detect(text): try: if re.match("^[0-9A-F=]+$", text.decode()) is not None: return 1 except: pass try: if re.match("^[A-Z2-7=]+$", text.decode()) is not None: return 2 except: pass try: if re.match("^[A-Za-z0-9+/=]+$", text.decode()) is not None: return 3 except: pass return 4 def autoDec(text): while True: if b"MRCTF{" in text: print("\n" + text.decode()) break code = detect(text) text = baseDec(text, code) with open("flag.txt", 'rb') as f: flag = f.read() autoDec(flag)
def main(): parser = build_parser() options = parser.parse_args() ori = options.ori img = options.img res = options.res alpha = options.alpha if not os.path.isfile(ori): parser.error("original image %s does not exist." % ori) if not os.path.isfile(img): parser.error("image %s does not exist." % img) decode(ori, img, res, alpha)
def decode(ori_path, img_path, res_path, alpha): ori = cv2.imread(ori_path) img = cv2.imread(img_path) ori_f = np.fft.fft2(ori) img_f = np.fft.fft2(img) height, width = ori.shape[0], ori.shape[1] watermark = (ori_f - img_f) / alpha watermark = np.real(watermark) res = np.zeros(watermark.shape) random.seed(height + width) x = range(height / 2) y = range(width) random.shuffle(x) random.shuffle(y) for i in range(height / 2): for j in range(width): res[x[i]][y[j]] = watermark[i][j] cv2.imwrite(res_path, res, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
picture=Image.new("RGB",(MAX,MAX)) for y in range(MAX): for x in range(MAX): string =file.readline() picture.putpixel([x,y],eval(string)) #直接使用eval()可以转为元组 picture.show()
#词频统计 http://corpus.zhonghuayuwen.org/CpsTongji.aspx import re file = open('D:/edge/read/11.txt') line = file.readlines() file.seek(0,0) file.close()
result = {} for i in range(97,123): count = 0 for j in line: find_line = re.findall(chr(i),j) count += len(find_line) result[chr(i)] = count res = sorted(result.items(),key=lambda item:item[1],reverse=True)
num = 1 for x in res: print('频数第{0}: '.format(num),x) num += 1
#encoding=GBK f = open('data.txt','w') s = "Hello everyone, I am Gilbert. Everyone thought that I was killed, but actually I survived. Now that I have no cash with me and I’m trapped in another country. I can't contact Violet now. She must be desperate to see me and I don't want her to cry for me. I need to pay 300 for the train, and 88 for the meal. Cash or battlenet point are both accepted. I don't play the Hearthstone, and I don't even know what is Rastakhan's Rumble." f.write(s) f.close()