首页 > 其他分享 >连分数分解(心情不好,爬起,遂有此烂文)

连分数分解(心情不好,爬起,遂有此烂文)

时间:2024-10-09 16:33:46浏览次数:6  
标签:p2 q1 p1 q2 连分数 cf 此烂文 分解

关于标题

今晚的月色深藏云间。(呜呜呜我就是在发癫)

连分数分解问题和勒让德定理关系较多,至少知道什么是连分数什么是勒让德定理。

维纳攻击 wiener attack

  攻击条件:

攻击原理:

适用情况和例题

出现多因子+大数时考虑连分数分解

[湖湘杯 2021]signin

附件:

from Crypto.Util.number import *
from secret import flag
import random

m1 = bytes_to_long(flag[:len(flag) // 2])
m2 = bytes_to_long(flag[len(flag) // 2:])

def gen(pbits, qbits):
    p1, q1 = getPrime(pbits), getPrime(qbits)
    n1 = p1**4*q1
    q2 = getPrime(qbits)
    bound = p1 // (8*q1*q2) + 1
    p2 = random.randrange(p1, p1 + bound)
    while not isPrime(p2):
        p2 = random.randrange(p1, p1 + bound)
    n2 = p2**4*q2
    return (n1, n2), (p1, q1), (p2, q2)

e = 0x10001
pbits = int(360)
qbits = int(128)
pk, sk1, sk2 = gen(pbits, qbits)
c1 = pow(m1, e, pk[0])
c2 = pow(m2, e, pk[1])
print(f'pk = {pk}')
print(f'c1, c2 = {c1, c2}')

"""
pk = (1150398070565459492080597718626032792435556703413923483458704675295997646493249759818468321328556510074044954676615760446708253531839417036997811506222349194302791943489195718713797322878586379546657275419261647635859989280700191441312691274285176619391539387875252135478424580680264554294179123254566796890998243909286508189826458854346825493157697201495100628216832191035903848391447704849808577310612723700318670466035077202673373956324725108350230357879374234418393233, 1242678737076048096780023147702514112272319497423818488193557934695583793070332178723043194823444815153743889740338870676093799728875725651036060313223096288606947708155579060628807516053981975820338028456770109640111153719903207363617099371353910243497871090334898522942934052035102902892149792570965804205461900841595290667647854346905445201396273291648968142608158533514391348407631818144116768794595226974831093526512117505486679153727123796834305088741279455621586989)
c1, c2 = (361624030197288323178211941746074961985876772079713896964822566468795093475887773853629454653096485450671233584616088768705417987527877166166213574572987732852155320225332020636386698169212072312758052524652761304795529199864805108000796457423822443871436659548626629448170698048984709740274043050729249408577243328282313593461300703078854044587993248807613713896590402657788194264718603549894361488507629356532718775278399264279359256975688280723740017979438505001819438, 33322989148902718763644384246610630825314206644879155585369541624158380990667828419255828083639294898100922608833810585530801931417726134558845725168047585271855248605561256531342703212030641555260907310067120102069499927711242804407691706542428236208695153618955781372741765233319988193384708525251620506966304554054884590718068210659709406626033891748214407992041364462525367373648910810036622684929049996166651416565651803952838857960054689875755131784246099270581394)
"""

思路:

计算连分数表示和连分数的收敛值,获取两数的最大公约数

exp:

from Crypto.Util.number import *
from gmpy2 import *
from sympy import *

def continued_fra(x,y):
    cf = []
    while y!=0:
        cf.append(x//y)
        x,y = y,x%y
    
    return cf

def exp(x,y):
    cf = continued_fra(x,y)
    fz = [cf[0],cf[0]*cf[1]+1]
    fm = [1,cf[1]]
    for i in range(2,len(cf)):
        z = fz[i-1]*cf[i]+fz[i-2]
        m = fm[i-1]*cf[i]+fm[i-2]
        fz.append(z)
        fm.append(m)
    
    return fz,fm

def get(x,y):
    tmp1,tmp2 = exp(x,y)
    for i in range(2,len(tmp1)):
        xx,yy = tmp1[i],tmp2[i]
        if x%xx==0 and y%yy==0 and x!=xx and y!=yy:
            return xx,yy



c1, c2 = (361624030197288323178211941746074961985876772079713896964822566468795093475887773853629454653096485450671233584616088768705417987527877166166213574572987732852155320225332020636386698169212072312758052524652761304795529199864805108000796457423822443871436659548626629448170698048984709740274043050729249408577243328282313593461300703078854044587993248807613713896590402657788194264718603549894361488507629356532718775278399264279359256975688280723740017979438505001819438, 33322989148902718763644384246610630825314206644879155585369541624158380990667828419255828083639294898100922608833810585530801931417726134558845725168047585271855248605561256531342703212030641555260907310067120102069499927711242804407691706542428236208695153618955781372741765233319988193384708525251620506966304554054884590718068210659709406626033891748214407992041364462525367373648910810036622684929049996166651416565651803952838857960054689875755131784246099270581394)
e = 0x10001
n1 = 1150398070565459492080597718626032792435556703413923483458704675295997646493249759818468321328556510074044954676615760446708253531839417036997811506222349194302791943489195718713797322878586379546657275419261647635859989280700191441312691274285176619391539387875252135478424580680264554294179123254566796890998243909286508189826458854346825493157697201495100628216832191035903848391447704849808577310612723700318670466035077202673373956324725108350230357879374234418393233
n2 = 1242678737076048096780023147702514112272319497423818488193557934695583793070332178723043194823444815153743889740338870676093799728875725651036060313223096288606947708155579060628807516053981975820338028456770109640111153719903207363617099371353910243497871090334898522942934052035102902892149792570965804205461900841595290667647854346905445201396273291648968142608158533514391348407631818144116768794595226974831093526512117505486679153727123796834305088741279455621586989
e = int(e)


q1,q2 = get(n1,n2)

p1 = gmpy2.iroot(n1//q1,4)[0]
p2 = gmpy2.iroot(n2//q2,4)[0]

phi1 = p1**3*(p1-1)*(q1-1)
phi2 = p2**3*(p2-1)*(q2-1)

d1 = inverse(e,phi1)
d2 = inverse(e,phi2)

m1 = pow(c1,d1,n1)
m2 = pow(c2,d2,n2)

print(long_to_bytes(m1)+long_to_bytes(m2))

标签:p2,q1,p1,q2,连分数,cf,此烂文,分解
From: https://www.cnblogs.com/snoozy/p/18454587

相关文章

  • 干货|CNAS-CL01设备部分解读,透彻掌握软件测试实验室设备关键点
    CNAS-CL01《检测和校准实验室能力认可准则》是软件测试实验室建立符合CNAS标准的质量管理体系必须要贯彻的一部准则,分为五大核心部分:通用要求、结构要求、资源要求、过程要求和管理体系要求。前面的文章中我们为大家分享了通用要求部分、结构要求部分以及资源要求中的人员部分,......
  • 数学分解软件CNum2025下载download
    本软件可以算单个整数的因式分解。本软件可以算2个整数的最大公因数、最小公倍数。本软件可以判断输入的整数是否是素数或者合数。本软件支持中英文双语界面,可以打开、保存和清空工作数据。本软件是共享软件,支持软件,可以获得更好的未来的软件。Thissoftwarecancalculatet......
  • 中秋献礼!2024年中科院一区极光优化算法+分解对比!VMD-PLO-Transformer-LSTM多变量时间
    中秋献礼!2024年中科院一区极光优化算法+分解对比!VMD-PLO-Transformer-LSTM多变量时间序列光伏功率预测目录中秋献礼!2024年中科院一区极光优化算法+分解对比!VMD-PLO-Transformer-LSTM多变量时间序列光伏功率预测效果一览基本介绍程序设计参考资料效果一览基本介绍1.中秋献礼!2024年......
  • 论文速递!时序预测!DCSDNet:双卷积季节性分解网络,应用于天然气消费预测过程
    本期推文将介绍一种新的时序预测方法:双卷积季节性分解网络(DualConvolutionwithSeasonalDecompositionNetwork,DCSDNet)在天然气消费预测的应用,这项研究发表于《AppliedEnergy》期刊。针对天然气消费的多重季节性和非规律性,推荐的文献提出了一种新的预测方法:双卷积季节性分解......
  • 2024年JCR一区极光优化算法+分解对比!VMD-PLO-Transformer-BiLSTM多变量时间序列光伏功
    中秋献礼!2024年中科院一区极光优化算法+分解对比!VMD-PLO-Transformer-LSTM多变量时间序列光伏功率预测目录中秋献礼!2024年中科院一区极光优化算法+分解对比!VMD-PLO-Transformer-LSTM多变量时间序列光伏功率预测效果一览基本介绍程序设计参考资料效果一览基本介绍1.中秋献礼!2024年......
  • 基于AFM注意因子分解机的推荐算法
    1.项目简介项目A033基于AFM(AttentionFactorizationMachine)的推荐算法,旨在通过引入注意力机制提升推荐系统的性能。推荐系统的核心是帮助用户在海量信息中找到符合个人需求的内容,而传统的因子分解机(FM)模型虽然能够捕捉特征间的线性关系,却无法有效利用复杂的高阶特征交互......
  • 求1000以内所有恰好能分解成10组两个素数之和
    要求根据哥德巴赫猜想,任意一个大偶数都可以分解为两个素数之和。但许多偶数分解为两个素数之和并不是唯一的。请编写函数fun,其功能是:求1000(不包括1000)以内的所有恰好能分解成10组两个素数之和(5+109和109+5被认为是同一组)的偶并依次存入数组a中并在屏幕上打印出来,打印时......
  • 【C++ 差分数组 前后缀分解】P7404家庭菜园
    本文涉及知识点C++差分数组C++前后缀分解P7404家庭菜园出自洛谷,我简述一下。已知数组a,长度为n(1<=n<=2e5),1<=a[i]<=1e9。一次操作如下:将a[i…j]全+1。问最少操作多少次,使得a成为山形数组,即存在k,a[0…k]严格递增,a[k…]严格递减。前后缀分解+差分数组(错误解法)n=a.......
  • 信息学奥赛初赛天天练-92-CSP-S2023阅读程序2-动态数组、反转函数、埃氏筛法、欧拉筛
    2023CSP-S阅读程序2判断题正确填√,错误填⨉;除特殊说明外,判断题1.5分,选择题3分,共计40分)01#include<iostream>02#include<cmath>03#include<vector>04#include<algorithm>05usingnamespacestd;0607longlongsolve1(intn){08vector<bo......
  • 信息学奥赛初赛天天练-92-CSP-S2023阅读程序2-动态数组、反转函数、埃氏筛法、欧拉筛
    2023CSP-S阅读程序2判断题正确填√,错误填⨉;除特殊说明外,判断题1.5分,选择题3分,共计40分)01#include<iostream>02#include<cmath>03#include<vector>04#include<algorithm>05usingnamespacestd;0607longlongsolve1(intn){08vector<boo......