from math import gcd from functools import reduce from fractions import Fraction as Frac
N = 6
defread_num(prompt): try: num = int(input(prompt)) except: return0 return num if num > 0else0
print(f"Please give me {N} pairs of positive integers (x,y,z) " f"satisfying the equation `x/(y+z) + y/(z+x) + z/(x+y) = {N}`\n") anss = [] mark = 0 for i inrange(N): x = read_num("[>] x: ") y = read_num("[>] y: ") z = read_num("[>] z: ") if x * y * z == 0: # positive integer mark = 1 print("This is not what i want!\n") break if reduce(gcd, [x, y, z]) != 1: # (kx, ky, kz) mark = 1 print("This is not what i want!\n") break if Frac(x, y+z) + Frac(y, z+x) + Frac(z, x+y) != N: mark = 1 print("This is not what i want!\n") break ans = tuple(sorted([x, y, z])) # (y, x, z) if ans in anss: mark = 1 print("This is not what i want!\n") break else: print("You are right!\n") anss.append(ans) if mark == 0: flag = open('/flag', 'r').read() print("flag is: " + flag + "\n") else: print("Something wrong!\n")
# sagemath from gmpy2 import * from Crypto.Util.number import long_to_bytes as l2b
deffind_p_puls_q(f,k): s = 0 b = k for i inrange(2000): a = (s+b) // 2 if f.subs(x==a) > 0: s = a else: b = a return a
deffind_p(pq,n): p = var('p') if pq^2 - 4*n<0: return [] f = p^2 - pq*p+n r = f.roots() res = [] for i in r: if i[0]>0: res.append(int(i[0])) return (res[0],res[1])
PK = [] N = [ciphertexts[0]['n'],ciphertexts[1]['n'],ciphertexts[2]['n']] E = [ciphertexts[0]['e'],ciphertexts[1]['e'],ciphertexts[2]['e']] C = [ciphertexts[0]['c'],ciphertexts[1]['c'],ciphertexts[2]['c']]
Mat = matrix(ZZ,a) Mat_LLL=Mat.LLL() x = int(abs(Mat_LLL[0][0])//M) assert x * M == abs(Mat_LLL[0][0]) S=[Mat_LLL[0][1],Mat_LLL[0][2],Mat_LLL[0][3]] A=[round(N[0]^0.25)^2,round(N[1]^0.25)^2,round(N[2]^0.25)^2]
assert (E[0] * x - S[0]) % N[0] == 0 assert (E[1] * x - S[1]) % N[1] == 0 assert (E[2] * x - S[2]) % N[2] == 0 Y = [0,0,0] for i inrange(3): Y[i] = (E[i]*x - S[i]) // N[i] KK = [0,0,0] for i inrange(3): KK[i] = (E[i] * x -Y[i] * N[i] ) // Y[i]
x = var('x') FF = [0,0,0] for i inrange(3): FF[i] = (3*(KK[i]-1)*x-3*x^2)^2 - A[i]*(x^2-4*N[i]) ppq1 = find_p_puls_q(FF[0],KK[0]) ppq2 = find_p_puls_q(FF[1],KK[1]) ppq3 = find_p_puls_q(FF[2],KK[2])