Created
July 12, 2020 07:52
-
-
Save yytasbag/d75c679da6c452e4e12468c0b680b59b to your computer and use it in GitHub Desktop.
TSGCTF 2020 sweet-like-apple-pie
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 Crypto.Util.number import * | |
R1 = RealField(998); R1 | |
RealNumber = R1 | |
# calculate t1 = arcsin(output) | |
# calculate t2 = pi - t1 | |
# solve linear cong: 10^299 * flag = t2 mod pi | |
def pi2(): | |
lasts, t, s, n, na, d, da = 0, R1(3), 3, 1, 0, 0, 24 | |
while s != lasts: | |
lasts = s | |
n, na = n + na, na + 8 | |
d, da = d + da, da + 32 | |
t = (t * n) / d | |
s += t | |
return s | |
pi = pi2() | |
def sin2(x): | |
x = R(x) % pi | |
p, factor = 0, x | |
for n in range(10000): | |
p += factor | |
factor *= - (x ** 2) / ((2 * n + 2) * (2 * n + 3)) | |
return p | |
x = 0.162452474092990408037062573408259688253995107643493293584426591003988903469791005222132158897198623144937279539555347413553688190959907095952250683633029959235933436782707275021817801890433801800730214807785288112267446678747104887584191096749196212784470161670299495426679759221652356130008110761143 | |
print(arcsin(x)) | |
t1 = 0.16317563760274096449072206226706138969608813915823060089904696867219050674349529473699077485324166107301677400198214572696291025373771977005460699177654679173873510871281393870913102947550839826319038943469831241191164283753165280426912074533597486915007225858970132342567867947771076975765821846727 | |
print(pi - t1) | |
t2 = 2.97841701598705227397192132101244149450108126021687522007589762363562589954271370389104405048887540690913131251130016092013093435581286246167075241635193432571154899398912458239642861514744055666719157499411266325402180329094399542951766241993522703999557630833375902518477564717050262384960203067400 | |
p = 314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914120 | |
t1 = 16317563760274096449072206226706138969608813915823060089904696867219050674349529473699077485324166107301677400198214572696291025373771977005460699177654679173873510871281393870913102947550839826319038943469831241191164283753165280426912074533597486915007225858970132342567867947771076975765821846727 | |
t2 = 297841701598705227397192132101244149450108126021687522007589762363562589954271370389104405048887540690913131251130016092013093435581286246167075241635193432571154899398912458239642861514744055666719157499411266325402180329094399542951766241993522703999557630833375902518477564717050262384960203067400 | |
R.<x> = PolynomialRing(Zmod(p//40)) | |
f = (10^299//40) * x - t2//40 | |
print(f.monic()) | |
flag = R(-7853981633974483096156608458198757210492923498437764552437361480769541015715522496570087063355292669955370216283205766617734611523876455579313398520320939551223521636163549493418135210571434074361754437275962215925343331417551514098569089684935495906861068132464569581158246674045381096870550298888) | |
print(flag) | |
flag = long_to_bytes(263242402188620591296809345763900985938312964200473796065223239490283903637606485897868228242508866003053284844081290367889142575152387147600323965) | |
print(flag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment