Skip to content

Commit

Permalink
Merge pull request #1 from Or4c13/Or4c13-patch-1
Browse files Browse the repository at this point in the history
Add files via upload
  • Loading branch information
Or4c13 authored May 10, 2024
2 parents 2118560 + 4ee71e5 commit 7c6c651
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Challenges/Curvesignin Revenge/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Alice's public key: Point(x=53887628258266977236946886765125225993985116834354341126233510219966071523616, y=28158965058787630555744590318664291139012897721840003355218563579301165856248)
Bob's public key: Point(x=34916507512495859038246013669842835077935990837718819374050138139835873991114, y=17695334453582551266443068581568418621987401844207090836349323784243222912322)
Encrypted flag: {'iv': 'aa4b4d17e2227752b79a811669915786', 'encrypt_flag': 'a4923a789d1ebe2a84c300bcf38dd564250089746a84509360ec8b728ecadac2fa5cd26bfdef00d26f8e6d2fcc4e6a00'}
66 changes: 66 additions & 0 deletions Challenges/Curvesignin Revenge/task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from random import randint
from os import urandom
from collections import namedtuple
from hashlib import sha256

from Crypto.Cipher import AES
from Crypto.Util.number import long_to_bytes
from Crypto.Util.Padding import pad
from secret import FLAG


Point = namedtuple("Point", "x y")


def add(P, Q):
Px, Py = P.x, P.y
Qx, Qy = Q.x, Q.y
Rx = (Px*Qx-e*Py*Qy) % N
Ry = (Px*Qy+Py*Qx) % N
return Point(Rx ,Ry)


def mul(P, exp):
Q = Point(1, 0)
while exp > 0:
if exp & 1:
Q = add(Q, P)
P = add(P, P)
exp >>= 1
return Q


def gen_key():
private_key = randint(1, N)
public_key = mul(G, private_key)
return (public_key, private_key)


def share_secret(P, d):
return mul(P, d).x


def encrypt(share_secret, flag):
key = sha256(long_to_bytes(share_secret)).digest()[:16]
iv = urandom(16)
cipher = AES.new(key, AES.MODE_CBC, iv)
ciphertext = cipher.encrypt(pad(flag,16))
data = {"iv":iv.hex(),"encrypt_flag":ciphertext.hex()}
return data


N = 61820395509869592945047899644070363303060865412602815892951881829112472104091
e = 133422
G = Point(37234080987968345210046814543941568534026683208134935256498818666416936228347,23681207802011885401101067347527183297441941230486570817545706194562153385116)
Alice_pub, n_a = gen_key()
Bob_pub, n_b = gen_key()
assert (Alice_pub.x**2 + e*Alice_pub.y**2) % N == 1
assert (Bob_pub.x**2 + e*Bob_pub.y**2) % N == 1

print(f"Alice's public key: {Alice_pub}")
print(f"Bob's public key: {Bob_pub}")

share = share_secret(Bob_pub, n_a)
enc = encrypt(share, FLAG)

print(f'Encrypted flag: {enc}')
32 changes: 32 additions & 0 deletions Challenges/Ezfactor/task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from sage.all import *
from Crypto.Util.number import *
from Crypto.Util.Padding import pad
from Crypto.Cipher import AES
from sercret import p,q,x1,y1,x2,y2,flag


e = 107851261855564315073903829182423950546788346138259394246439657948476619948171
n = 1612520630363003059353142253089981533043311564255746310310940263864745479492015266264329953981958844235674179099410756219312942121244956701500870363219075525408783798007163550423573845701695879459236385567459569561236623909034945892869546441146006017614916909993115637827270568507869830024659905586004136946481048074461682125996261736024637375095977789425181258537482384460658359276300923155102288360474915802803118320144780824862629986882661190674127696656788827

assert x1**2 + e*y1**2 == n
assert x2**2 + e*y2**2 == n
assert x1 != x2 and y1 != y2
assert p.bit_length() == q.bit_length() == 768
assert p*q == n


key = long_to_bytes(x1+x2+y1+y2)[:16]
iv = long_to_bytes((x1^x2)+(y1^y2))[:16]
cipher = AES.new(key,AES.MODE_CBC,iv)
Flag = cipher.encrypt(pad(flag,16)).hex()
gift = p>>360
print(Flag)
print(gift)
print(e)


'''
725039090b61b83a729d1e1061de62f0aae6b3c13aa601e2302b88393a910086497ccb4ef1e8d588a0fffe1e7b2ac46e
484571358830397929370234740984952703033447536470079158146615136255872598113610957918395761289775053764210538009624146851126
107851261855564315073903829182423950546788346138259394246439657948476619948171
'''
36 changes: 36 additions & 0 deletions Challenges/MinTrix/generate.sage
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from secret import flag
from Crypto.Cipher import AES
from Crypto.Util.number import long_to_bytes,getPrime

p = getPrime(32)
K = GF(p)
n,m = 66,99

def keygen():
sk,pk = [],[]
for _ in range(4):
A,B = random_matrix(K, m, n),random_matrix(K, n, m)
sk.append((A, B))
pk.append(A*B)
return (sk, pk)

def dh(sk, pk):
shared = []
for csk, cpk in zip(sk, pk):
A, B = csk
shared.append((A.transpose() * cpk * B.transpose()).det())
return shared

skA, pkA = keygen()
skB, pkB = keygen()

shA = dh(skA, pkB)
shB = dh(skB, pkA)

assert shA == shB

shared = b"".join(long_to_bytes(int(x)) for x in shA)
aes = AES.new(shared, AES.MODE_ECB)
ct = aes.encrypt(flag)

save((pkA, pkB, ct.hex()), "output")
Binary file added Challenges/MinTrix/output.sobj
Binary file not shown.
4 changes: 4 additions & 0 deletions Challenges/Modular/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
t = [11073785215399803853235061745025562471766281988061641769170576363313934679887217569801706599445660251521490126719635890179790621896844392956750809517990639, 12784423683616355098221440270623389347446777829352207702598822877935018742664765859424225840149743452815607228031166385525161497357580362090660087099463561, 7577732948268541787833560588485400689498904836182855054537116304468801803503701362142780756917159201619693280432140363109600711705084476590538898348091495, 10036538640393786727964860426918224804395694550532020220245239953525930433428030055698778916572386196731753524645673726564120152278880865190304242838501920, 10350368650118830326935007050127643692116265403962735788790668428564040409091749460517049732741049767368020817994528495057047372858538413379955184253035769, 13082554968320497009249783104283288691709656534267611249943658226578147441363459169752889315185021462154340729253550232757143969324177683836471761515296113, 11723150434377457341138045422253564051303981348922807490004982382654753129474768284517683118936761131376439630001542756355826193794438839584263048602040310, 2312593563786911571681233063720151667279804480769620841211384417877924447027383126968652725221072664250609182525144659105664559685824277385834372886285094, 8049485076552016296159857980961344802126929658650665671825539449229142359019667254159718901978033859414007639521459856787506712053910501662601618610514914, 12822523655335498062846821483569187428698965071054245766972798473300669853079078505565238968193164176053130900424396330887238266290091854068639522572449339, 1988079154144136979677332642795216452632297338094750910617093873182523143339869438995891613910990545752839876846627284570472460679615904755635544112116092, 9194005022626331512379119874845502249344166649769798000933209476153024446423815364991330602243774497089790879352599144546648334988413603137287141470786227, 11727206829831450157203317046245035552298279328303831066317871736717278323280297412293674926381591364506598009757202174628385178306540269839380835605774245, 11215884114131863628931482493525076575449310680468928386799247991075129949742646459804819103409234048309002257507655620363713887571426410650360692900914699, 13229252051259887566909445786745289385337948372770305233565261009723186917196139796699867121485348607425821132607169548715417088553975822119578238895523265, 2434133230340215157166799626659846713913609778121753977290859118021406007835503746444795101542893453323303681652821047182210814815480500209549189261212091]
h = [127689167482288014000425602448716351832061686812439342522706528519984932610953307949977350023021888687983251179153954114903130408334900302125917604314161605704555174302412954096635321614161214385582921381486515033274321858036598915744458540554641638486064496964212510591699130814604388251826605946884931609239, 56413040451215992468023998497689962423937259634730422435837574010842048007293695901884911359124444138173478449239034017088644337562220927468594721047524149961827124075147838400693750768945802932499189371097807548365894469129746580626236019137090009004220729941666144085424522735838394947258817989463046580083, 159096117503489718963992325680213552682830013716063476625015908241930978596419248762838492502713441290032524915163962289091138236114604143819360187403692143046854081221922184032793094745439121739937527053820166175718197141255384894581172929886611605237834758037034390281470190860024729504992421640301133083404, 148614330434083992178131965309280278458335893214841048516035856106213897958541973680637125288066896832409976839772740287748661345292024159485776320225956338647921725106379463224642461406265568922245631807144160289351197425214555754580233288475579979258758527061759197292322910306030807023192166185587921285671, 123345966798742829864063791304200566491120706593219158548382987040598862749861728657659502537047580298796463849444588459425801502067157624710064438370936408393253024836355432534385142463869549691987813313361098037942855131514209362841779839493625734946204159916085515497669218464956693057910996989418368224718, 143730572425993961234876793125643776784767574870493801394069361432939095891758175702481539677359617673034631044084638831967344534252877445924666622233969641174369690202553271751772918142543732283676883488826667008492638895690040854698522971159686315980188834562253564620383944905979625152892744587185914741619, 1899333675825489355648956982427596214776139771238039023541139046760215434943108710292661083292292953429117286234729966131691913785686567736252854362355954922873970819020441817967086919426033302536398011099152039375012125999540633921013012116333257553654574739476224062806921065018986994063829525027823407648, 40021946460891456694763667739829844641491219915874879792778254614695339805691219947475184567199479881579252472064910345853968456976632175231245612205653295824088485229980359745332624808591401283855146511631022408273586520877407674644614613998690455052346136191115393887831117621257895456840650358274704555826, 12587255965576618872424846983892765361571446840329606167872576672371962359763011155165681721852152650809792269562777388435588015401100477502385787955972250368547408410489592248270305167054993487526965497026997328059292719829447657379952511915845044662968837407738496706780296294079791108598328537710381157919, 35373123117894082903769877421701955286540504796790597579883645896246184957279758828485780634720987127549717035820445126876568629689752869185045633419105196626182281116564659179017183846877215180869022831602437473904695745472745901533685175353016286208073998879110512700881415857098355556619716927272875712543, 134932924556053419947479552023990513361719644723460306853893813536315826606671396974575808371962061681863431171645460950240068835345485082055042507057318484642248377464012190169846843382519054758782949721704286454756070440219919539517396121347211156022973464793745891250380424466962047539290876180276174954017, 27899997727957090644819589789584825770425643969528465008806641542434382954966398613498974641857103683569692073706544870428810334295672590103909799629869694715078979935157432679153773828133621666694959818824171709239244599243012260821032040518358082030953828035117001054087875399613540555646765816048615539771, 7990260348729651065061774330514759509564837031091710787389017717183671432285163356986386067690017705747754893027235277280940946101800970816540560960119674128607348218440305393345959072544795513286812841410488767361374115717105992844205502565330711799795306905954106878365241897255454156656558563160409751399, 27068508791948756691803985700118866000386053120093908814487276298724757390487696031090900109841931605137365394815754358395620936879082992913896989240280854388738478132736076967155970572855435930485296183348479074877371237239722477255173805754299750182013036348100323337537900501322375563232654474595361640515, 13068380881558918013590945724589640458561504299404063853219448769281966209348511384884736841017603963103299381103791221248018581424389899807981567417759391600600984972983942688701208630779299513897011464626036238552507148124206493947096118137357598103691906343263150876734284019870558697515292943970868900740, 144432759930368947380264594980501091338004849606824563808700906729893535126944352004834658811698724817007929870819639919440203958980489826241756941893529760770624315120979622281316834874867192315134768359044211887340768352160881022324364858511458276652532183301934534104684508521052564120793282785818867643234]
p = 164845988554803570034210932437537368454111382224593662888381752205097830374220032126019668095170780104196793308898619165077628440843625297811060080191510695127294662392565386869488665989314790417153155199484603115711496029502166530435242963549027629739137822533436875021838499822082806570509681528804270137211
{'iv': '27d72ebeda75d7dc922c928f151d2db0', 'encrypt_flag': '94cec3dc63fba1e8383852d852468d25ed7a2e05b4006d6162c3fcd4bef2565a'}
30 changes: 30 additions & 0 deletions Challenges/Modular/task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from Crypto.Util.number import *
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from hashlib import sha256
from secret import flag
import random
import os


n = 16
p = getPrime(1024)
s = random.randint(1,p-1)
T = 1 << 512
E = 1 << 328


t = [random.randint(1, T) for _ in range(n)]
e = [random.randint(1, E) for _ in range(n)]
h = [(inverse(s + t[i], p) - e[i]) % p for i in range(n)]

print("t = ", t)
print("h = ", h)
print("p = ", p)

key = sha256(long_to_bytes(s)).digest()[:16]
iv = os.urandom(16)
cipher = AES.new(key, AES.MODE_CBC, iv)
ciphertext = cipher.encrypt(pad(flag, 16))
data = {"iv": iv.hex(), "encrypt_flag": ciphertext.hex()}
print(data)
Loading

0 comments on commit 7c6c651

Please sign in to comment.