whileTrue: p = randint(2**511, num1) q = randint(2**511, num2) if isPrime(p) and isPrime(q) and p!=q: break N = p*q e = 65537 leak = pow(p-q, num1, num1*num2) ct = pow(pt, e, N)
import sys sys.path.append("..") from secret import key,flag2 as flag
def_l(idx, s): return s[idx:] + s[:idx] defmainProc(p, k1, k2): s = b"abcd07efghij89klmnopqr16stuvwxyz-_{}ABCDEFGHIJKL34MNOPQRST25VWXYZ" t = [[_l((i+j)%len(s), s) for j inrange(len(s))] for i inrange(len(s))] i1 = 0 i2 = 0 c = b"" for a in p: c += t[s.find(a)][s.find(k1[i1])][s.find(k2[i2])] i1 = (i1 + 1) % len(k1) i2 = (i2 + 1) % len(k2) return c res = mainProc(flag,key,key[::-1]) print(res)
defmainProc(p, k1, k2): s = b"abcd07efghij89klmnopqr16stuvwxyz-_{}ABCDEFGHIJKL34MNOPQRST25VWXYZ" t = [[_l((i+j)%len(s), s) for j inrange(len(s))] for i inrange(len(s))] i1 = 0 i2 = 0 c = b"" for a in p: c += t[s.find(a)][s.find(k1[i1])][s.find(k2[i2])] i1 = (i1 + 1) % len(k1) i2 = (i2 + 1) % len(k2) return c
等同于下面这个加密过程
1 2 3 4 5 6 7 8 9 10
defmainProc(p, k1, k2): s = b"abcd07efghij89klmnopqr16stuvwxyz-_{}ABCDEFGHIJKL34MNOPQRST25VWXYZ" i1 = 0 i2 = 0 c = b"" for a in p: c += long_to_bytes(s[(s.find(a) + s.find(k1[i1]) + s.find(k2[i2])) % len(s)]) i1 = (i1 + 1) % len(k1) i2 = (i2 + 1) % len(k2) return c
defdecrypt(c,tmp): s = b"abcd07efghij89klmnopqr16stuvwxyz-_{}ABCDEFGHIJKL34MNOPQRST25VWXYZ" i = 0 message = b"" for a in c: message += long_to_bytes(s[(s.find(a) - tmp[i]) % 65]) i = (i+1) % len(tmp) return message
m = b"flag{ISEC-" c = b"6JnsNxHKJ8mkvhS{rMO_c9apMfHDHObq80PMu{_ww_r{rq"
tmp = [] for i inrange(len(m)): s = b"abcd07efghij89klmnopqr16stuvwxyz-_{}ABCDEFGHIJKL34MNOPQRST25VWXYZ" index = s.find(c[i]) #先找到密文在字符串s中的位置 tmp.append((index - s.find(m[i])) % len(s)) #做减法