DamoNeer@home:~$

CryptoHack - Primes Part 1 | Crypto

Factoring

Factorise the 150-bit number 510143758735509025530880200653196460532653147 into its two constituent primes. Give the smaller one as your answer.

Solution

http://factordb.com/index.php?query=510143758735509025530880200653196460532653147+

Inferius Prime

Here is my super-strong RSA implementation, because it’s 1600 bits strong it should be unbreakable… at least I think so!

Solution

Opening the output.txt file will give us n, c, e . Factor the given n into two prime numbers first, then use the downloaded python script as a reference as to how to get the decrypted message back.

\\Python
from Crypto.Util.number import long_to_bytes

p = 986369682585281993933185289261 #prime number 1
q = 752708788837165590355094155871 #prime number 2
e = 3 #encryption key
#n = p * q #prime product
n = 742449129124467073921545687640895127535705902454369756401331
c = 39207274348578481322317340648475596807303160111338236677373 #ciphertext
phi = (p-1)*(q-1)
d = pow(e, -1, phi) #decryption key

pt = pow(c, d, n)
decrypted = long_to_bytes(pt)

print(decrypted)

Monoprime

Why is everyone so obsessed with multiplying two primes for RSA. Why not just use one?

Solution

In the case of one prime number being used, phi(n) will simply equal to n-1.

\\Python
from Crypto.Util.number import long_to_bytes

p = 1 #prime number 1
#q = n #prime number 2
e = 65537 #encryption key
#n = p * q #prime product
n = 171731371218065444125482536302245915415603318380280392385291836472299752747934607246477508507827284075763910264995326010251268493630501989810855418416643352631102434317900028697993224868629935657273062472544675693365930943308086634291936846505861203914449338007760990051788980485462592823446469606824421932591
c = 161367550346730604451454756189028938964941280347662098798775466019463375610700074840105776873791605070092554650190486030367121011578171525759600774739890458414593857709994072516290998135846956596662071379067305011746842247628316996977338024343628757374524136260758515864509435302781735938531030576289086798942 #ciphertext
phi = (n-1)
d = pow(e, -1, phi) #decryption key

pt = pow(c, d, n)
decrypted = long_to_bytes(pt)

print(decrypted)

Square Eyes

It was taking forever to get a 2048 bit prime, so I just generated one and used it twice.

Solution

p and q are the same this time. The formula for phi will be equal to p(q-1) instead.

\\Python
from Crypto.Util.number import long_to_bytes

p = 23148667521998097720857168827790771337662483716348435477360567409355026169165934446949809664595523770853897203103759106983985113264049057416908191166720008503275951625738975666019029172377653170602440373579593292576530667773951407647222757756437867216095193174201323278896027294517792607881861855264600525772460745259440301156930943255240915685718552334192230264780355799179037816026330705422484000086542362084006958158550346395941862383925942033730030004606360308379776255436206440529441711859246811586652746028418496020145441513037535475380962562108920699929022900677901988508936509354385660735694568216631382653107 #prime number 1
q = 23148667521998097720857168827790771337662483716348435477360567409355026169165934446949809664595523770853897203103759106983985113264049057416908191166720008503275951625738975666019029172377653170602440373579593292576530667773951407647222757756437867216095193174201323278896027294517792607881861855264600525772460745259440301156930943255240915685718552334192230264780355799179037816026330705422484000086542362084006958158550346395941862383925942033730030004606360308379776255436206440529441711859246811586652746028418496020145441513037535475380962562108920699929022900677901988508936509354385660735694568216631382653107 #prime number 2
e = 65537 #encryption key
#n = p * q #prime product
n = 535860808044009550029177135708168016201451343147313565371014459027743491739422885443084705720731409713775527993719682583669164873806842043288439828071789970694759080842162253955259590552283047728782812946845160334801782088068154453021936721710269050985805054692096738777321796153384024897615594493453068138341203673749514094546000253631902991617197847584519694152122765406982133526594928685232381934742152195861380221224370858128736975959176861651044370378539093990198336298572944512738570839396588590096813217791191895941380464803377602779240663133834952329316862399581950590588006371221334128215409197603236942597674756728212232134056562716399155080108881105952768189193728827484667349378091100068224404684701674782399200373192433062767622841264055426035349769018117299620554803902490432339600566432246795818167460916180647394169157647245603555692735630862148715428791242764799469896924753470539857080767170052783918273180304835318388177089674231640910337743789750979216202573226794240332797892868276309400253925932223895530714169648116569013581643192341931800785254715083294526325980247219218364118877864892068185905587410977152737936310734712276956663192182487672474651103240004173381041237906849437490609652395748868434296753449
c = 222502885974182429500948389840563415291534726891354573907329512556439632810921927905220486727807436668035929302442754225952786602492250448020341217733646472982286222338860566076161977786095675944552232391481278782019346283900959677167026636830252067048759720251671811058647569724495547940966885025629807079171218371644528053562232396674283745310132242492367274184667845174514466834132589971388067076980563188513333661165819462428837210575342101036356974189393390097403614434491507672459254969638032776897417674577487775755539964915035731988499983726435005007850876000232292458554577437739427313453671492956668188219600633325930981748162455965093222648173134777571527681591366164711307355510889316052064146089646772869610726671696699221157985834325663661400034831442431209123478778078255846830522226390964119818784903330200488705212765569163495571851459355520398928214206285080883954881888668509262455490889283862560453598662919522224935145694435885396500780651530829377030371611921181207362217397805303962112100190783763061909945889717878397740711340114311597934724670601992737526668932871436226135393872881664511222789565256059138002651403875484920711316522536260604255269532161594824301047729082877262812899724246757871448545439896 #ciphertext
phi = (p-1)*(q)
d = pow(e, -1, phi) #decryption key

pt = pow(c, d, n)
decrypted = long_to_bytes(pt)

print(decrypted)

ManyPrime

Using one prime factor was definitely a bad idea so I’ll try using over 30 instead.

Solution

Use factordb to get all of the prime factors. Set up a loop and iterate each factor to calculate phi.

image

\\Python
from Crypto.Util.number import long_to_bytes

#p =  #prime number 1
#q =  #prime number 2
e = 65537 #encryption key
#n = p * q #prime product
n = 580642391898843192929563856870897799650883152718761762932292482252152591279871421569162037190419036435041797739880389529593674485555792234900969402019055601781662044515999210032698275981631376651117318677368742867687180140048715627160641771118040372573575479330830092989800730105573700557717146251860588802509310534792310748898504394966263819959963273509119791037525504422606634640173277598774814099540555569257179715908642917355365791447508751401889724095964924513196281345665480688029639999472649549163147599540142367575413885729653166517595719991872223011969856259344396899748662101941230745601719730556631637
c = 320721490534624434149993723527322977960556510750628354856260732098109692581338409999983376131354918370047625150454728718467998870322344980985635149656977787964380651868131740312053755501594999166365821315043312308622388016666802478485476059625888033017198083472976011719998333985531756978678758897472845358167730221506573817798467100023754709109274265835201757369829744113233607359526441007577850111228850004361838028842815813724076511058179239339760639518034583306154826603816927757236549096339501503316601078891287408682099750164720032975016814187899399273719181407940397071512493967454225665490162619270814464 #ciphertext
factors = [9282105380008121879, 9303850685953812323, 9389357739583927789, 10336650220878499841, 10638241655447339831, 11282698189561966721, 11328768673634243077, 11403460639036243901, 11473665579512371723, 11492065299277279799, 11530534813954192171, 11665347949879312361, 12132158321859677597, 12834461276877415051, 12955403765595949597, 12973972336777979701, 13099895578757581201, 13572286589428162097, 14100640260554622013, 14178869592193599187, 14278240802299816541, 14523070016044624039, 14963354250199553339, 15364597561881860737, 15669758663523555763, 15824122791679574573, 15998365463074268941, 16656402470578844539, 16898740504023346457, 17138336856793050757, 17174065872156629921, 17281246625998849649]
phi = 1
for factor in factors:
    phi *= (factor-1)
d = pow(e, -1, phi) #decryption key
pt = pow(c, d, n)
decrypted = long_to_bytes(pt)

print(decrypted)