2020重庆市教育局网络安全攻防比赛——密码学

2020重庆市教育局网络安全攻防比赛——密码学

RSA

题目:

(p-2)*(q-2)= 0x9360ce5eb573dcdb85af4cef9468a29323aa9d26f8cef9a2b004f3d9922c12c45f74b85c00db81fa34de4714a6a95b676618a3ea8155df7095056c079531233f3e80cc372263ccaf4d42e5b7aa637586b673e30820a2d7eba201691371e138e4b3e45ed756cc6faac6e6f4686dfb56e7fcd361ac312d0f7110e76f8fee5cff75894e8a2f4e50ffd0ef9db7f0eb685a6b3038892a96b355ea1d154b77db6e97a3facd36dd8ee14b94cb98a21f4cea1412e7c72ea4cad530995ade3f5aae3444204dfc0d6ede436427
e= 0x2e43a6e5
n= 0x9360ce5eb573dcdb85af4cef9468a29323aa9d26f8cef9a2b004f3d9922c12c45f74b85c00db81fa34de4714a6a95b676618a3ea8155df7095056c079531233f3e80cc372263ccaf4d42e5b7aa637586b673e30820a2d7eba201691371e138e4b3e45eda7d04ff5b6a850dd6c5d5dcaab3588c8acc1b56794cbef1337664afd984d491d8134e3c1d661414278836b76e0de6a4e9a16f1c3f6abe86448dd065f317515d09888955eba578c5579381f59a5355584d1b2003c93660ada247f13db12aadc74a6801803b
c= 0x49c627fa815685ad85060c0891e2cd04b5cd722cd82cc809835cb43da79b21ce547f4139da69a67e201c5f4643ff91306b92ae7d1e3cc96a01e7074c7016058bf607038061fc3a99b6ac3ae1eaf6a3fddcc70303ed56281896183a4cd98c18e5f0378bf18d6a09c685c6fefdd0c0914b4b22e183ac5c88d5674b54141ef8291855bc394296b8031c0b0b6ec26889871137b91224321bb0d2a89ae1cf84eeba9fe459d0b8dff7fb1aadbae839956dfdfef5b0a8dbdfe8fd2613228e75f45195ee24cfa58b85a57e0f

已知:(p-2)*(q-2),e,n,c,n=pq

设:(p-2)(q-2)=y,p+q=x

已知y求x。

y=pq-2p-2q+4
y=pq-2(p+q)+4
y=n-2x+4
x=(n+4-y)/2

phi=(p-1)(q-1)
phi=pq-q-p+1
phi=pq-x+1

思路有了后就可以写程序了。

from gmpy2 import *
from Crypto.Util.number import *

y = 0x9360ce5eb573dcdb85af4cef9468a29323aa9d26f8cef9a2b004f3d9922c12c45f74b85c00db81fa34de4714a6a95b676618a3ea8155df7095056c079531233f3e80cc372263ccaf4d42e5b7aa637586b673e30820a2d7eba201691371e138e4b3e45ed756cc6faac6e6f4686dfb56e7fcd361ac312d0f7110e76f8fee5cff75894e8a2f4e50ffd0ef9db7f0eb685a6b3038892a96b355ea1d154b77db6e97a3facd36dd8ee14b94cb98a21f4cea1412e7c72ea4cad530995ade3f5aae3444204dfc0d6ede436427
e = 0x2e43a6e5
n = 0x9360ce5eb573dcdb85af4cef9468a29323aa9d26f8cef9a2b004f3d9922c12c45f74b85c00db81fa34de4714a6a95b676618a3ea8155df7095056c079531233f3e80cc372263ccaf4d42e5b7aa637586b673e30820a2d7eba201691371e138e4b3e45eda7d04ff5b6a850dd6c5d5dcaab3588c8acc1b56794cbef1337664afd984d491d8134e3c1d661414278836b76e0de6a4e9a16f1c3f6abe86448dd065f317515d09888955eba578c5579381f59a5355584d1b2003c93660ada247f13db12aadc74a6801803b
c = 0x49c627fa815685ad85060c0891e2cd04b5cd722cd82cc809835cb43da79b21ce547f4139da69a67e201c5f4643ff91306b92ae7d1e3cc96a01e7074c7016058bf607038061fc3a99b6ac3ae1eaf6a3fddcc70303ed56281896183a4cd98c18e5f0378bf18d6a09c685c6fefdd0c0914b4b22e183ac5c88d5674b54141ef8291855bc394296b8031c0b0b6ec26889871137b91224321bb0d2a89ae1cf84eeba9fe459d0b8dff7fb1aadbae839956dfdfef5b0a8dbdfe8fd2613228e75f45195ee24cfa58b85a57e0f

x_2 = n + 4 - y
# x = x_2 / 2		# 这里数太大,python无法进行计算,需要找工具进行计算后才能继续下一步。
x = 10499790783038484569805597902684142859480193320728007213400678232071927076798651687119789844875553678691846010779762493711953914470123187073249367456081129311312900659899447998876519337555563418886210866861967752734977578142838309788531494412
# 这我直接把计算的值赋值给x。
phi = n - x + 1
d = invert(e,phi)
flag = pow(c,d,n)
flag = long_to_bytes(flag)
print(flag.decode('utf-8'))

flag is :31e7957b168706db1acb124c3589e367

bullshit

题目:

from flag import flag
def pairing(a,b):
    shell = max(a, b)
    step = min(a, b)
    if step == b:
        flag = 0
    else:
        flag = 1
    return shell ** 2 + step * 2 + flag

def encrypt(message):
    res = ''
    for i in range(0,len(message),2):
        res += str(pairing(message[i],message[i+1]))
    return res

print(encrypt(flag))
# 1186910804152291019933541010532411051999082499105051010395199519323297119520312715722

分析代码得知计算方式为:flag每两个字节分别计算,较大者的平方+小者的2倍+标志,结果转成十进制字符串。逆向解出flag没想到算法,选择暴力破解。

flag一般均为可见字符,一开始手动构造了[a-z,A-Z,0-9,_,{,}],遍及求解即可。a**2+2b+1的取值范围大体计算了下3-5位数之间。

构造代码如下:

result = "1186910804152291019933541010532411051999082499105051010395199519323297119520312715722"
# a=['{','}','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
a= [i for i in range(48,128)]
b=a
flag=""
def pairing(a,b):
    shell = max(a, b)
    step = min(a, b)
    if step == b:
        flag = 0
    else:
        flag = 1
    return shell ** 2 + step * 2 + flag
def check(n):
    for i in range(0, len(a), 1):
        for j in range(0, len(b), 1):
            if (str(pairing(ord(a[i]), ord(b[j]))) == n):
                #print("%c%c" % (a[i], b[j]))
                return a[i], b[j]
    return 0,0
 
p=0
while p<len(result):
    for x in range(3,6):
        n=result[p:p+x]
        r1,r2 = check(n)
        if r1!=0:
            p+=x
            flag += r1+r2
            break;
print(flag)

crypto_1

题目:

Jxyi yi oekh tqo.Jxyi yi oekh suburhqjyed., qdt jxu vbqw yi vv97v97t5t1ss32t9q5u62s2uu1t2v2s, ikrcyj myjx vbqw qdt {}

这题直接用在线工具解码:https://quipqiup.com/

在这里插入图片描述

解密后得到flag:

[https://s1.ax1x.com/2020/10/26/Bnrn29.png]

This is work daw.This is work peleukation., and the flag is ff97f97d5d1pp32d9a5e62p2ee1d2f2p, srujit vith flag and {}

Base64

题目:

import string

table ='PackmybxwthfivdzenlqorjugspACKMYBXWTHFIVDZENLQORJUGS'+string.digits + '+/'

def encode(origin_bytes):
	# 将字符串转换成二进制。
    getdBytes = ['{:0>8}'.format(str(bin(b)).replace('0b', '')) for b in origin_bytes]

    resp = ''
    nums = len(getdBytes) // 3
    remain = len(getdBytes) % 3

    integral_part = getdBytes[0:3 * nums]
    while integral_part:
        # 获取每3个字符的二进制
        tmp_unit = ''.join(integral_part[0:3])
        tmp_unit = [int(tmp_unit[x: x + 6], 2) for x in [0, 6, 12, 18]]
        resp += ''.join([table[i] for i in tmp_unit])
        integral_part = integral_part[3:]

    if remain:
        remain_part = ''.join(getdBytes[3 * nums:]) + (3 - remain) * '0' * 8
        tmp_unit = [int(remain_part[x: x + 6], 2) for x in [0, 6, 12, 18]][:remain + 1]
        resp += ''.join([table[i] for i in tmp_unit]) + (3 - remain) * '='
    return resp


if __name__ == '__main__':
    s = '******************************'.encode()
    encflag = encode(s)
    print('encflag is:', encflag)
    #encflag is: sIUXs3LUgSgUdjsHvIo5vbm2gSH3g2o3iTrXi2o3vjo3i2o0vx0=


解题:

s = "PackmybxwthfivdzenlqorjugspACKMYBXWTHFIVDZENLQORJUGS0123456789+/"

s_f = 'sIUXs3LUgSgUdjsHvIo5vbm2gSH3g2o3iTrXi2o3vjo3i2o0vx0='

# 将字符串转化为2进制
bin_str = []
for i in s_f:
    if i != '=':
        x = str(bin(s.index(i))).replace('0b', '')
        bin_str.append('{:0>6}'.format(x))

outputs = ""
nums = s_f.count('=')
while bin_str:
    temp_list = bin_str[:4]
    temp_str = "".join(temp_list)

    if (len(temp_str) % 8 != 0):
        temp_str = temp_str[0:-1 * nums * 2]

    for i in range(0, int(len(temp_str) / 8)):
        outputs += chr(int(temp_str[i * 8:(i + 1) * 8], 2))
    bin_str = bin_str[4:]
print(outputs)


  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值