CTF比赛中的数据格式化(采用Python语言)
2021/10/21 17:11:37
本文主要是介绍CTF比赛中的数据格式化(采用Python语言),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
前言
有的时候使用Visual Studio用几行代码就可以任意操纵数据格式,免去查找各类转换网站的苦恼。
一、字符串代换
flag = ['g','x','u','c','t','f','{','l','u','c','k','y','!','}'] print(str(flag).replace("'","").replace(",","").replace(" ",""))
二、字符串转ASCII码、二进制、八进制、十六进制
s = "union select" sasc = [] #ASCII sbin = [] #二进制 soct = [] #八进制 shex = [] #十六进制 for c in list(s): asc = ord(c) sasc.append(asc) sbin.append(bin(asc)) soct.append(oct(asc)) shex.append(hex(asc)) print("string:" + s) print("asc:" + str(sasc)) print("bin:" + str(sbin)) print("oct:" + str(soct)) print("hex:" + str(shex))
三、ASCII码、二进制、八进制、十六进制转字符串
#ASCII码转字符串 sasc = [103, 120, 117, 99, 116, 102, 123, 108, 117, 99, 107, 121, 33, 125] flag = "" for c in sasc: flag+=chr(c) print(flag) #二进制转字符串 sbin = ['0b1100111', '0b1111000', '0b1110101', '0b1100011', '0b1110100', '0b1100110', '0b1111011', '0b1101100', '0b1110101', '0b1100011', '0b1101011', '0b1111001', '0b100001', '0b1111101'] flag = "" for c in sbin: flag+=chr(int(c,2)) print(flag) #八进制转字符串 soct = ['0o147', '0o170', '0o165', '0o143', '0o164', '0o146', '0o173', '0o154', '0o165', '0o143', '0o153', '0o171', '0o41', '0o175'] flag = "" for c in soct: flag+=chr(int(c,8)) print(flag) #十六进制转字符串 shex = ['0x67', '0x78', '0x75', '0x63', '0x74', '0x66', '0x7b', '0x6c', '0x75', '0x63', '0x6b', '0x79', '0x21', '0x7d'] flag = "" for c in shex: flag+=chr(int(c,16)) print(flag)
这篇关于CTF比赛中的数据格式化(采用Python语言)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南
- 2024-11-06Python编程基础入门指南
- 2024-11-06怎么使用python 计算两个GPS的距离功能-icode9专业技术文章分享