week1
test_your_nc
直接nc上去,发现好像是不同进制的加减乘除,让ai写一个脚本解决
[code]from pwn import *import re# 连接远程服务器r = remote('challenge2.pctf.top', 31297)context.log_level = 'debug' # 改为debug以获取更多信息class UniversalBaseSolver: def __init__(self): self.base_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+-*/" def convert_from_base(self, num_str, base): """将指定进制的字符串转换为十进制整数""" if base < 1 or base > 40: log.warning(f"Base {base} out of range 1-40") return None try: if base == 1: return len(num_str) else: # 对于所有进制,统一处理大小写 num_str_upper = num_str.upper() log.info(f"Converting '{num_str}' (-> '{num_str_upper}') from base {base}") if base 40: log.warning(f"Base {base} out of range 1-40") return str(num) try: num = int(num) log.info(f"Converting {num} to base {base}") if base == 1: if num < 0: return '-' + '1' * (-num) return '1' * num is_negative = num < 0 n = abs(num) if n == 0: result = '0' log.info(f"Result: {result}") return result digits = [] if base 0: n, remainder = divmod(n, base) if remainder < 10: digits.append(str(remainder)) else: digits.append(chr(ord('A') + remainder - 10)) result = ''.join(reversed(digits)) else: alphabet = self.base_chars[:base] while n > 0: n, remainder = divmod(n, base) digits.append(alphabet[remainder]) result = ''.join(reversed(digits)) if is_negative: result = '-' + result log.info(f"Conversion result: {result}") return result except Exception as e: log.warning(f"Base conversion error: {e}") return str(num) def detect_base(self, base_str): """检测并解析进制描述""" base_str = base_str.lower().strip() base_map = { '1': 1, 'unary': 1, 'base1': 1, '2': 2, 'binary': 2, 'bin': 2, 'base2': 2, '3': 3, 'ternary': 3, 'base3': 3, '4': 4, 'quaternary': 4, 'base4': 4, '5': 5, 'quinary': 5, 'base5': 5, '6': 6, 'senary': 6, 'base6': 6, '7': 7, 'septenary': 7, 'base7': 7, '8': 8, 'octal': 8, 'oct': 8, 'base8': 8, '9': 9, 'nonary': 9, 'base9': 9, '10': 10, 'decimal': 10, 'dec': 10, 'base10': 10, '11': 11, 'undecimal': 11, 'base11': 11, '12': 12, 'duodecimal': 12, 'base12': 12, '13': 13, 'tridecimal': 13, 'base13': 13, '14': 14, 'tetradecimal': 14, 'base14': 14, '15': 15, 'pentadecimal': 15, 'base15': 15, '16': 16, 'hexadecimal': 16, 'hex': 16, 'base16': 16, '17': 17, 'base17': 17, '18': 18, 'base18': 18, '19': 19, 'base19': 19, '20': 20, 'base20': 20, '21': 21, 'base21': 21, '22': 22, 'base22': 22, '23': 23, 'base23': 23, '24': 24, 'base24': 24, '25': 25, 'base25': 25, '26': 26, 'base26': 26, '27': 27, 'base27': 27, '28': 28, 'base28': 28, '29': 29, 'base29': 29, '30': 30, 'base30': 30, '31': 31, 'base31': 31, '32': 32, 'duotrigesimal': 32, 'base32': 32, '33': 33, 'base33': 33, '34': 34, 'base34': 34, '35': 35, 'base35': 35, '36': 36, 'hexatrigesimal': 36, 'base36': 36, '37': 37, 'base37': 37, '38': 38, 'base38': 38, '39': 39, 'base39': 39, '40': 40, 'base40': 40 } if base_str in base_map: result = base_map[base_str] log.info(f"Base detection: '{base_str}' -> {result}") return result try: base_num = int(base_str) if 1 |