题目考点
- 离散对数
解题思路
- 下载题目附件:
1
2
3
4
5
6
7
8
9
10
11
12
13#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Crypto.Util.number import *
import random
n = 2 ** 512 # 2^512
m = random.randint(2, n-1) | 1 # 随机生成一个奇数(使用random.randint()函数生成一个大于等于2且小于n-1的随机整数,并通过按位或操作符"| 1"将其转换为奇数)
c = pow(m, bytes_to_long(flag), n) # c = m^flag mod n
print 'm = ' + str(m)
print 'c = ' + str(c)
# m = 391190709124527428959489662565274039318305952172936859403855079581402770986890308469084735451207885386318986881041563704825943945069343345307381099559075
# c = 6665851394203214245856789450723658632520816791621796775909766895233000234023642878786025644953797995373211308485605397024123180085924117610802485972584499 - 对于
c = m^flag mod n
,已知c,m,n,求flag,这是典型的离散对数问题。 - 使用sympy库进行求解:
1
2
3
4
5
6
7
8
9from sympy.ntheory import discrete_log # conda update sympy
from Crypto.Util.number import long_to_bytes # pip install pycryptodome
m = 391190709124527428959489662565274039318305952172936859403855079581402770986890308469084735451207885386318986881041563704825943945069343345307381099559075
c = 6665851394203214245856789450723658632520816791621796775909766895233000234023642878786025644953797995373211308485605397024123180085924117610802485972584499
n = 2 ** 512
flag=discrete_log(n, c, m) # 求解离散对数
print long_to_bytes(flag)
FLAG
1 | flag{5f95ca93-1594-762d-ed0b-a9139692cb4a} |