题目如下:

输出的结果:

题目分析:

在原题的题目描述中并没有什么有用的消息,更多的信息是通过代码审计出来的。大致意思是,先把字节flag转换为二进制形式的字符串,然后判断字符串中每个字符,如果为1,则直接添加到cipertext列表中,否则对n 取负再求余,得到结果添加到cipertext列表中。

源码中给了a和p,根据前面知识,先计算一下勒让德符号(Legendre's Symbol):(a / p) ≡ a(p-1)/2 mod p

a_p = pow(a, (p - 1) // 2, p)
print(a_p)

返回结果为:1

说明a 是二次剩余,a的幂也是二次剩余,原因由二次剩余性质得到,如下:

Quadratic Residue,简称QR,中文称作二次剩余,则QNR 称作二次非剩余

所以 a<sup>e</sup>&nbsp;可看成 e 个 a 相乘,则&nbsp;&nbsp;a<sup>e</sup>&nbsp;也是二次剩余

因为 b == ‘1’ 时是直接把 n 添加到 cipertext 列表中的,所以我们对 n 求勒让德符号,结果为 1 则说明&nbsp;a<sup>e</sup>&nbsp;为二次剩余,满足上述条件,则 b = 1

勒让德符号服从如下关系:

<img src="https://img2022.cnblogs.com/blog/2842002/202207/2842002-20220707133427893-962023011.png" alt="" loading="lazy">

否则 我们断言 n 不是二次剩余,返回的是 p - 1。原因是勒让德符号等于 -1 ,而pow函数是不会返回负数,则返回的是 p - 1

解题代码:

#coding:utf-8
result_list = [67594220461269, 501237540280788, 718316769824518, 296304224247167, 48290626940198, 30829701196032, 521453693392074, 840985324383794, 770420008897119, 745131486581197, 729163531979577, 334563813238599, 289746215495432, 538664937794468, 894085795317163, 983410189487558, 863330928724430, 996272871140947, 352175210511707, 306237700811584, 631393408838583, 589243747914057, 538776819034934, 365364592128161, 454970171810424, 986711310037393, 657756453404881, 388329936724352, 90991447679370, 714742162831112, 62293519842555, 653941126489711, 448552658212336, 970169071154259, 339472870407614, 406225588145372, 205721593331090, 926225022409823, 904451547059845, 789074084078342, 886420071481685, 796827329208633, 433047156347276, 21271315846750, 719248860593631, 534059295222748, 879864647580512, 918055794962142, 635545050939893, 319549343320339, 93008646178282, 926080110625306, 385476640825005, 483740420173050, 866208659796189, 883359067574584, 913405110264883, 898864873510337, 208598541987988, 23412800024088, 911541450703474, 57446699305445, 513296484586451, 180356843554043, 756391301483653, 823695939808936, 452898981558365, 383286682802447, 381394258915860, 385482809649632, 357950424436020, 212891024562585, 906036654538589, 706766032862393, 500658491083279, 134746243085697, 240386541491998, 850341345692155, 826490944132718, 329513332018620, 41046816597282, 396581286424992, 488863267297267, 92023040998362, 529684488438507, 925328511390026, 524897846090435, 413156582909097, 840524616502482, 325719016994120, 402494835113608, 145033960690364, 43932113323388, 683561775499473, 434510534220939, 92584300328516, 763767269974656, 289837041593468, 11468527450938, 628247946152943, 8844724571683, 813851806959975, 72001988637120, 875394575395153, 70667866716476, 75304931994100, 226809172374264, 767059176444181, 45462007920789, 472607315695803, 325973946551448, 64200767729194, 534886246409921, 950408390792175, 492288777130394, 226746605380806, 944479111810431, 776057001143579, 658971626589122, 231918349590349, 699710172246548, 122457405264610, 643115611310737, 999072890586878, 203230862786955, 348112034218733, 240143417330886, 927148962961842, 661569511006072, 190334725550806, 763365444730995, 516228913786395, 846501182194443, 741210200995504, 511935604454925, 687689993302203, 631038090127480, 961606522916414, 138550017953034, 932105540686829, 215285284639233, 772628158955819, 496858298527292, 730971468815108, 896733219370353, 967083685727881, 607660822695530, 650953466617730, 133773994258132, 623283311953090, 436380836970128, 237114930094468, 115451711811481, 674593269112948, 140400921371770, 659335660634071, 536749311958781, 854645598266824, 303305169095255, 91430489108219, 573739385205188, 400604977158702, 728593782212529, 807432219147040, 893541884126828, 183964371201281, 422680633277230, 218817645778789, 313025293025224, 657253930848472, 747562211812373, 83456701182914, 470417289614736, 641146659305859, 468130225316006, 46960547227850, 875638267674897, 662661765336441, 186533085001285, 743250648436106, 451414956181714, 527954145201673, 922589993405001, 242119479617901, 865476357142231, 988987578447349, 430198555146088, 477890180119931, 844464003254807, 503374203275928, 775374254241792, 346653210679737, 789242808338116, 48503976498612, 604300186163323, 475930096252359, 860836853339514, 994513691290102, 591343659366796, 944852018048514, 82396968629164, 152776642436549, 916070996204621, 305574094667054, 981194179562189, 126174175810273, 55636640522694, 44670495393401, 74724541586529, 988608465654705, 870533906709633, 374564052429787, 486493568142979, 469485372072295, 221153171135022, 289713227465073, 952450431038075, 107298466441025, 938262809228861, 253919870663003, 835790485199226, 655456538877798, 595464842927075, 191621819564547]
a = 288260533169915
p = 1007621497415251 #计算勒让德符号
a_p = pow(a, (p - 1) // 2, p)
print(a_p) # print(len(result_list)) 224
plaintext = ''
for m in result_list:
L = pow(m, (p - 1) // 2, p)
# print(L)
if L == 1:
plaintext += '1'
else:
assert L == p - 1
plaintext += '0'
print(plaintext) flag = ''
for i in range(0, len(plaintext), 8):
flag += chr(int(plaintext[i: i+8], 2))
print(flag)

总结:

勒让德符号可以用来快速判断一个数是不是二次剩余,当模数p 满足 模 4 余 3 时,还可以推出 (a(p+1)/4 )2  ≡ a mod p 然后计算出 x2 ≡ a mod p 中的x。

Cryptohack的Adrien's Signs解题思路的更多相关文章

  1. n皇后2种解题思路与代码-Java与C++实现

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了n皇后问题的解题思路,并分别用java和c++实现了过程,最后,对于算法改进 ...

  2. 阿里聚安全攻防挑战赛第三题Android PwnMe解题思路

    阿里聚安全攻防挑战赛第三题Android PwnMe解题思路 大家在聚安全挑战赛正式赛第三题中,遇到android app 远程控制的题目.我们今天带你一探究竟,如何攻破这道题目. 一.题目 购物应用 ...

  3. [LeetCode] 16. 3Sum Closest 解题思路

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  4. [LeetCode] 234. Palindrome Linked List 解题思路

    Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time ...

  5. [LeetCode] 76. Minimum Window Substring 解题思路

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  6. [LeetCode] 3Sum 解题思路

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  7. [LeetCode] Minimum Size Subarray Sum 解题思路

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  8. [LeetCode] Word Break 解题思路

    Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...

  9. [LeetCode] Longest Valid Parentheses 解题思路

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

随机推荐

  1. C++面向对象编程之reference

    1.声明 reference 一定要有初值,指针可以不用设初值 2. int& r = x; 表示 r 代表 x, r 用起来就是 x ,而且 reference 设完初值后再也不能代表其他变 ...

  2. Codeforces Round #804 (Div. 2) C(组合 + mex)

    Codeforces Round #804 (Div. 2) C(组合 + mex) 本萌新的第一篇题解qwq 题目链接: 传送门QAQ 题意: 给定一个\(\left [0,n-1 \right ] ...

  3. 图解不同版本的HTTP协议

    前言 大家好,我是蜗牛,今天我们聊聊HTTP协议,通过这篇文章我们能了解到不同版本HTTP优缺点.他们之间的性能差异以及现在主流的HTTP协议用的那个版本 HTTP/1.1 时代 HTTP/1.1 对 ...

  4. jsp中使用Servlet查询SQLSERVER数据库中的表的信息,并且打印在屏幕上

    jsp中使用Servlet查询SQLSERVER数据库中的表的信息,并且打印在屏幕上 1.JavaBean的使用 package com.zheng; public class BookBean { ...

  5. Vue中组件化编码 完成任务的添加、删除、统计、勾选需求(实战练习三完结)

    上一个章节实现数据在组件之间的传递 .这一章主要是完成添加任务到任务栏.删除任务栏.统计任务完成情况.主要还是参数在各个组件之间的传递. 上一章节的链接地址:https://blog.csdn.net ...

  6. 7.Gitee导入其他远程托管中心仓库

    的码云是开源中国推出的基于Git的代码托管服务中心 网址是https://gitee.com/,使用方式跟github一致,并且是一个中文网站 码云的使用配置方式与github一致,码云支持导入git ...

  7. 8.pygame-定时器

    使用定时器添加敌机 游戏启动后,每隔一秒出现一架敌方飞机 每架飞机向屏幕下方飞行,速度各不相同 没加敌机出现的水平位置也不进相同 当敌机从屏幕下方飞出,不会再飞回到屏幕中   定时器 pygame中使 ...

  8. [转]VB中资源文件.res的使用方法详解

    来源:https://blog.csdn.net/miaozk2006/article/details/82417156 在几乎所有的Windows应用程序中都拥有资源文件,这些文件定义使用应用程序将 ...

  9. elasticsearch聚合之bucket terms聚合

    目录 1. 背景 2. 前置条件 2.1 创建索引 2.2 准备数据 3. 各种聚合 3.1 统计人数最多的2个省 3.1.1 dsl 3.1.2 运行结果 3.2 统计人数最少的2个省 3.2.1 ...

  10. Java—猜数字

    package cn.day03.demo01; import java.util.Random; import java.util.Scanner; public class RandomGame ...