二进制
base64
- python —— base64 encode/decode
编码解码
class CustomBase64:
CHAR_SET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0!@#$%^&*()-"
@classmethod
def encode(cls, s: str) -> str:
binary_str = ''.join(format(ord(c), '08b') for c in s) # 转化为二进制字符串
padding = 3 - (len(s) % 3) if len(s) % 3 else 0 # 计算需要的填充
binary_str += '0' * (padding * 8)
index_strs = [binary_str[i:i + 6] for i in range(0, len(binary_str), 6)]
encoded = ''.join(cls.CHAR_SET[int(index_str, 2)] for index_str in index_strs)
return encoded[:-padding] + "=" * padding # 添加填充
@classmethod
def decode(cls, s: str) -> str:
padding = s.count('=')
s = s.rstrip('=')
binary_str = ''.join(format(cls.CHAR_SET.index(c), '06b') for c in s) # 转化为二进制字符串
byte_strs = [binary_str[i:i + 8] for i in range(0, len(binary_str), 8)][:-padding]
decoded = ''.join(chr(int(byte_str, 2)) for byte_str in byte_strs)
return decoded
base64包
base64换表
print(base64.b64decode("SGVsbG*sIFdvcmxkIQ==".translate(str.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0!@#$%^&*()-", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"))).decode('utf-8'))
使用标准表作为媒介,转换后进行映射
base64隐写
helo -> aGVsbw==
word -> d29yZA==
helo -> aGVsbw== -> w 48 -> 110000
word -> d29yZA== -> A 0 -> 000000
隐写a->0110 0001
w 48 -> 110000 -> 110110 -> 54 -> 2
A 0 -> 000000 -> 000001 -> 1 -> B
编码变为
helo -> aGVsb2==
word -> d29yZB==
文本混淆
社会主义核心价值观编码——有点小问题
import random
import urllib.parse
def assert_(*express):
l = len(express)
msg = express[l-1] if isinstance(express[l-1], str) else 'Assert Error'
for b in express:
if not b:
raise AssertionError(msg)
def rand_bin():
return random.random() >= 0.5
values = '富强民主文明和谐自由平等公正法治爱国敬业诚信友善'
def str2utf8(s):
not_encoded = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~*'()"
str1 = ''.join([c if c in not_encoded else format(ord(c), 'x') for c in s])
str2 = urllib.parse.quote(str1)
concated = str2.replace('%', '').upper()
return concated
def utf82str(utfs):
assert_(isinstance(utfs, str), 'utfs Error')
l = len(utfs)
assert_((l & 1) == 0)
splited = []
for i in range(l):
if (i & 1) == 0:
splited.append('%')
splited.append(utfs[i])
return urllib.parse.unquote(''.join(splited))
def hex2duo(hexs):
assert_(isinstance(hexs, str))
duo = []
for c in hexs:
n = int(c, 16)
if n < 10:
duo.append(n)
else:
if rand_bin():
duo.append(10)
duo.append(n - 10)
else:
duo.append(11)
duo.append(n - 6)
return duo
def duo2hex(duo):
assert_(isinstance(duo, list))
hexs = []
l = len(duo)
i = 0
while i < l:
if duo[i] < 10:
hexs.append(duo[i])
else:
i += 1
if duo[i-1] == 10:
hexs.append(duo[i] + 10)
else:
hexs.append(duo[i] + 6)
i += 1
return ''.join([format(v, 'X') for v in hexs])
def duo2values(duo):
return ''.join([values[2*d] + values[2*d+1] for d in duo])
def values_decode(encoded):
duo = []
for c in encoded:
i = values.find(c)
if i == -1 or i & 1:
continue
duo.append(i >> 1)
hexs = duo2hex(duo)
assert_((len(hexs) & 1) == 0)
try:
return utf82str(hexs)
except Exception as e:
raise e
def values_encode(s):
return duo2values(hex2duo(str2utf8(s)))
# ------------------
# 假设你有一个简单的命令行界面来代替 HTML 元素
def main():
while True:
choice = input("选择操作 (encode/decode/exit): ").strip().lower()
if choice == 'encode':
decoded = input("输入要编码的字符串: ").strip()
encoded = values_encode(decoded)
print(f"编码结果: {encoded}")
elif choice == 'decode':
encoded = input("输入要解码的字符串: ").strip()
decoded = values_decode(encoded)
print(f"解码结果: {decoded}")
elif choice == 'exit':
break
else:
print("无效的选择,请重新输入。")
if __name__ == "__main__":
main()
兽音译者
beast = ['嗷', '呜', '啊', '~']
def str2hex(text: str):
ret = ""
for x in text:
charHexStr = hex(ord(x))[2:]
if len(charHexStr) == 3:
charHexStr = "0" + charHexStr
elif len(charHexStr) == 2:
charHexStr = "00" + charHexStr
ret += charHexStr
return ret
def hex2str(text: str):
ret = ""
for i in range(0, len(text), 4):
unicodeHexStr = text[i:i + 4]
charStr = chr(int(unicodeHexStr, 16))
ret += charStr
return ret
def encode(str):
hexArray = list(str2hex(str))
code = ""
n = 0
for x in hexArray:
k = int(x, 16) + n % 16
if k >= 16:
k -= 16
code += beast[int(k / 4)] + beast[k % 4]
n += 1
return code
def decode(str):
hexArray = list(str)
code = ""
for i in range(0, len(hexArray), 2):
pos1 = beast.index(hexArray[i])
pos2 = beast.index(hexArray[i + 1])
k = ((pos1 * 4) + pos2) - (int(i / 2) % 16)
if k < 0:
k += 16
code += hex(k)[2:]
return hex2str(code)
if __name__ == '__main__':
print(encode("你好"))
print(decode("呜嗷嗷嗷啊嗷嗷~啊呜~啊~呜呜嗷"))
一些抽象的
与佛论禅
源版:https://www.keyfc.net/bbs/tools/tudoucode.aspx
GitHub 开源重制:https://github.com/takuron/talk-with-buddha
代码混淆
原文:test
-
jsfuck :
(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]
-
Brainfuck :
+++++ +++++ [->++ +++++ +++<] >++++ +++++ +++++ ++.<+ ++[-> ---<] >---- --.<+ ++[-> +++<] >++++ +.+.<
-
JJEncode :
_=~[];_={___:++_,$$$$:(![]+"")[_],__$:++_,$_$_:(![]+"")[_],_$_:++_,$_$$:({}+"")[_],$$_$:(_[_]+"")[_],_$$:++_,$$$_:(!""+"")[_],$__:++_,$_$:++_,$$__:({}+"")[_],$$_:++_,$$$:++_,$___:++_,$__$:++_};_.$_=(_.$_=_+"")[_.$_$]+(_._$=_.$_[_.__$])+(_.$$=(_.$+"")[_.__$])+((!_)+"")[_._$$]+(_.__=_.$_[_.$$_])+(_.$=(!""+"")[_.__$])+(_._=(!""+"")[_._$_])+_.$_[_.$_$]+_.__+_._$+_.$;_.$$=_.$+(!""+"")[_._$$]+_.__+_._+_.$+_.$$;_.$=(_.___)[_.$_][_.$_];_.$(_.$(_.$$+"\""+_.__+_.$$$_+"\\"+_.__$+_.$$_+_._$$+_.__+"\"")())();
-
AAEncode:
゚ω゚ノ= /`m´)ノ ~┻━┻ //*´∇`*/ ['_']; o=(゚ー゚) =_=3; c=(゚Θ゚) =(゚ー゚)-(゚ー゚); (゚Д゚) =(゚Θ゚)= (o^_^o)/ (o^_^o);(゚Д゚)={゚Θ゚: '_' ,゚ω゚ノ : ((゚ω゚ノ==3) +'_') [゚Θ゚] ,゚ー゚ノ :(゚ω゚ノ+ '_')[o^_^o -(゚Θ゚)] ,゚Д゚ノ:((゚ー゚==3) +'_')[゚ー゚] }; (゚Д゚) [゚Θ゚] =((゚ω゚ノ==3) +'_') [c^_^o];(゚Д゚) ['c'] = ((゚Д゚)+'_') [ (゚ー゚)+(゚ー゚)-(゚Θ゚) ];(゚Д゚) ['o'] = ((゚Д゚)+'_') [゚Θ゚];(゚o゚)=(゚Д゚) ['c']+(゚Д゚) ['o']+(゚ω゚ノ +'_')[゚Θ゚]+ ((゚ω゚ノ==3) +'_') [゚ー゚] + ((゚Д゚) +'_') [(゚ー゚)+(゚ー゚)]+ ((゚ー゚==3) +'_') [゚Θ゚]+((゚ー゚==3) +'_') [(゚ー゚) - (゚Θ゚)]+(゚Д゚) ['c']+((゚Д゚)+'_') [(゚ー゚)+(゚ー゚)]+ (゚Д゚) ['o']+((゚ー゚==3) +'_') [゚Θ゚];(゚Д゚) ['_'] =(o^_^o) [゚o゚] [゚o゚];(゚ε゚)=((゚ー゚==3) +'_') [゚Θ゚]+ (゚Д゚) .゚Д゚ノ+((゚Д゚)+'_') [(゚ー゚) + (゚ー゚)]+((゚ー゚==3) +'_') [o^_^o -゚Θ゚]+((゚ー゚==3) +'_') [゚Θ゚]+ (゚ω゚ノ +'_') [゚Θ゚]; (゚ー゚)+=(゚Θ゚); (゚Д゚)[゚ε゚]='\\'; (゚Д゚).゚Θ゚ノ=(゚Д゚+ ゚ー゚)[o^_^o -(゚Θ゚)];(o゚ー゚o)=(゚ω゚ノ +'_')[c^_^o];(゚Д゚) [゚o゚]='\"';(゚Д゚) ['_'] ( (゚Д゚) ['_'] (゚ε゚+(゚Д゚)[゚o゚]+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ ((゚ー゚) + (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (o^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (゚ー゚)+ (゚Д゚)[゚o゚]) (゚Θ゚)) ('_');
密码类编码
- DNA
图片码
-
二进制转二维码
from PIL import Image
def generate_qrcode_from_binary(binary_str, img_size):
assert len(binary_str) == img_size[0] * img_size[1], "Size mismatch!"
pic = Image.new("RGB", img_size, color="white")
index = 0
for y in range(img_size[1]):
for x in range(img_size[0]):
if binary_str[index] == '1':
pic.putpixel([x, y], (0, 0, 0))
index += 1
return pic
# 示例二进制数据
binary_data = "1111111000100001101111111100000101110010110100000110111010100000000010111011011101001000000001011101101110101110110100101110110000010101011011010000011111111010101010101111111000000001011101110000000011010011000001010011101101111010101001000011100000000000101000000001001001101000100111001111011100111100001110111110001100101000110011100001010100011010001111010110000010100010110000011011101100100001110011100100001011111110100000000110101001000111101111111011100001101011011100000100001100110001111010111010001101001111100001011101011000111010011100101110100100111011011000110000010110001101000110001111111011010110111011011"
img_size = (25, 25)
qrcode = generate_qrcode_from_binary(binary_data, img_size)
qrcode.show()
qrcode.save("flag.png")
- 二维码修复
- 二维码拼接
tool
URL编码
- URL 编码,也被称为百分号编码,是一种编码机制,用于将不安全或特殊的字符转换为
%
后跟其 ASCII 的十六进制表示,以确保 URL 的安全传输。 - 通常的 url 编码只会处理符号和不可见字符,比如
Squdgy fez, blank jimp crwth vox
会被编码为Squdgy%20fez%2C%20blank%20jimp%20crwth%20vox
(普通类型) - 但在 CTF 中我们可能会将其编码为
%53%71%75%64%67%79%20%66%65%7a%2c%20%62%6c%61%6e%6b%20%6a%69%6d%70%20%63%72%77%74%68%20%76%6f%78
(复杂类型) - 甚至出现多次 Url 编码的情况,当然这可能存在一些恶趣味,但是在渗透过程中,多次 url 编码确实是一种有效的 Bypass 手段。