This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gmpy2 | |
| O = (0, 0) | |
| def add_ecc(p, q): | |
| if p == O: | |
| return q | |
| elif q == O: | |
| return p | |
| elif p[0] == q[0] and p[1]==-q[1]: | |
| return O |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gmpy2 | |
| from point_addition import add_ecc | |
| O = (0, 0) | |
| def scalar_mul(n, p): | |
| q, r = p, O | |
| while n > 0: | |
| if n % 2 == 1: | |
| r = add_ecc(r, q) | |
| q, n = add_ecc(q, q), n // 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from scalar_multiplication import scalar_mul | |
| import hashlib | |
| if __name__ == "__main__": | |
| QA, nB = (815, 3190), 1829 | |
| key = scalar_mul(nB, QA)[0] | |
| flag = hashlib.sha1(b'%f' % key).hexdigest() | |
| print('crypto{%s}' % flag) | |
| '''codes for scalar_mul and point_addition are below: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pwn import * | |
| import re | |
| import json | |
| conn = remote('socket.cryptohack.org', 13372) | |
| s = conn.recv(1024) | |
| conn.send(json.dumps({"option":"get_flag"})) | |
| s = conn.recv(1024) | |
| num = re.findall(r': (.*)\n', s.decode())[0] | |
| data = num[1:-2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Crypto.Util.number import inverse, long_to_bytes | |
| e = 3 | |
| n = 742449129124467073921545687640895127535705902454369756401331 | |
| ct = 39207274348578481322317340648475596807303160111338236677373 | |
| # get p,q from https://www.alpertron.com.ar/ECM.HTM by factoring n | |
| p = 752708788837165590355094155871 | |
| q = 986369682585281993933185289261 | |
| phi = (p-1) * (q-1) | |
| d = inverse(e, phi) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Crypto.Util.number import inverse, long_to_bytes | |
| e = 65537 | |
| n = 171731371218065444125482536302245915415603318380280392385291836472299752747934607246477508507827284075763910264995326010251268493630501989810855418416643352631102434317900028697993224868629935657273062472544675693365930943308086634291936846505861203914449338007760990051788980485462592823446469606824421932591 | |
| ct = 161367550346730604451454756189028938964941280347662098798775466019463375610700074840105776873791605070092554650190486030367121011578171525759600774739890458414593857709994072516290998135846956596662071379067305011746842247628316996977338024343628757374524136260758515864509435302781735938531030576289086798942 | |
| d = inverse(e, n-1) | |
| pt = pow(ct, d, n) | |
| decrypted = long_to_bytes(pt) | |
| print(decrypted) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Crypto.Util.number import inverse, long_to_bytes | |
| n = 53586080804400955002917713570816801620145134314731356537101445902774349173942288544308470572073140971377552799371968258366916487380684204328843982807178997069475908084216225395525959055228304772878281294684516033480178208806815445302193672171026905098580505469209673877732179615338402489761559449345306813834120367374951409454600025363190299161719784758451969415212276540698213352659492868523238193474215219586138022122437085812873697595917686165104437037853909399019833629857294451273857083939658859009681321779119189594138046480337760277924066313383495232931686239958195059058800637122133412821540919760323694259767475672821223213405656271639915508010888110595276818919372882748466734937809110006822440468470167478239920037319243306276762284126405542603534976901811729962055480390249043233960056643224679581816746091618064739416915764724560355569273563086214871542879124276479946989692475347053985708076717005278391827318030483531838817708967423164091033774378975 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Crypto.Util.number import inverse, long_to_bytes | |
| n = 580642391898843192929563856870897799650883152718761762932292482252152591279871421569162037190419036435041797739880389529593674485555792234900969402019055601781662044515999210032698275981631376651117318677368742867687180140048715627160641771118040372573575479330830092989800730105573700557717146251860588802509310534792310748898504394966263819959963273509119791037525504422606634640173277598774814099540555569257179715908642917355365791447508751401889724095964924513196281345665480688029639999472649549163147599540142367575413885729653166517595719991872223011969856259344396899748662101941230745601719730556631637 | |
| e = 65537 | |
| ct = 3207214905346244341499937235273229779605565107506283548562607320981096925813384099999833761313549183700476251504547287184679988703223449809856351496569777879643806518681317403120537555015949991663658213150433123086223880166668024784854760596258880330171980834729760117199983339855317569786787588974728453581677302215065738177984671000237 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Crypto.Util.number import inverse, long_to_bytes | |
| from gmpy2 import iroot | |
| n = 17258212916191948536348548470938004244269544560039009244721959293554822498047075403658429865201816363311805874117705688359853941515579440852166618074161313773416434156467811969628473425365608002907061241714688204565170146117869742910273064909154666642642308154422770994836108669814632309362483307560217924183202838588431342622551598499747369771295105890359290073146330677383341121242366368309126850094371525078749496850520075015636716490087482193603562501577348571256210991732071282478547626856068209192987351212490642903450263288650415552403935705444809043563866466823492258216747445926536608548665086042098252335883 | |
| e = 3 | |
| ct = 243251053617903760309941844835411292373350655973075480264001352919865180151222189820473358411037759381328642957324889519192337152355302808400638052620580409813222660643570085177957 | |
| pt = iroot(ct, 3)[0] | |
| decrypted = long_to_bytes(pt) | |
| print(decrypted) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Crypto.Util.number import inverse, long_to_bytes, bytes_to_long | |
| import hashlib | |
| mes = "crypto{Immut4ble_m3ssag1ng}" | |
| res = hashlib.sha256(mes.encode()) | |
| h_m = int(res.hexdigest(),16) | |
| n = 15216583654836731327639981224133918855895948374072384050848479908982286890731769486609085918857664046075375253168955058743185664390273058074450390236774324903305663479046566232967297765731625328029814055635316002591227570271271445226094919864475407884459980489638001092788574811554149774028950310695112688723853763743238753349782508121985338746755237819373178699343135091783992299561827389745132880022259873387524273298850340648779897909381979714026837172003953221052431217940632552930880000919436507245150726543040714721553361063311954285289857582079880295199632757829525723874753306371990452491305564061051059885803 | |
| d = 11175901210643014262548222473449533091378848269490518850474399681690547281665059317155831692300453197335735728459259392366823302405685389586883670043744683993709123180805154631088513521456979317628012721881537154 |
OlderNewer