Created
April 30, 2018 21:57
-
-
Save elliptic-shiho/db47d80d78de8fb068eb76dd6ed233d2 to your computer and use it in GitHub Desktop.
ASIS CTF 2018 Quals: Uncle Sam Solver
This file contains 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
factoreal @ myThinkMate in ... E$ python Uncle_Sam.py ] | |
def generate_key(k): p, q = getPrime(k), getPrime(k) pubkey = p**2 * q 1 = (p-1)*(q-1) / gcd(p-1, q-1) privkey = inverse(n, 1) return pubkey, privkey | |
def encrypt(m, pubkey): return pow(bytes_to_long(m), pubkey, pubkey) | |
pubkey = 104324738132004141014637484768390560888606798880281575965549007150696481142773349666805536470082277990816674819353434190328538733265808156204153422896153845183002504176253763998515034491758406482 761535653576387253992598998411706820755549870058537633073142835948979160031963607977702534421724847548583529868943792600395857814178437985795126497310921480391644570296404789944700219154896523988409580209 179878798874541517857859720681512291543835163667268135551798241012356996124256319448039934796175367815921021799352673830679650366056316302928741973221024757979326689108517881704753675846523995086126659252 420639086982297246913756604517669027781335256339283884741767452925162741947981509786889099315321551548887709776027239948311101360261855484609689380510882721134446779707235207243059131848509167701126191299 2157762106672216780766138057271434398274272110062768324672899209610001835423246735718435995420720133657793744810610657 | |
privkey = 10571787767222429578429167538554675012960147216337952737536712823800347179309734176339199950391365954208752080836428716764534955589777442817628882903147770359477634126816043366897623719833012490 437254689795395524177847532207416046976716256623435890774041280521124759869848164020795682719904841994984861973105086075780808210684495360217650324778653542342310423956691071352869129869233214978368903272 277200997440471678331220088555534387761109499811730797039924164021355382004346014049380340419077417191296265107510098383407125902103832288611466002878822909487254551605475770006826462802452439499579513546 4746570071201 | |
enc = 343369686707916921497078851452395954252074753628024855326592148594828266567853497784448902839960599855457261387659174943864861324798607407210198762531665500523668627672623380100283047707927966101715 266190355476680204081288124100983003649559499979731342450364456322062273208742008750774795951290651360492364136674198126979777860541228166734597108964573061640243513571440689299166495541329990802602494896 619995591485311779060353650700199981044058309406067935205196708178000370643018639282003328307492888263256672104905274453644042024751439967243049147724769464785043328741645419214885736940487139062463786022 104540986811119563549305718088453842093257734689508882969016290658885961965896726616361694426487326338043950416067501288065942862535560013037283761552797410980713186506671844418096395304234050342551849999 867017770968633512178545044838766793795733222455421862835695299142219006201321417882617773291364153890050471244104 | |
factoreal @ myThinkMate in .... $ 1 |
This file contains 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 scryptos import * | |
pubkey = 1043247381320041410146374847683905608886067988802815759655490071506964811427733496668055364700822779908166748193534341903285387332658081562041534228961538451830025041762537639985150344917584064827615356535763872539925989984117068207555498700585376330731428359489791600319636079777025344217248475485835298689437926003958578141784379857951264973109214803916445702964047899447002191548965239884095802091798787988745415178578597206815122915438351636672681355517982410123569961242563194480399347961753678159210217993526738306796503660563163029287419732210247579793266891085178817047536758465239950861266592524206390869822972469137566045176690277813352563392838847417674529251627419479815097868890993153215515488877097760272399483111013602618554846096893805108827211344467797072352072430591318485091677011261912992157762106672216780766138057271434398274272110062768324672899209610001835423246735718435995420720133657793744810610657 | |
privkey = 105717877672224295784291675385546750129601472163379527375367128238003471793097341763391999503913659542087520808364287167645349555897774428176288829031477703594776341268160433668976237198330124904372546897953955241778475322074160469767162566234358907740412805211247598698481640207956827199048419949848619731050860757808082106844953602176503247786535423423104239566910713528691298692332149783689032722772009974404716783312200885555343877611094998117307970399241640213553820043460140493803404190774171912962651075100983834071259021038322886114660028788229094872545516054757700068264628024524394995795135464746570071201 | |
enc = 343369686707916921497078851452395954252074753628024855326592148594828266567853497784448902839960599855457261387659174943864861324798607407210198762531665500523668627672623380100283047707927966101715266190355476680204081288124100983003649559499979731342450364456322062273208742008750774795951290651360492364136674198126979777860541228166734597108964573061640243513571440689299166495541329990802602494896619995591485311779060353650700199981044058309406067935205196708178000370643018639282003328307492888263256672104905274453644042024751439967243049147724769464785043328741645419214885736940487139062463786022104540986811119563549305718088453842093257734689508882969016290658885961965896726616361694426487326338043950416067501288065942862535560013037283761552797410980713186506671844418096395304234050342551849999867017770968633512178545044838766793795733222455421862835695299142219006201321417882617773291364153890050471244104 | |
n = pubkey | |
d = privkey | |
pow2 = pow(2, n*d, n) | |
assert pow2 != 2 | |
g = gcd(pow2 - 2, n) | |
assert g != 1 and g != n | |
assert n % g == 0 | |
pq = g | |
print [long_to_bytes(pow(enc, d, pq))] # => ['ASIS{Y0u_c4N_m4n493_Schmidt_5am0A_CryP7o_SysT3M!!}'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment