Skip to main content

Embryonic Plant

In a post-apocalyptic world, you are an aspiring botanist who has dedicated his life to the study of plants and their genetic manipulation, and is an expert on their embryonic stage. On your journey around the world, hoping to find a way to artificially create plants that can withstand Earth's cruel environment, you have come across a new species in a seemingly inhospitable area. You know it's time for you to unlock the secrets of nature. Will 5 plants be enough?

script.py
from Crypto.Util.number import getPrime, long_to_bytes, inverse
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from hashlib import sha256
from secret import FLAG

class RNG:
def __init__(self, seed):
self.e = 0x10001
self.s = seed

self.r = getPrime(768)
while True:
self.p, self.q = getPrime(768), getPrime(768)
if self.p < self.r and self.q < self.r:
break

self.n = self.p * self.q * self.r
phi = (self.p - 1) * (self.q - 1) * (self.r - 1)
self.d = inverse(self.e, phi)

def next(self):
self.s = (self.s * self.p + self.q) % self.r
return self.s

def main():
rng = RNG(getPrime(512))
rns = [rng.next() for _ in range(5)]

key = sha256(long_to_bytes(rng.d)).digest()
cipher = AES.new(key, AES.MODE_ECB)
enc_flag = cipher.encrypt(pad(FLAG, 16)).hex()

with open('output.txt', 'w') as f:
f.write(f'n = {rng.n}\n')
f.write(f's = {rns}\n')
f.write(f'enc_flag = {enc_flag}\n')

if __name__ == "__main__":
main()
output.txt
n = 953212452632162415623854742466108898886257018761981737488515480124784784754313403541058723530771941185648440076953890845364164881753643355212476926626742101375422468157394494383915186197027584298810203766388023131196821200163753827759350781726289328080241887775877824351482527440834821313689834438591567613042759531267263403394331824891899899505726815540209695860955058659042180466101027165453544129867565132811217413181292156021136184504130428910065116301275284964237087553827437109939035287527986380535446925078275313404977210504275217640523278087762041948497195357622678060873426815474421439984697128135689500335385151376561597600186415289317989920506634067994928935237389715706143172780083
s = [107663563520221758967681052016945344894135463272720867342404293429418113761640130338846143415694339846703472327422471509923932434685628383794998869995327761272087050985560474031629673883432008583476972873462387774454021532562638911, 375715892557297364364744701696307763009546269920835800827316473134718210911604668305115761037621526838903749589794728067744014884724708180550902913867595275270476040258585551516530116122396379615935241551413224529146764536011818960, 1142431136128743680237588635513380046580339971378804783979851430431837015880156204447030433004896454182104721893126547029880672333914367506184442229874405762062665597996081499892502200704128255903361177726702376303206644325660472696, 696181402062958907421352186902458487367420124659441418095569426735447880619442484035499857372339751543528153083380619139649590779544110176169319718082842863368788080781170847125373363885050864587076550882230251633851030744318779877, 1090087409231264760633243725379604084008037546075358826209944877794280528534452761945892984736121167182908072643369909923239008686694491992033132238021506681618226619691505113704791978765000558863195023783700460638272869374754376211]
enc_flag = d3587442177b157fa0cecb6dd880872d86e15a50e3f05ecfeea8b90f5cfca22835a59d9c4f23e87a68317d4ccabe1bf3aa2e6cdf0a9ef1ada0a2e83d8da0bff2b739cf0e2b2b779958d9b1154a6f3698

Solution

This WriteUp Solution is password protected by the flag of the challenge.