from random import randint
from secret import flag, enc_key
dir="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}"assertlen(flag)==64assertlen(enc_key)==64defgetGraph(row, column):
graph =[[''for _ inrange(row)]for _ inrange(column)]for i inrange(column):for j inrange(row):
graph[i][j]=dir[randint(0,63)]return graph
defbestkasscnEncryption(str):
binary =''
res =''for c instr:
binary +='0'+bin(ord(c))[2:]+''whilelen(binary)%6!=0:
binary +='0'for i inrange(len(binary)//6):
res +=dir[int(binary[i *6:6+ i *6],2)]whilelen(res)%3!=0:
res +='}'return res
encrypt = bestkasscnEncryption(enc_key)
graph1 = getGraph(len(encrypt),len(encrypt))
graph2 = getGraph(len(encrypt),len(encrypt))for i inrange(len(flag)):
graph1[dir.index(encrypt[i])][i]= enc_key[i]
graph2[i][dir.index(encrypt[i])]= flag[i]for i inrange(0,len(flag),2):
graph2[i][dir.index(encrypt[i])]= enc_key[i]
graph1[dir.index(encrypt[i])][i]= flag[i]withopen('graph1.txt','w')asfile:file.write("graph1:\n")for i in graph1:file.write(str(i))file.write(',')file.write('\n')file.close()withopen('graph2.txt','w')asfile:file.write("graph2:\n")for j in graph2:file.write(str(j))file.write(',')file.write('\n')file.close()withopen('encrypt.txt','w')asfile:file.write(encrypt)file.close()
破解:
dir="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}"//检验
defbestkasscnEncryption(str):
binary =''
res =''for c instr:
binary +='0'+bin(ord(c))[2:]+''whilelen(binary)%6!=0:
binary +='0'for i inrange(len(binary)//6):
res +=dir[int(binary[i *6:6+ i *6],2)]whilelen(res)%3!=0:
res +='}'return res
str="One_who_has_seen_the_ocean_thinks_nothing_of_mere_rivers_so_do_I"
res=''
res=bestkasscnEncryption(str)print(res)#encrypt=t25Lx3DOB19OyxnFC2vLBL90AgvFB2nLyw5FDgHPBMTZx25VDgHPBMDFB2zFBwvYzv9YAxzLCNnFC29Fzg9Fsq}
encrypt="t25Lx3DOB19OyxnFC2vLBL90AgvFB2nLyw5FDgHPBMTZx25VDgHPBMDFB2zFBwvYzv9YAxzLCNnFC29Fzg9Fsq}"//运行下面这个循环需要把最后那个}删掉
for i inrange(len(encrypt)):for j inrange(len(dir)):if encrypt[i]==dir[j]:print(bin(j),end=" ")break//把输出结果补齐6位,高位补0,放入cyberchef中from Binary就得到压缩包密码
print("\n")//将文件中二维矩阵放入即可
graph1 =
graph2 =for i inrange(64):if i%2==1:print(graph2[i][dir.index(encrypt[i])], end="")else:print(graph1[dir.index(encrypt[i])][i],end="")print("\n")//根据下面两个可以猜测是交错的,得上面循环
for i inrange(64):print(graph2[i][dir.index(encrypt[i])],end="")print("\n")for i inrange(0,64,2):print(graph1[dir.index(encrypt[i])][i],end="")