2023年SWPU NSS 秋季招新赛 (校外赛道)WP—Crypto

南飓风  金牌会员 | 2023-11-10 08:28:31 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 887|帖子 887|积分 2661

一、Caesar_base

题目信息
  1. s = "HIJKLMNOPQRSTUVWXYZABCDEFGhijklmnopqrstuvwxyzabcdefg0123456789+/"    #码表
  2. def My_base64_encode(inputs):
  3.         bin_str = []
  4.         for i in inputs:
  5.                 x = str(bin(ord(i))).replace('0b', '')
  6.                 bin_str.append('{:0>8}'.format(x))
  7.         #print(bin_str)
  8.         outputs = ""
  9.         nums = 0
  10.         while bin_str:
  11.                 temp_list = bin_str[:3]
  12.                 if(len(temp_list) != 3):
  13.                         nums = 3 - len(temp_list)
  14.                         while len(temp_list) < 3:
  15.                                 temp_list += ['0' * 8]
  16.                 temp_str = "".join(temp_list)
  17.                 #print(temp_str)
  18.                 temp_str_list = []
  19.                 for i in range(0,4):
  20.                         temp_str_list.append(int(temp_str[i*6:(i+1)*6],2))
  21.                 #print(temp_str_list)
  22.                 if nums:
  23.                         temp_str_list = temp_str_list[0:4 - nums]
  24.                        
  25.                 for i in temp_str_list:
  26.                         outputs += s[i]
  27.                 bin_str = bin_str[3:]
  28.         outputs += nums * '='
  29.         print("Encrypted String:\n%s "%outputs)
  30. print("-------input 'ys' to encode-------")       
  31. sr = input("Please input!\n")
  32. if(sr == "ys"):
  33.         input_str = input("Please enter a string that needs to be encrypted: \n")
  34.         My_base64_encode(input_str)            
  35.   
复制代码
根据第一行新表base64解码即可

二、EasyRSA

题目附件
  1. import libnum  
  2.   
  3. p=libnum.generate_prime(1024)  
  4. q=libnum.generate_prime(1024)  
  5. e=65537  
  6. m="NSSCTF{*******************}"  
  7. m=libnum.s2n(m)  
  8. n=p*q  
  9. phi_n=(p-1)*(q-1)  
  10. d=libnum.invmod(e,phi_n)  
  11. c=pow(m,e,n)  
  12.   
  13. print("p=",p)  
  14. print("q=",q)   
  15. print ("e=",e)  
  16. print ("c=",c)
  17. #p= 122912801126049869009003839542545176400185213365268209105714006257803073428638629824801261702125287814910668428403367391355051987389837804474055637991864563803834741161217607848968821280710324766558457056004037592628178078680121173634128054936108782807954132605887275556228703383455969903056759874047110115433
  18. #q= 120790113700754477830062212762518406876786376726996249661848284428829412089402183812692045970711341815805796005449714738748110749559462448861357011272792817313060401380148108517705435100103533857957024851181447994572972501120774586405811257420853542417275740953525627232008812587423053626515513859653865873671
  19. #e= 65537
  20. #c= 7094224488947659163318199615533819770556597977720767621640224798887506152292861133457571683713587909779712343346370719403811813233693263526316785431883833118583425528830238629831001255198236686372518770451273159769779374149881346761523688131115323441973953523582174059584087249568245044443295176738493785560215046375056269378223045128094953923926250055718405799885041115025529297362914403732661935017257507786348635366480744933193471899621592092711962814949533564454932121056035003021428158830645604347966849572981124877683317022116903132719663958775850982016292384237647664448371811915879714093710876989697939277005
复制代码
基础RSA
exp:
[code]import gmpy2from Crypto.Util.number import long_to_bytesp = 122912801126049869009003839542545176400185213365268209105714006257803073428638629824801261702125287814910668428403367391355051987389837804474055637991864563803834741161217607848968821280710324766558457056004037592628178078680121173634128054936108782807954132605887275556228703383455969903056759874047110115433q = 120790113700754477830062212762518406876786376726996249661848284428829412089402183812692045970711341815805796005449714738748110749559462448861357011272792817313060401380148108517705435100103533857957024851181447994572972501120774586405811257420853542417275740953525627232008812587423053626515513859653865873671c = 7094224488947659163318199615533819770556597977720767621640224798887506152292861133457571683713587909779712343346370719403811813233693263526316785431883833118583425528830238629831001255198236686372518770451273159769779374149881346761523688131115323441973953523582174059584087249568245044443295176738493785560215046375056269378223045128094953923926250055718405799885041115025529297362914403732661935017257507786348635366480744933193471899621592092711962814949533564454932121056035003021428158830645604347966849572981124877683317022116903132719663958775850982016292384237647664448371811915879714093710876989697939277005phi = (p-1) * (q-1)e = 65537n = p * qd = gmpy2.invert(e, phi)m = pow(c, d, n)print('
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

南飓风

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表