from Crypto.Util.number import inverse, long_to_bytes from gmpy2 import next_prime
n = 739243847275389709472067387827484120222494013590074140985399787562594529286597003777105115865446795908819036678700460141950875653695331369163361757157565377531721748744087900881582744902312177979298217791686598853486325684322963787498115587802274229739619528838187967527241366076438154697056550549800691528794136318856475884632511630403822825738299776018390079577728412776535367041632122565639036104271672497418509514781304810585503673226324238396489752427801699815592314894581630994590796084123504542794857800330419850716997654738103615725794629029775421170515512063019994761051891597378859698320651083189969905297963140966329378723373071590797203169830069428503544761584694131795243115146000564792100471259594488081571644541077283644666700962953460073953965250264401973080467760912924607461783312953419038084626809675807995463244073984979942740289741147504741715039830341488696960977502423702097709564068478477284161645957293908613935974036643029971491102157321238525596348807395784120585247899369773609341654908807803007460425271832839341595078200327677265778582728994058920387721181708105894076110057858324994417035004076234418186156340413169154344814582980205732305163274822509982340820301144418789572738830713925750250925049059 c = 229043746793674889024653533006701296308351926745769842802636384094759379740300534278302123222014817911580006421847607123049816103885365851535481716236688330600113899345346872012870482410945158758991441294885546642304012025685141746649427132063040233448959783730507539964445711789203948478927754968414484217451929590364252823034436736148936707526491427134910817676292865910899256335978084133885301776638189969716684447886272526371596438362601308765248327164568010211340540749408337495125393161427493827866434814073414211359223724290251545324578501542643767456072748245099538268121741616645942503700796441269556575769250208333551820150640236503765376932896479238435739865805059908532831741588166990610406781319538995712584992928490839557809170189205452152534029118700150959965267557712569942462430810977059565077290952031751528357957124339169562549386600024298334407498257172578971559253328179357443841427429904013090062097483222125930742322794450873759719977981171221926439985786944884991660612824458339473263174969955453188212116242701330480313264281033623774772556593174438510101491596667187356827935296256470338269472769781778576964130967761897357847487612475534606977433259616857569013270917400687539344772924214733633652812119743 e = 65537 l = 2331# DP 序列长度
# 状态机定义 defbuild_transition(): transition = {s: {} for s inrange(7)} for s inrange(7): for b in [0, 1]: if s in [1, 2, 3]: # 连续的 1 co = s transition[s][b] = co + 1if b == 1and co + 1 < 4else (4if b == 0else -1) elif s in [4, 5, 6]: # 连续的 0 cz = s - 3 transition[s][b] = cz + 4if b == 0and cz + 1 < 4else (1if b == 1else -1) else: # 中性状态 transition[s][b] = 1if b == 1else4 return transition
for pos inrange(1, l - 1): curr, prev = pos % 2, (pos - 1) % 2 DP[curr] = [0] * 7 for s inrange(7): if DP[prev][s] == 0: continue for b in [0, 1]: next_s = transition[s][b] if next_s != -1: DP[curr][next_s] += DP[prev][s]
# 处理最后一位为 1 的情况 total = 0 curr = (l - 2) % 2 for s inrange(7): if DP[curr][s] == 0: continue next_s = transition[s][1] if next_s != -1: total += DP[curr][s] return total
# 求解 RSA 因子和解密 defdecrypt_rsa(n, c, e, key): p = int(next_prime(key)) q = n // p assert p * q == n, "分解 n 失败!"
phi = (p - 1) * (q - 1) d = inverse(e, phi) m = pow(c, d, n) return long_to_bytes(m)
try: xor_result_str = xor_result.decode('utf-8') print(f"XOR Result as String: {xor_result_str}") except UnicodeDecodeError: print("XOR result contains non-printable characters, cannot convert to a string.")