首页 > 其他分享 >LUC_RSA

LUC_RSA

时间:2024-06-10 17:26:02浏览次数:22  
标签:gmpy2 idx int pow RSA LUC LS import

https://www.math.u-bordeaux.fr/~gcastagn/publi/crypto_quad.pdf

https://www.researchgate.net/publication/26623030_A_New_Computation_Algorithm_for_a_Cryptosystem_Based_on_Lucas_Functions

最近通过qwb了解到了这个新东西,顺手进一步加深了对于LUCAS序列的理解。

典型例题

UMass CTF 2021 - Weird RSA

import random
from Crypto.Util.number import isPrime

m, Q = """REDACTED""", 1 

def genPrimes(size):
    base = random.getrandbits(size // 2) << size // 2
    base = base | (1 << 1023) | (1 << 1022) | 1
    while True:
        temp = base | random.getrandbits(size // 4)
        if isPrime(temp):
            p = temp
            break
    while True:
        temp = base | random.getrandbits(size // 4)
        if isPrime(temp):
            q = temp
            break
    return (p, q)

def pow(m, e, n):     
    return v(e)

def v(n):
    if n == 0:
        return 2
    if n == 1:
        return m
    return (m*v(n-1) - Q*v(n-2)) % N

p, q = genPrimes(1024)

N = p * q
e = 0x10001

print("N:", N)
print("c:", pow(m, e, N))

"""
N: 18378141703504870053256589621469911325593449136456168833252297256858537217774550712713558376586907139191035169090694633962713086351032581652760861668116820553602617805166170038411635411122411322217633088733925562474573155702958062785336418656834129389796123636312497589092777440651253803216182746548802100609496930688436148522617770670087143010376380205698834648595913982981670535389045333406092868158446779681106756879563374434867509327405933798082589697167457848396375382835193219251999626538126258606572805220878283429607438382521692951006432650132816122705167004219371235964716616826653226062550260270958038670427
c: 14470740653145070679700019966554818534890999807830802232451906444910279478539396448114592242906623394239703347815141824698585119347592990685923384931479024856262941313458084648914561375377956072245149926143782368239175037299219241806241533201175001088200209202522586119648246842120571566051381821899459346757935757111233323915022287370687524912870425787594648397524189694991735372527387329346198018567010117587531474035014342584491831714256980975368294579192077738910916486139823489975038981139084864837358039928972730135031064241393391678984872799573965150169368237298603189344477806873779325227557835790957023000991
"""

LUC-RSA Solution

So how does it work? Well to encrypt (as we’ve seen) we calculate the e-th order Lucas sequence with P=m and Q=1. Then, to decrypt we calculate the d-th order Lucas sequence with P=c and Q=1. Huh, sounds quite neat. Our next step is to find the private exponent d, however there’s a catch. We cannot use our familiar

那么它是如何工作的呢?好吧,为了加密(正如我们所看到的),我们计算 P=m 和 Q=1 的第 e 阶卢卡斯序列。然后,为了解密,我们计算 P=c 和 Q=1 的第 d 阶卢卡斯序列。呵呵,听起来很整洁。我们的下一步是找到私有指数 d,但有一个问题。我们不能使用我们熟悉的

d = ~e % phi(N),

instead we use 取而代之的是,我们使用

d = ~e % LCM( (p +- 1), (q +- 1) ).

Now we end up with four possible decryption keys. We could easily try them all out, but we can also find the proper form from

现在我们最终得到了四个可能的解密密钥。我们可以很容易地尝试它们,但我们也可以从中找到合适的形式

d = ~e % LCM( (p - LS(D/p)), (q - LS(D/q)) )

where LS is the Legendre symbol and D = C^2 - 4 the discriminant (abc-formula, anyone?). Finally, just to speed things up, we implement a more efficient encryption function (provided by the chall’s author: Soul). Now we can go and get ourselves a nice flag

标签:gmpy2,idx,int,pow,RSA,LUC,LS,import
From: https://www.cnblogs.com/JustGo12/p/18240796

相关文章

  • rsa加密过长数据工具类
    rsa默认最多只能加密密钥长度/8-11长度的明文,最多只能解密密钥长度/8长度的密文,如:密钥长度为1024,则明文长度最长117,密文长度最长128。可以采用分段加解密的方式,增加明文密文长度(同时加解密的效率也会按比例降低)。工具类如下: packagecom.kuandeng.common.common.util;imp......
  • RSAUtils 非对称加密hutool
    1、使用hutool的rsa加解密工具,自定义公钥私钥字符串2、importcn.hutool.core.codec.Base64Decoder;importcn.hutool.crypto.asymmetric.KeyType;importcn.hutool.crypto.asymmetric.RSA;importlombok.extern.slf4j.Slf4j;importorg.jeecg.common.util.CN;importjav......
  • Towards Universal Sequence Representation Learning for Recommender Systems
    目录概符号说明UniSRec统一的文本表示统一的序列表示Parameter-EfficientFine-tuning代码HouY.,MuS.,ZhaoW.X.,LiY.,DingB.andWenJ.TowardsUniversalSequenceRepresentationLearningforRecommenderSystems.KDD,2022.概本文提出了一个用text替代ID......
  • you will hear two long conversations. At the end of each conversation, you will
    Directions:inthissection,youwillheartwolongconversations.Attheendofeachconversation,youwillhearfourquestions.Boththeconversationandthequestionswillbespokenonlyonce.Afteryouhearaquestion,youmustchoosethebestanswer......
  • NSS刷题心得1(古典+RSA)
    古典密码在线工具:https://ctf.bugku.com/tools.html一键解码工具库:随波逐流,在github上下载即可注:古典密码只需做个了解,因为很多都是靠工具实现的,多刷题有个印象,遇到题能看出像什么密码就好。Base家族在密码学领域,"base"通常指的是一种编码方式,用于将二进制数据转换为可......
  • 前端服务端React(Next.js)、Vue(Nuxt.js)、Angular(Universal)渲染搭建和开发案例
    前端服务端渲染(Server-SideRendering,简称SSR)是一种Web开发技术,它允许服务器动态生成HTML内容,然后将其发送到客户端,客户端再将这些HTML内容渲染成页面。这种方式可以提高首屏加载速度,改善SEO,以及提供更好的用户体验。前端服务端渲染搭建步骤:选择框架:选择支持服务端渲染......
  • TS2Vec: 面向通用的时间序列表示《TS2Vec: Towards Universal Representation of Time
    今天是2024年5月22日,10:24,今天看这篇经典的论文(如果你问我为什么最近频繁看论文,因为我的创新点无了,要找创新点+太菜了,菜就多看多学)。论文:TS2Vec:TowardsUniversalRepresentationofTimeSeries或者是:TS2Vec:TowardsUniversalRepresentationofTimeSeriesGitHub:https......
  • crypto--rsa基础(1)
    在ctf---crypto中rsa应该是最常见也是现在最容易考到的密码题型吧,这篇博客就简单的介绍一下rsa和rsa的一些基本的攻击手法.对于我们这些萌新来说要做rsa的话也必须先掌握四大基本公式就是欧拉函数,费马小定理,中国剩余定理,威尔逊定理,现在就先基本了解一下就能够做题了,在网上的百度......
  • Microsoft Office for Mac 2024 (Office 365) 16.85 Universal 预览版下载
    MicrosoftOfficeforMac2024(Office365)16.85Universal预览版OfficeLTSC2024forMac请访问原文链接:https://sysin.org/blog/office-2024-for-mac/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org宣布推出适用于Windows和Mac的MicrosoftOfficeLTSC......
  • Microsoft Office for Mac 2021 (Office 365) 16.85 Universal 下载
    MicrosoftOfficeforMac2021(Office365)16.85UniversalOfficeLTSC2021forMac请访问原文链接:https://sysin.org/blog/office-2021-for-mac/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org2021.09.16,微软正式发布了OfficeLTSC2021,当然也包括forMac......