#!/usr/bin/env python3 from Crypto.Util.number import * # It's clear that: x*y + 37*x + 13*y = (x + 13) * (y + 37) - 13 * 37 # expr = x*y + 37*x + 13*y expr = 78165212618609657138836880180784953147937847225293529662866015685047230804901135619861816170298320767361932994009655444276454635767070943018615661814998170196988225114090917916739405210438739233946336624923903318136213856380816539075895614337743455379152165904564622942983293828630483375617563060841436037032 # Now try to factor (expr + 13 * 37), it's easy to check that (expr + 13 * 37) has only two prime factor :) # expr + 13 * 37 = (x + 13) * (y + 37) N = expr + 13 * 37 # python3 -m primefac N # 11963762482016783111 6533497529402055603646403092973137776146443537692607524362392132709879518444985038203228969704717741570837972352283511024609066666196224249075700651781381718135200089722249648104171275658471066248300072773775896536019470067922066326056012448278885442521552695200564882311694290367135046383 # Then: x = 11963762482016783111 - 13 y = 6533497529402055603646403092973137776146443537692607524362392132709879518444985038203228969704717741570837972352283511024609066666196224249075700651781381718135200089722249648104171275658471066248300072773775896536019470067922066326056012448278885442521552695200564882311694290367135046383 - 37 # So we have an official RSA task here, first we factor x and y: x = 2 * 5981881241008391549 y = 2 * 3266748764701027801823201546486568888073221768846303762181196066354939759222492519101614484852358870785418986176141755512304533333098112124537850325890690859067600044861124824052085637829235533124150036386887948268009735033961033163028006224139442721260776347600282441155847145183567523173 phi = 2 * (x // 2 - 1) * (y // 2 - 1) e = 31337 d = inverse(e, phi) c = 77659016890839762768185177448290865321689103903688518906063059972868578338626965390649161940137932439934612804680280807664502018534568684267970075208429306631612376831959148670053665126977208637383716238501111347514927281055286901278746032120016861900738163160264095274050080381725656064614271318154902797773 # The original message is: m = pow(c, d, x * y) flag = long_to_bytes(m) print(f'flag = {flag}')