# coding=utf-8
import base64
import chardet
a = b"\260\332\266\311\311\350\261\270\310\325\326\276\312\325\274\257\304\243\277\351"
strings = '496CCJL*_F0<h0(c2E0`D0#_%cfN'
decode_from_base64 = base64.b64decode(strings) #解码base64编码后的字符,编码用 ====> base64.b64encode(strings)
before_then = chardet.detect(decode_from_base64)
fencoding = chardet.detect(a) #这行可以判断当前字符串的格式,以便后面设置打印字符的字符编码
print(str(fencoding)+'//n'+str(before_then))
astring = a.decode('GB2312')
print(decode_from_base64)
#ctfstring =decode_from_base64.decode('utf8', errors='ignore')
ctfstring =decode_from_base64.decode('Windows-1252', errors='ignore')
print(astring,ctfstring)
for_example_sting = "what is you name?"
s = base64.b64encode(bytes(for_example_sting,'utf-8'))
print(chardet.detect(s))
from itertools import combinations, permutations
a = '496CCJL*_F0<h0(c2E0`D0#_%cfN'
[chr(c-47 if c > 80 else c+47) for c in [ord(b) for b in a ]] # boss show
add1 = lambda n1, n2, n3, a: ''.join([chr(abs(e + n1 if e < n3 else e - n1)) for e in [ord(i) for i in a]])
example_list = list(range(200))
per = lambda example ,range1: list(permutations(example ,range1)) #组合计算
list_maybe = [add1(i[0],i[1],i[2],a) for i in per(example_list,3)]
print(set([i for i in list_maybe if i[0:6]=='cherry']))
'''R0T47编码'''
ROT47_1 = lambda strings :''.join([chr(33+(e+14)%94) for e in [ord(i) for i in strings] if e >=33 and e <= 126])
ROT47_2 = lambda strings : [chr(c-47 if c > 80 else c+47) for c in [ord(b) for b in strings ]]
'''图像处理'''
import matplotlib.pyplot as plt # plt 用于显示图片
import matplotlib.image as mpimg # mpimg 用于读取图片
import numpy as np
lena = mpimg.imread('/Users/deleter/Downloads/bnwlk.jpg') # 读取和代码处于同一目录下的 lena.png
# 此时 lena 就已经是一个 np.array 了,可以对它进行任意处理
lena.shape #(512, 512, 3)
open('/Users/deleter/Downloads/bnwlk.jpg','rb').read()
jpg_data_hex = open('/Users/deleter/Downloads/bnwlk.jpg','rb').read().splitlines()
flag_text = [i for i in jpg_data_hex if 'flag' in str(i)]
jpg_logo = [i for i in jpg_data_hex if 'jpg' in str(i)]
jpg_body = [i for i in jpg_data_hex if 'jpg' not in str(i) and 'flag' not in str(i)]
type_decode = lambda strings : chardet.detect(strings)
print(type_decode(flag_text[0]))
加解密练习
最新推荐文章于 2023-12-11 13:37:51 发布