Tags: crypto 

Rating:

# Stairs Solution

c(0) = M^5 + M

f(m) := c(m) + c(-m) = [(m+M)^5 + (m+M)] +[(-m+M)^5 + (-m+M)] = 2 [M^5 + 10 M^3 m^2 + 5 M m^4 + M]

=> f(1) = 2 [M^5 + 10 M^3 + 5 M + M]

=> f(2) = 2 [M^5 + 40 M^3 + 80 M + M]

g(m) := f(m) - 2c(0)

=> g(1) = 2 [10 M^3 + 5 M]

=> g(2) = 2 [40 M^3 + 80 M]

=> z := g(2) - 4 g(1) = 120M

```python
# def encrypt(m, pubkey):
# e, n = 5, pubkey
# M = bytes_to_long(flag)
# m += M
# c = (pow(m, e, n) + m) % n
# return c
```

```python
from Crypto.Util.number import long_to_bytes

c_1 = 12463077482655592763773366940880588926584228850407850339364181354846334126052671318897613578395695990018699160526907202319265735461128531927796708834352851351256559994513280826469425788437494169402668137459362817944188032721699614155454171030318962381934816494593759068057514483016703434559811896159566893993877243093155680502678078643747085758774608428107758051330929819636589600827968063140896881634241333293096729766367426049793272256646070943903762348960353790030013336127573323474856989179359305462881963153355054137409935427599962730203487306808445222233204538719844193217236957466682890527951820584629429371450
c__1 = 3753837927705671097829371224269226524158585603879158025371024930431241718952604087411658855108988511662936454442646226168162690103586254641939305821956373380582075481026830448124795911077561485418744841591726353724069422160611166134067750506560839176310354380884292667368476307648708002757417022166965818488782277458111315158897229680256613380709477941238795027484706484557053314607718526268771350352325307432422902448235149586649496644536779060392154491282559366807002996944319167541244608999187807830109725218803121787950947557275232709114760219703480585940255843162252971846172461100823188627171112571055761412611
c_2 = 7730012393233342659678707921008810746878404081499062136184700912073843560689179219049759089680499575982167283801997637538644310198428379626828381827692870569908745071832045629443146527741505391422556282259625241012901229742635679094071806397645541708211271607488866935216097215731182623149932669201780517377785765945197588128901970031197347668507502646099406433735929380840556381806561605217233108079080495973081273505634988844500066876760590853093089809104825674323566010288313958367178312911997323745971522804927436068469540148420595704537914277553236949466601737896420827301604001397403738694618265838018551844485
c__2 = 8486903017127921201924030244141004703864410372787946228550505373203732284316096187259513523036180945329901246001001421568495427017653070385044938191923177177913049818386082659636143966460495805606731455248033176359781936083140522322191406090358777248531580907042711722234453236399458440055260006035005373226157502721003235995682526893078074666170420725895429223920895772306671711504844108814606969428229743348312448501515909185649324863084584501277108892998258486005484364734987732171886439945690522259495393063293279773096267545415658685672225700098053397760493644966141884032184052720120250422816358217961899566356
c_0 = 17196142572077842867868025960752367106290053619316638542543661797618824691416163418745468126848224410598708675529631977306457597940950905376144137628781773137932094722087188361657394647362464794785404912144623476776950072681918689592416965980033888855157588594716505952291998451052397754792995038344629126324018930771915571289799793209113824363014627367100563517651764005334294387065289206476142101608871577220919248409755485774049006659472680561345883849272869641924026337162176508507680338678795898694528712694227196315287976520258286011500792806795321378141975406736314902938738642102145276725311400594037409988985
n = 18175369733794421874133313756354918761837292784346268720352117309960073537827051431181663879929096326059259374367525736332057207534309245329931362389023262549353273773526937786882257193438855782152021764723680863787117927462681739270892440740229481951569233526972802476499525998594460614231415743999476599539139590364208756405694007627647857318276447365737334816101621322792807584653464865083339919738091046581610227869091170042890785363982710178341304542855929735124851737137744386709989103127410960965245687401589925555954462177586218477935744409330241286147698912174842986248284816420752086859202406157677593944089
```

```python
g_1 = (c_1+c__1) - 2*c_0
g_2 = (c_2+c__2) - 2*c_0
z = (g_2-4*g_1) % n
```

```python
for k in range(0, 2):
m = k*n+z
if m % 120 == 0:
m = m//120
print(k)
print(long_to_bytes(m).decode())
```

```python
# :::. The flag is: ASIS{7hI5_cryptOsySt3M_Iz_DeF1nit3lY_vUlNEr4bl3!?} .:::
```

Original writeup (https://github.com/pfire-ctf/asis2021-finals-writeups/blob/main/Stairs).