Cryptohack的Adrien's Signs解题思路
题目如下:
输出的结果:
题目分析:
在原题的题目描述中并没有什么有用的消息,更多的信息是通过代码审计出来的。大致意思是,先把字节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> 可看成 e 个 a 相乘,则 a<sup>e</sup> 也是二次剩余
因为 b == ‘1’ 时是直接把 n 添加到 cipertext 列表中的,所以我们对 n 求勒让德符号,结果为 1 则说明 a<sup>e</sup> 为二次剩余,满足上述条件,则 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解题思路的更多相关文章
- n皇后2种解题思路与代码-Java与C++实现
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了n皇后问题的解题思路,并分别用java和c++实现了过程,最后,对于算法改进 ...
- 阿里聚安全攻防挑战赛第三题Android PwnMe解题思路
阿里聚安全攻防挑战赛第三题Android PwnMe解题思路 大家在聚安全挑战赛正式赛第三题中,遇到android app 远程控制的题目.我们今天带你一探究竟,如何攻破这道题目. 一.题目 购物应用 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [LeetCode] Minimum Size Subarray Sum 解题思路
Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...
- [LeetCode] Word Break 解题思路
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- [LeetCode] Longest Valid Parentheses 解题思路
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
随机推荐
- SpringBoot入门项目CRM学习过程中的报错记录(更新ing)
在用mybatis自动生成实体类和mapper时报错..... is unrecognized or represents more than one time zone. You must conf ...
- RAID5 IO处理之对齐读代码详解
1 总体流程 当一个读请求的覆盖范围落在一个chunk范围内时为对齐读,流程图如下所示: 2 入口 在RAID5的IO处理函数 make_request() 一开始进行了对齐读的判断和处理,代码如下所 ...
- 一篇文章带你掌握主流办公框架——SpringBoot
一篇文章带你掌握主流办公框架--SpringBoot 在之前的文章中我们已经学习了SSM的全部内容以及相关整合 SSM是Spring的产品,主要用来简化开发,但我们现在所介绍的这款框架--Spring ...
- Java云原生崛起微服务框架Quarkus入门实践
@ 目录 概述 定义 GraalVM简介 为何使用 特性 官方性能 实战 入门示例 步骤 安装GraalVM 创建quarkus工程 Idea导入项目 Idea运行和调试 打包成普通的Jar 打包成依 ...
- 常用排序算法(C语言)
1.冒泡排序 void BubbleSort(int a[],int len) {int tmp; for (int i=0; i<n-1; i++) { int flag = FALSE; f ...
- python关于Django搭建简单博客项目(教程)
由于csdn各种django blog博文都有或多或少的bug,所以我决定自己写一篇,先附上教程,详解在另一篇博文里,为了便于大家复制粘贴,本文代码尽量不使用图片. 源代码及解析文章请在我的githu ...
- letcode刷题记录-day02-回文数
回文数 题目描述 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标. 你可以假设每种输入只会对应一个答 ...
- python 的time、datetime模块
python 时间模块 import datetime res = datetime.datetime.now() print(res) # 2022-08-07 16:47:07.120459 ...
- django-environ学习
官方说明:https://django-environ.readthedocs.io/en/latest/index.html install pip install django-environ q ...
- JUC学习笔记——共享模型之管程
JUC学习笔记--共享模型之管程 在本系列内容中我们会对JUC做一个系统的学习,本片将会介绍JUC的管程部分 我们会分为以下几部分进行介绍: 共享问题 共享问题解决方案 线程安全分析 Monitor ...