def test_provide_d(): p = 10521374782824813290994579853274637230207626975146963889181856590626488761976645789358310837242743914530728188687731977638030308962654142267888963222503343 q = 12487242021364162467562188423511025316215288842706293616055871433560266243438370414713554195328487123426394309079933807016181275891241323834614194158361083 n = p * q e = 65537 phi = (p - 1) * (q - 1) d = inverse(e, phi) rsa = RSA(n, e) rsa.factor_n_with_d(d) assert (rsa.decryptable())
def test_decrypt(): p = 10521374782824813290994579853274637230207626975146963889181856590626488761976645789358310837242743914530728188687731977638030308962654142267888963222503343 q = 12487242021364162467562188423511025316215288842706293616055871433560266243438370414713554195328487123426394309079933807016181275891241323834614194158361083 n = p * q e = 65537 rsa = RSA(n, e, p=p, q=q) m = b'flag{test}' c = rsa.encrypt(b2l(m)) m_ = l2b(rsa.decrypt(c)) assert (m == m_)
def test_yafu(): n = 101 * 97 e = 3 rsa = RSA(n, e) rsa.yafu() assert (rsa.decryptable())
def test_fermat(): n = 151241484875409902584366641910487623321093888282254049961681200771760772331360145082075526020483544203724954345655616757700916320207167585136394888371691427032985312915821422788232118299975301266402830019610689976927958187993765060729092003744458930098806902200559229950523489583547627229164721487941117364507 e = 3 rsa = RSA(n, e) rsa.fermat() assert (rsa.decryptable())
def test_fatordb(): n = 101 * 97 e = 3 rsa = RSA(n, e) rsa.factordb() assert (rsa.decryptable())
def test_wiener(): n = 23244179871445238784705712902302394907767196955951905090318512287370619632899295457482277135660897016527032245869029651703237429209945741228308344902587932386853768610619586176138217852499113891689061749798082976186674552249573002535453466810353699848807994720994086344361472708968688002761479743593463076223235611382648373685490412428631795575449849013233752788620739790212365935476593922145288397398931564982835707946185702751942244295782033020422622524447589117235697540484301961620172664197195682014111902321163293735315721909597576795306876198403342991351132358395076418125264908278842282695195835040024365917839 e = 21617368442750760928342788126866354792185240901656703479219958207295978799909993213714846109890271413013163584271182755478162680995707105768591140954762013330252568102130544727825084521492795588743122784849375079378598268500021586966524305446876820899116070368687275549151333633744527761116519260032484501707438968582266004943987112241659650934403405036946038865525352796135817543466497277298289251107268823424983221644768156129026016417688087746766052569824502721261823187597725759580212184604057216182838381836276071651496001055800652551320364727076053076055001597607986056022793536167480892267152940415453432687823 rsa = RSA(n, e) rsa.wiener() assert (rsa.decryptable())