BUUCTF-MISC-[QCTF2024]picture_elephantut ctf cloacked

文章介绍了使用Python实现的DES解密脚本,并提到一套完整的网络安全学习资料,包括基础知识、进阶课程和实战项目,适合不同水平的学习者。
摘要由CSDN通过智能技术生成
[[4, 11,  2, 14, 15,  0,  8, 13,  3, 12,  9,  7,  5, 10,  6,  1],     
 [13,  0, 11,  7,  4,  9,  1, 10, 14,  3,  5, 12,  2, 15,  8,  6],     
 [1,  4, 11, 13, 12,  3,  7, 14, 10, 15,  6,  8,  0,  5,  9,  2],     
 [6, 11, 13,  8,  1,  4, 10,  7,  9,  5,  0, 15, 14,  2,  3, 12]],

[[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
[1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
[7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
[2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]]]

pc1=(57, 49, 41, 33, 25, 17, 9,
1, 58, 50, 42, 34, 26, 18,
10, 2, 59, 51, 43, 35, 27,
19, 11, 3, 60, 52, 44, 36,
63, 55, 47, 39, 31, 23, 15,
7, 62, 54, 46, 38, 30, 22,
14, 6, 61, 53, 45, 37, 29,
21, 13, 5, 28, 20, 12, 4)

pc2= (14, 17, 11, 24, 1, 5, 3, 28,
15, 6, 21, 10, 23, 19, 12, 4,
26, 8, 16, 7, 27, 20, 13, 2,
41, 52, 31, 37, 47, 55, 30, 40,
51, 45, 33, 48, 44, 49, 39, 56,
34, 53, 46, 42, 50, 36, 29, 32)

d = (1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1)

all=[‘desencode’]
class DES():

def __init__(self):
	pass

def code(self,from_code,key,code_len,key_len):
	output=""
	trun_len=0
	
	code_string=self._functionCharToA(from_code,code_len)
	code_key=self._functionCharToA(key,key_len)
	
	if code_len%16!=0:
		real_len=(code_len/16)*16+16
	else:
		real_len=code_len
	
	if key_len%16!=0:
		key_len=(key_len/16)*16+16
	key_len*=4

	trun_len=4*real_len

	for i in range(0,trun_len,64):
		run_code=code_string[i:i+64]
		l=i%key_len
		run_key=code_key[l:l+64]

		run_code= self._codefirstchange(run_code)
		run_key= self._keyfirstchange(run_key)
		
		for j in range(16):
			
			code_r=run_code[32:64]
			code_l=run_code[0:32]
				
			run_code=code_r
			
			code_r= self._functionE(code_r)
			
			key_l=run_key[0:28]
			key_r=run_key[28:56]
			key_l=key_l[d[j]:28]+key_l[0:d[j]]
			key_r=key_r[d[j]:28]+key_r[0:d[j]]
			run_key=key_l+key_r
			key_y= self._functionKeySecondChange(run_key)

			code_r= self._codeyihuo(code_r,key_y)

			code_r= self._functionS(code_r)
			
			code_r= self._functionP(code_r)
			
			code_r= self._codeyihuo(code_l,code_r)
			run_code+=code_r

		code_r=run_code[32:64]
		code_l=run_code[0:32]
		run_code=code_r+code_l
		

		output+=self._functionCodeChange(run_code)
	return output

def _codeyihuo(self,code,key):
	code_len=len(key)
	return_list=''
	for i in range(code_len):
		if code[i]==key[i]:
			return_list+='0'
		else:
			return_list+='1'
	return return_list
 		 							
def _codefirstchange(self,code):
	changed_code=''
	for i in range(64):
		changed_code+=code[ip[i]-1]
	return changed_code

def _keyfirstchange (self,key):
	changed_key=''
	for i in range(56):
		changed_key+=key[pc1[i]-1]
	return changed_key


def _functionCodeChange(self, code):
	lens=len(code)/4
	return_list=''
	for i in range(lens):
		list=''
		for j in range(4):
			list+=code[ip_1[i*4+j]-1]
		return_list+="%x" %int(list,2)
	return return_list

def _functionE(self,code):
	return_list=''
	for i in range(48):
		return_list+=code[e[i]-1]
	return return_list		

def _functionP(self,code):
	return_list=''
	for i in range(32):
		return_list+=code[p[i]-1]
	return return_list

def _functionS(self, key):
	return_list=''
	for i in range(8):
		row=int( str(key[i*6])+str(key[i*6+5]),2)
		raw=int(str( key[i*6+1])+str(key[i*6+2])+str(key[i*6+3])+str(key[i*6+4]),2)
		return_list+=self._functionTos(s[i][row][raw],4)

	return return_list
	
def _functionKeySecondChange(self,key):
	return_list=''
	for i in range(48):
		return_list+=key[pc2[i]-1]
	return return_list

def _functionCharToA(self,code,lens):
	return_code=''
	lens=lens%16
	for key in code:
		code_ord=int(key,16)
		return_code+=self._functionTos(code_ord,4)		
	if lens!=0:
		return_code+='0'*(16-lens)*4
	return return_code

def _functionTos(self,o,lens):
	return_code=''
	for i in range(lens):
		return_code=str(o>>i &1)+return_code
	return return_code

def tohex(string):
return_string=‘’
for i in string:
return_string+=“%02x”%ord(i)
return return_string

def tounicode(string):
return_string=‘’
string_len=len(string)
for i in range(0,string_len,2):
return_string+=chr(int(string[i:i+2],16))
return return_string

def desencode(from_code,key):
from_code=tohex(from_code)
key=tohex(key)

des=DES()
key_len=len(key)
string_len=len(from_code)		
	
if string_len<1 or key_len<1:
	print 'error input'
	return False
key_code= des.code(from_code,key,string_len,key_len)
return key_code

if name == ‘main’:
if(desencode(sys.argv[1],‘mtqVwD4JNRjw3bkT9sQ0RYcZaKShU4sf’)==‘e3fab29a43a70ca72162a132df6ab532535278834e11e6706c61a1a7cefc402c8ecaf601d00eee72’):
print ‘correct.’
else:
print ‘try again.’


发现是DES解密脚本


运行后结果为:


**先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7**

**深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**

**因此收集整理了一份《2024年最新网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。**
![img](https://img-blog.csdnimg.cn/img_convert/6dd9ce2f2908d1540191675f85297b01.png)
![img](https://img-blog.csdnimg.cn/img_convert/8c97a7a53952d7989e730f2ddeeb57e9.png)
![img](https://img-blog.csdnimg.cn/img_convert/bab8b67b146a4d27a661ff4495a1a864.png)
![img](https://img-blog.csdnimg.cn/img_convert/1a2f379cfb6dc54f4bd3e5dfbd8cc4af.png)
![img](https://img-blog.csdnimg.cn/img_convert/83c2a9415290b552a67af5728e5571e5.png)
![img](https://img-blog.csdnimg.cn/img_convert/dde7f102229535e5cec58dc6dd8d08b3.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上网络安全知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以点击这里获取](https://bbs.csdn.net/topics/618540462)**
714116785471)]

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上网络安全知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以点击这里获取](https://bbs.csdn.net/topics/618540462)**
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值