2023 Cryptography Summer Camp

Photo by rawpixel on Unsplash

Date
May 23, 2023 12:00 AM

本项目为面向上海大学网络空间安全专业本科生(2020级、2021级)的暑期实训课程。 内容包括:

  1. 密码和编码
  2. 近世代数和数论
  3. 非对称密码
  4. Challenges

Repository

本课程相关材料均已在 GitHub-LuminolT/security-summercamp 备份。

Challenges

Chal1. 套娃

  • 本题共 3 个 flag
  • flag 形式均为:'flag{[0-9A-Za-z=_]*}'

新佛曰:諸隸僧降冥吽諸陀摩隸僧缽冥薩願耨咤陀願羅咤喃迦祗蜜耨阿嚤僧喼所聞薩闍嚩聞念須亦心耨冥心阿冥聞慧蜜咤冥心念訶冥嚩冥聞冥念降咤冥劫耨降寂願慧般祗闍隸冥修阿闍莊陀冥莊冥劫莊嚴冥宣隸阿摩嚩蜜心咒冥闍我須咒慧冥闍諦羅迦聞慧婆劫嘚慧咒迦慧慧我慧冥闍念劫嘇隸蜜祗伏嚤慧咒修缽聞色祗冥闍僧嘚迦降阿莊冥慧聞蜜降咤寂波嘇塞薩如囑

Chal2. ezRSA

  • 本题共 1 个 flag
  • flag 形式为:'flag{[0-9A-Za-z=_]*}'
from Crypto.Util.number import getPrime, bytes_to_long
from gmpy2 import is_prime, invert
from typing import Tuple
from secert import flag

def gen_rsa_param() -> Tuple[int, int, int, int, int]:
    """Generate usable RSA parameters.
    
    params:
        None
    
    return:
        a tuple, including `p, q, n, e, d`
    """
    p = getPrime(256)
    q = p + 2
    while True:
        q += 2
        if is_prime(q):
            break
        
    assert p < q
    
    n = p * q
    phi_n = (p-1) * (q-1)
    e = 0x10001
    d = invert(e, phi_n)
    
    return p, q, n, e, d

def rsa_encrypt(m: str, *args) -> str:
    """Generate usable RSA parameters.
    
    params:
        m: message to be encrypted
        args: RSA parameters
    
    return:
        a string, which is the encrypted message
    """
    assert len(args) == 5
    p, q, n, e, d = args
    m = bytes_to_long(m)
    c = pow(m, e, n)
    return c

params = gen_rsa_param()
print(rsa_encrypt(flag, *params))
print(params[2])
# 5796768148637887491255587039409951397511832995737366433505141785703232675749200657380232851343254281355390391562734825283953711907092653161783752372166386
# 7948512242985881433771203281939490726039994357587772712416312873824297606161653053722572268861029945737411249803561023517431875922105282741637330609169129
Chenghao Chen
Chenghao Chen
M.E student in Electronic Information (Cyberspace Security)

An Cryptography Learner