破解加密数据
备注
某工控厂商自行研发了一套加密系统,这样的话只要不是系统内部人员,即使数据被窃听没关系了。你截获了一段密文:109930883401687215730636522935643539707,请进行解密
flag 形式为 flag{}
ChatGPT 直接秒了
先分析加密脚本
m = "unknown"
e = 2
n = 0x6FBD096744B2B34B423D70C8FB19B541
assert(int(m.encode('hex'), 16) < n)
c = pow(int(m.encode('hex'), 16),e,n)
print c
典型的 RSA 加密问题
求解 m 的可能值
from sympy import mod_inverse, isprime, sqrt_mod
# Given values
c = 109930883401687215730636522935643539707
n = 0x6FBD096744B2B34B423D70C8FB19B541
e = 2
# Check if c has a modular square root under n
try:
# Compute the modular square root of c mod n
m_values = sqrt_mod(c, n, all_roots=True)
except ValueError:
m_values = None
m_values
# [31698494966724069351424094257, 47966037907531568164415165899182644837, 100559804454305364139582472308130223836, 148525842330138437337273568855888774416]
尝试还原出字符串
# Function to convert a number to a hex string and then decode it as text
def number_to_string(num):
try:
# Convert to hex, remove the '0x' prefix, and decode to ASCII
hex_str = hex(num)[2:] # Remove '0x' prefix
if len(hex_str) % 2 != 0: # Make sure it's even-length for decoding
hex_str = "0" + hex_str
return bytes.fromhex(hex_str).decode('utf-8', errors='ignore') # Decode ignoring invalid characters
except Exception:
return None
# Attempt to decode each candidate for m
decoded_strings = [number_to_string(m) for m in m_values]
decoded_strings
即可得到答案
flag{flag_EnCryp1}