UNCTF:BABYRSA
下载附件,解压后有一个加密文件和rsa.py代码如下:
flag = open('flag.txt','r').read() N = 221 e = 5 enc = b'' for i in flag: enc += bytes([pow(ord(i),e,N)]) encrypt = open('encrypt','wb') encrypt.write(enc) encrypt.close()
知道加密脚本我们反向编写脚本获取flag:
flag="" N = 221 e = 5 with open('encrypt','rb') as fp: encrypt=fp.read() encrypt=bytes.decode(encrypt) for i in encrypt: for x in range(0,255): if pow(x,e,N)==ord(i): flag+=chr(x) break print(flag)