from Crypto.Util.number import * from random import * p = getPrime(256) q = getPrime(256) n = p * q e = 65537 d = inverse_mod(e, (p - 1) * (q - 1)) flag = 923527005889600515717927945977637659146494233475843599679540322066522531810019204383510355169667412726034587411782045475101164773757 flag_length = flag.nbits() c = pow(flag, e, n) defcheck_padding(c): padding_pos = n.bit_length() - 2 m = pow(c, d, n) return (m >> (padding_pos - 8)) == 0xFF
k = n.bit_length() - 2 - 8 L = 0xFF << k R = L + (1 << k) - 1 B = 1 << flag_length good = [] whilelen(good) < flag_length // 10 + 10: a = randrange(1, n) cc = pow(a, e, n) * c % n res = check_padding(cc) if res: good.append(a) print(len(good))
M = matrix(good).stack(matrix.identity(len(good)) * n) M = matrix([1] + len(good) * [0]).T.augment(M)