第七届楚慧杯 Crypto

文章内容涉及使用AES加密算法,通过矩阵变换和随机数预测来解密数据。首先,对原始的base64编码进行处理,然后通过一系列的矩阵变换操作,再利用随机数生成器的预测方法来恢复随机数矩阵,最终解密出隐藏的信息。
摘要由CSDN通过智能技术生成

旋转base

base64变种,做替换

import base64
base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
flag = "ly9tl+gDcvc9Zyc/kvdtYfNtafw+ZfYCYCQAZPUDZicEZvgBk/hwVfpQ"
for i in range(64):
    res=''
    for j in flag:
        res+=base[(base.index(j)-i) %64]
    print(base64.b64decode(res))

Ro1l!

老套路了随机数预测,不过最后才更新附件什么意思?

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


def Ro1l(Matrix):
    L = len(list(Matrix))
    tmp = matrix(ZZ, L, L)
    for i in range(L):
        for j in range(L):
            tmp[i, j] = Matrix[j][L-1-i]
    return tmp

key = random.randbytes(16)

data = []
for j in range(625):
    num = ''
    for i in random.randbytes(4):
        num += str(i).zfill(4)
    num = int(num)
    data.append(num)

iv = long_to_bytes(random.getrandbits(128))
M = matrix(25,25,data)
for i in range(int(random.randint(1, 2022220220222202))):
    M = Ro1l(M)


cipher = AES.new(key, AES.MODE_CBC, iv)
with open('Ro!l.txt', 'w') as f:
    f.writelines(str(M)+'\n')
    f.writelines(str(cipher.encrypt(flag)))

还有你这个矩阵数据读起来很浪费时间,两次对称,周期为4,所以四次变换都试一下。得到随机数列表,贴心给了625个数据,多一个给我们来验证.

然后就很简单的随机数向前向后预测

还原随机数矩阵

s='''
[112009002480190  70021500330218   7008700480181 209000200040085 198013501410177 142020202190226 221000401800044 193001101320020  33011700560070 127004202330227 238004100390136  35008200150181 222005301370247 199015101660124 203012700570089 135024501180241 108006101480224 132001802450184 181019400850172 252000800540221  52014800390217 170012601240122 242013301550019 234001100990024  21014900890219]
[ 12021902110144 214013300290251  77000500170134 198025300440114  19012000560186 233016900830121  95004502200183      1201220097  12012002450226 182018601580024 155005602310123  91009201870044 236018002540064   3004602480168  91003901630077  32001701780176 133018402510173 162011400980036 227018500750111  72002901110050  54019702090106 252011400690126 175008600440111  53009701480118 123020101050213]
[ 98017101620115  62014702270022  78008002390095  77007801900239 121015702050017 239017801280055 240009202490063 237007501240199 143014500230145  69016701210084  30015502110072 225024901260105 216023702140034  13020102350232 137003401840020 110024601680170  25002700690194 191017401890138 209024902150145 169012500550108 225008501880103 222022000610187  90022401390230  53017000070171 179017802280131]
[ 93011802000237 129024701070129  79016201270147  69018001710006 190024900820224 251004402320048 226020801270097  86018300990084  26011800970152 137007100710178  37011601490132  93020300560108 197006400680193 255010301220201 129001701420076  83015302440058 120015400450074 141011800190149 141022500390141 143001800320150 175003200070144 106017200020079 225022802110185 138002000120253  44001902010055]
[ 43020501500027 117014802420249  28024202200136  53018200650130 185006302030091 255016602070142 173011700190087 140018300480124  31015901990113 131015301630177 151006900190103  29024501140089 230009801330056  60021301440023 202017200860070  51021400320146  49007002410030 195022201930014  32025300130021 212008402550243 193006901590110  67011300420186 113022901500043 204008201010159 254024500460204]
[163006601050051 185012700200105 103019101210122 171001300000245 132015301780201  59017802100124 241009100590241 209014400160131 176000501390175 132022800720005 123009401220255  73008901200194 170022502020141 160012101760030  20018500250128  66001501890177  13009600120118 135003202140047 186011002050089  11018700480237 139012601860200 135024300350127  89011401460141  13025201640030 221001802490113]
[149009002370213 112001901220153 182009402510213 223023401950103  19016101140136 173017501040036 156016900830179 231022201310030  10009401630035 160025300440006 150023301320079  23019000420161 101018800320195  35021400250052  51023900180118  75023600290112 231008600150163 100010100650086 138005802180187 133008401840098 124003602450191  24005200300047  77012600380012  85013400050029 142018600870220]
[132014401610185  69008900070098  69021100250049 246016200300222 253022702400229 163016602550049  57011300350158  45008101510033 186009500320009  80011301850185 140009001820079 220000802310157 192001200590127 191011002470193  40020802120202  58006001490110 236011500550213  64012502010233 233017201680240  99022901110170 148012000970255 214010001460244 204015501540143 178009701980115 105023401560037]
[ 74011302530003  64016300240158 223019502460164  90018001490123   8014300200188  72025501370051 117024000920193 126013101760017 172006100860037 247006200000229  60008601560236  23007701490126  55024101010000 131022201680117  83018302100129  50007400770197 170009701290126 225002602170251 118017000260234 230019601200109 152003601290212 152010502480168  17001800670039  49025301590016  12013102410159]
[171010802290021 195011201870119  40007400060232 140021201400078  88016700450247  62018701560199  98021302140254 247012900900120  71007502230084 106017800690224  12001600860181 117011701880042  48010300700003 253001602540193 193020200960038 204022501460127 105017501340047  28012001950076 211005200460083 164018100550214 202024201300190  36007702210230 155010501590237 185024802330126 181015102180015]
[ 26002201230064 197006201660105 168009100010055 153018700610018 149011801870182  38024900300228  38000402180029 123016901050230     19100950153  85015600300200 209003900200123 107016301340250 208013601280071 228020301820035 213008702510113  60003700510240  25013201490203  57005601380049 199012101900249 218024701990094 253018901270009   7025502380032 215011201370234 229000401150027 221007100620022]
[ 15007500780236  82019100560107  97014501110207 158003901760108 104013101760230 112009802370199  35011800520007  45006301450155 123008901160243 179002400790075  90006001200146 220025101190108 145021201730065 101010701890034  87015300180245  95023201200064  23017100280028  68016801380031 227017901630083 216007201060168 187009101160002  71008101040191 206012601020249  49013901210164 249022001260135]
[ 48021001800035 167008901210106 141005300520043 147002101380198 201018302210128 151006500920174  82006001710180   2010901640103 111025300300120  90002401160042 243017901320091 100013500280102 123014800750231 124017901500024  22001701820017  21017002510152  55019500970004 244010402150206 160006901630009  39007302220050  71016601110104  93009201270249  92009800470197 212012000360145 129013102170067]
[125015402290215 139008401760124  45016602490126  72016800900000  23008202310155  78000300030069 157000001180248  12000300610171  73014200700012 189004900990152 206018102480186 127016902050081 174006200330063 110020801740092 147024101300109  20022200670173 219020800500175   4009202400113  63006202080087 173024201510159 204010301270034 143011900790019 208002901210242 231006301590178 112020002150156]
[ 25024400590147 201006100440155  76009801110008  48023301690102  59012200360063 154014700320012  26016601130079 116017600990129 130022200530190  20021901080085 190000800260237 175024800190046  22010100370221 118019500120044   2007401000112  98006200080112 157006400530067 174012201980212 146003300750125  93017100810120  49001302160224  22012902090014 121015900560014 230011401160188 151008300930255]
[133021700450086 225009701370046 141024502460138 107014500230076 169010600430155 203003501300190  95020700910192  68001800120210 187015201650112 141019801290000 146007400200097 134013500790200 185013300930122 253001700900239 134018001590205 105000000020205 139002000320245 229010301660151 223009300120174  26008301240213 121022702320182 252024301350063 190011600920196 115004500650241  21001201750137]
[148013400500251  60014300670240  30018100760229 140022201910084 124015300000047 108002000790171  46012201430084 139002302490190 173004501410212  81018002360115  15016700440133  82005200760137 134016102300064  25019101160234 190019101180111 231010200010139 173014600650236  88001000890041 149021500520050 250007801990226  23015600900190 151005600300198 155013900540121 101017202190005  51016702460065]
[116010501150003  22003400940106  93011700490178  90009101460197  36018501150096 253007001470143  53021100820097 107005901520026  95000700690248 199003500380186  19001700370056  96008301930187  43001201030004  90018801590052  87023702190011 156012800470032 244008101760112 140014301770073 104000102420006 117013000940166 171004102520128 113021301180038  38013401830141 229023700390146  73014000920173]
[ 73007301780194 111013701350101 152010801740060 207006600800152 117019301920048 206022701950204 178015401760029 233022501900016 122002502450129 145024202330129 246013900260121 207001702260160  51010902320149  92023800730069 159001100570019  43018400520057 142024602000131  84002601990232 119006400910203 117024300930183 211023700050195 128018500400072 152008500030072 148010401430047  60001101820199]
[ 35023802280152 107020100110074 229011300470254  85001700620196 240013501320126 112016601600001 143022401020188 143002502520038  97021200700150  92020402280063  72013602300176 160013102220031  14016002480010 225023901350128 200020101810195  31013301870185  28023202540194 220005200350165  26006001210213  53024400910031   4003100930066 164007601460177 107002901550094 192003601320033 161005300400226]
[ 49006102290103 177006801880247 240017500150199  73000701330157  17023202400213   3001502040224 181010102400160 140005601860032  58009800100100  26023502240163 152024401640102  28003501290034  99003900250025  59023200050091   7011600430079 101025401790236 229023200880177 124004400440013 177021001390097  60005300280251  60023501490159  83022601720182 252005900720168 177015501600104 193004902460253]
[ 50008601160039 104018801440017 102005701840001 124020401080249  10017300520137 208009700750058  15015300400253 126000700750155 120010401260150 150014602160121  73021600470252  11019601480010 110011402050091  18016301560165 115008802350121 106007100540077 248007401230175  70011202140237 106019300490039 135014001270048 182021401970030 169016302470107  45011700150023 255004501060135  87001801620009]
[217024900480146 156025002000110 160002602200200  74015700040144  93014401630039  40019600000119  57011600180165  76023901050159  28010701530144  29000101780238  81025400090132 208009902270185  90019700260060 118020800700100  67019000760170  18011502160056 109004301170017 187008201920133 205008800090185 131012900370082 183003602370118  83001800710095  75007601410231  31009200850235 203021200420170]
[ 35018600180237 230024101130112  18014701850120  17002801610243  51010700740225 113012401560087  48002802020225 242004702010174 243014700580089  65019702550216  92019901700236  76022401060255  47019500540214 131002000380104  39019100760204  69006501580121 178014301610109 192017301980242  24003500280112   8021701620212  47002601510126  72000202270077 179014500370104 175012500410167 197017301990236]
[203009701300184 112024802060021 150001802040162  26005700090141  49024801630122 140019102310061 243009900760216  77021600050132  98005800800044  10021100930172 118006701100225   1002402510126  49009700340122 214013800640214 116012200030030 123015900940178 188016500850006  83013002530099  60014601700156 211011302260224  41023000890088  59022901760240   8006201350238 192009600580032  83010800090142]
'''
from Crypto.Util.number import *
# from randcrack import RandCrack
# from extend_mt19937_predictor import ExtendMT19937Predictor
s=s.replace('[',' ').replace('\n','').replace(']',' ')
res=[]
num=''
for i in s:
    if i==' ' and num!='':
        res.append(int(num))
        num=''
        continue
    if i==' ' and num=='':
        continue
    else:
        num+=i
    # print(num)
# res.append(83010800090142)
res=res[::-1]

m = Matrix(25,25,res)


def Ro1l(matrix):
    L = len(list(matrix))
    tmp = Matrix(ZZ, L, L)
    for i in range(L):
        for j in range(L):
            tmp[i, j] = matrix[j][L-1-i]
    return tmp

for i in range(4):
    m=Ro1l(m)
# print(m[0,0],m[24,24])
m=vector(m)
m

预测

from Crypto.Cipher import AES

from Crypto.Util.number import *
from randcrack import RandCrack
from extend_mt19937_predictor import ExtendMT19937Predictor
res=(83010800090142, 192009600580032, 8006201350238, 59022901760240, 41023000890088, 211011302260224, 60014601700156, 83013002530099, 188016500850006, 123015900940178, 116012200030030, 214013800640214, 49009700340122, 1002402510126, 118006701100225, 10021100930172, 98005800800044, 77021600050132, 243009900760216, 140019102310061, 49024801630122, 26005700090141, 150001802040162, 112024802060021, 203009701300184, 197017301990236, 175012500410167, 179014500370104, 72000202270077, 47002601510126, 8021701620212, 24003500280112, 192017301980242, 178014301610109, 69006501580121, 39019100760204, 131002000380104, 47019500540214, 76022401060255, 92019901700236, 65019702550216, 243014700580089, 242004702010174, 48002802020225, 113012401560087, 51010700740225, 17002801610243, 18014701850120, 230024101130112, 35018600180237, 203021200420170, 31009200850235, 75007601410231, 83001800710095, 183003602370118, 131012900370082, 205008800090185, 187008201920133, 109004301170017, 18011502160056, 67019000760170, 118020800700100, 90019700260060, 208009902270185, 81025400090132, 29000101780238, 28010701530144, 76023901050159, 57011600180165, 40019600000119, 93014401630039, 74015700040144, 160002602200200, 156025002000110, 217024900480146, 87001801620009, 255004501060135, 45011700150023, 169016302470107, 182021401970030, 135014001270048, 106019300490039, 70011202140237, 248007401230175, 106007100540077, 115008802350121, 18016301560165, 110011402050091, 11019601480010, 73021600470252, 150014602160121, 120010401260150, 126000700750155, 15015300400253, 208009700750058, 10017300520137, 124020401080249, 102005701840001, 104018801440017, 50008601160039, 193004902460253, 177015501600104, 252005900720168, 83022601720182, 60023501490159, 60005300280251, 177021001390097, 124004400440013, 229023200880177, 101025401790236, 7011600430079, 59023200050091, 99003900250025, 28003501290034, 152024401640102, 26023502240163, 58009800100100, 140005601860032, 181010102400160, 3001502040224, 17023202400213, 73000701330157, 240017500150199, 177006801880247, 49006102290103, 161005300400226, 192003601320033, 107002901550094, 164007601460177, 4003100930066, 53024400910031, 26006001210213, 220005200350165, 28023202540194, 31013301870185, 200020101810195, 225023901350128, 14016002480010, 160013102220031, 72013602300176, 92020402280063, 97021200700150, 143002502520038, 143022401020188, 112016601600001, 240013501320126, 85001700620196, 229011300470254, 107020100110074, 35023802280152, 60001101820199, 148010401430047, 152008500030072, 128018500400072, 211023700050195, 117024300930183, 119006400910203, 84002601990232, 142024602000131, 43018400520057, 159001100570019, 92023800730069, 51010902320149, 207001702260160, 246013900260121, 145024202330129, 122002502450129, 233022501900016, 178015401760029, 206022701950204, 117019301920048, 207006600800152, 152010801740060, 111013701350101, 73007301780194, 73014000920173, 229023700390146, 38013401830141, 113021301180038, 171004102520128, 117013000940166, 104000102420006, 140014301770073, 244008101760112, 156012800470032, 87023702190011, 90018801590052, 43001201030004, 96008301930187, 19001700370056, 199003500380186, 95000700690248, 107005901520026, 53021100820097, 253007001470143, 36018501150096, 90009101460197, 93011700490178, 22003400940106, 116010501150003, 51016702460065, 101017202190005, 155013900540121, 151005600300198, 23015600900190, 250007801990226, 149021500520050, 88001000890041, 173014600650236, 231010200010139, 190019101180111, 25019101160234, 134016102300064, 82005200760137, 15016700440133, 81018002360115, 173004501410212, 139002302490190, 46012201430084, 108002000790171, 124015300000047, 140022201910084, 30018100760229, 60014300670240, 148013400500251, 21001201750137, 115004500650241, 190011600920196, 252024301350063, 121022702320182, 26008301240213, 223009300120174, 229010301660151, 139002000320245, 105000000020205, 134018001590205, 253001700900239, 185013300930122, 134013500790200, 146007400200097, 141019801290000, 187015201650112, 68001800120210, 95020700910192, 203003501300190, 169010600430155, 107014500230076, 141024502460138, 225009701370046, 133021700450086, 151008300930255, 230011401160188, 121015900560014, 22012902090014, 49001302160224, 93017100810120, 146003300750125, 174012201980212, 157006400530067, 98006200080112, 2007401000112, 118019500120044, 22010100370221, 175024800190046, 190000800260237, 20021901080085, 130022200530190, 116017600990129, 26016601130079, 154014700320012, 59012200360063, 48023301690102, 76009801110008, 201006100440155, 25024400590147, 112020002150156, 231006301590178, 208002901210242, 143011900790019, 204010301270034, 173024201510159, 63006202080087, 4009202400113, 219020800500175, 20022200670173, 147024101300109, 110020801740092, 174006200330063, 127016902050081, 206018102480186, 189004900990152, 73014200700012, 12000300610171, 157000001180248, 78000300030069, 23008202310155, 72016800900000, 45016602490126, 139008401760124, 125015402290215, 129013102170067, 212012000360145, 92009800470197, 93009201270249, 71016601110104, 39007302220050, 160006901630009, 244010402150206, 55019500970004, 21017002510152, 22001701820017, 124017901500024, 123014800750231, 100013500280102, 243017901320091, 90002401160042, 111025300300120, 2010901640103, 82006001710180, 151006500920174, 201018302210128, 147002101380198, 141005300520043, 167008901210106, 48021001800035, 249022001260135, 49013901210164, 206012601020249, 71008101040191, 187009101160002, 216007201060168, 227017901630083, 68016801380031, 23017100280028, 95023201200064, 87015300180245, 101010701890034, 145021201730065, 220025101190108, 90006001200146, 179002400790075, 123008901160243, 45006301450155, 35011800520007, 112009802370199, 104013101760230, 158003901760108, 97014501110207, 82019100560107, 15007500780236, 221007100620022, 229000401150027, 215011201370234, 7025502380032, 253018901270009, 218024701990094, 199012101900249, 57005601380049, 25013201490203, 60003700510240, 213008702510113, 228020301820035, 208013601280071, 107016301340250, 209003900200123, 85015600300200, 19100950153, 123016901050230, 38000402180029, 38024900300228, 149011801870182, 153018700610018, 168009100010055, 197006201660105, 26002201230064, 181015102180015, 185024802330126, 155010501590237, 36007702210230, 202024201300190, 164018100550214, 211005200460083, 28012001950076, 105017501340047, 204022501460127, 193020200960038, 253001602540193, 48010300700003, 117011701880042, 12001600860181, 106017800690224, 71007502230084, 247012900900120, 98021302140254, 62018701560199, 88016700450247, 140021201400078, 40007400060232, 195011201870119, 171010802290021, 12013102410159, 49025301590016, 17001800670039, 152010502480168, 152003601290212, 230019601200109, 118017000260234, 225002602170251, 170009701290126, 50007400770197, 83018302100129, 131022201680117, 55024101010000, 23007701490126, 60008601560236, 247006200000229, 172006100860037, 126013101760017, 117024000920193, 72025501370051, 8014300200188, 90018001490123, 223019502460164, 64016300240158, 74011302530003, 105023401560037, 178009701980115, 204015501540143, 214010001460244, 148012000970255, 99022901110170, 233017201680240, 64012502010233, 236011500550213, 58006001490110, 40020802120202, 191011002470193, 192001200590127, 220000802310157, 140009001820079, 80011301850185, 186009500320009, 45008101510033, 57011300350158, 163016602550049, 253022702400229, 246016200300222, 69021100250049, 69008900070098, 132014401610185, 142018600870220, 85013400050029, 77012600380012, 24005200300047, 124003602450191, 133008401840098, 138005802180187, 100010100650086, 231008600150163, 75023600290112, 51023900180118, 35021400250052, 101018800320195, 23019000420161, 150023301320079, 160025300440006, 10009401630035, 231022201310030, 156016900830179, 173017501040036, 19016101140136, 223023401950103, 182009402510213, 112001901220153, 149009002370213, 221001802490113, 13025201640030, 89011401460141, 135024300350127, 139012601860200, 11018700480237, 186011002050089, 135003202140047, 13009600120118, 66001501890177, 20018500250128, 160012101760030, 170022502020141, 73008901200194, 123009401220255, 132022800720005, 176000501390175, 209014400160131, 241009100590241, 59017802100124, 132015301780201, 171001300000245, 103019101210122, 185012700200105, 163006601050051, 254024500460204, 204008201010159, 113022901500043, 67011300420186, 193006901590110, 212008402550243, 32025300130021, 195022201930014, 49007002410030, 51021400320146, 202017200860070, 60021301440023, 230009801330056, 29024501140089, 151006900190103, 131015301630177, 31015901990113, 140018300480124, 173011700190087, 255016602070142, 185006302030091, 53018200650130, 28024202200136, 117014802420249, 43020501500027, 44001902010055, 138002000120253, 225022802110185, 106017200020079, 175003200070144, 143001800320150, 141022500390141, 141011800190149, 120015400450074, 83015302440058, 129001701420076, 255010301220201, 197006400680193, 93020300560108, 37011601490132, 137007100710178, 26011800970152, 86018300990084, 226020801270097, 251004402320048, 190024900820224, 69018001710006, 79016201270147, 129024701070129, 93011802000237, 179017802280131, 53017000070171, 90022401390230, 222022000610187, 225008501880103, 169012500550108, 209024902150145, 191017401890138, 25002700690194, 110024601680170, 137003401840020, 13020102350232, 216023702140034, 225024901260105, 30015502110072, 69016701210084, 143014500230145, 237007501240199, 240009202490063, 239017801280055, 121015702050017, 77007801900239, 78008002390095, 62014702270022, 98017101620115, 123020101050213, 53009701480118, 175008600440111, 252011400690126, 54019702090106, 72002901110050, 227018500750111, 162011400980036, 133018402510173, 32001701780176, 91003901630077, 3004602480168, 236018002540064, 91009201870044, 155005602310123, 182018601580024, 12012002450226, 1201220097, 95004502200183, 233016900830121, 19012000560186, 198025300440114, 77000500170134, 214013300290251, 12021902110144, 21014900890219, 234001100990024, 242013301550019, 170012601240122, 52014800390217, 252000800540221, 181019400850172, 132001802450184, 108006101480224, 135024501180241, 203012700570089, 199015101660124, 222005301370247, 35008200150181, 238004100390136, 127004202330227, 33011700560070, 193001101320020, 221000401800044, 142020202190226, 198013501410177, 209000200040085, 7008700480181, 70021500330218, 112009002480190)


rc=RandCrack()
predictor = ExtendMT19937Predictor()
def rem(num):
    num=str(num).zfill(16)
    # print(num)
    by=b''
    for i in range(0,16,4):
        by+= long_to_bytes(int(num[i:i+4]))
    rc.submit(bytes_to_long(by[::-1]))
    predictor.setrandbits(bytes_to_long(by[::-1]), 32)

for i in res[1:]:
    rem(i)
num=''
_ = [predictor.backtrack_getrandbits(32) for _ in range(625)]


iv=long_to_bytes(rc.predict_getrandbits(128))
key=long_to_bytes(predictor.backtrack_getrandbits(128))[::-1]

cipher = AES.new(key, AES.MODE_CBC, iv)
c=b'\xc0\xcfp\x1d|\xc5\xa4\x9d\x1b\xeam<\xe4\xd4\x87*\xa6\x05\x91#\xd7t\xfb\xef\xce\x0e\xaf\xb4\x16\xf0\x9cd|\x91\xbcO\xe4\xc8u\x94\xd4-\xb6\xae\xa1\xd5\xae\xa0'
print(cipher.decrypt(c))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值