当前位置: 首页 > article >正文

[CTF]-Reverse:Reverse做题笔记

Tea:

[HNCTF 2022 WEEK2]TTTTTTTTTea:

找出关键数据,运行脚本

#include <stdio.h>
int main(){
    unsigned int l,r;
    unsigned int v4[6]={-1054939302,-1532163725,-165900264,853769165,768352038,876839116};
    int flag[6]={0};
    unsigned int delta;
    unsigned int key[4]={0x00010203,0x04050607,0x08090a0b,0x0c0d0e0f};
    int i,j;
    for(i=0;i<6;i+=2){
        l=v4[i];
        r=v4[i+1];
        delta=-32*1640531527;
        for(j=0;j<32;j++){
            r -= (((l >> 5) ^ (l*16)) + l) ^ (key[(delta>>11)&3]+ delta);//*16==<<4 
            delta += 1640531527;
            l -= (((r >> 5) ^ (r*16)) + r) ^ (key[delta&3]+ delta);
        }
        flag[i]=l;
        flag[i+1]=r;
    }
    char *p = (char*)flag;
    for(i=0;i<24;i++){
        printf("%c",*p);
        p++;
    }
}

[MoeCTF 2022]ezTea:

运行脚本

#include <stdio.h>
#include <stdint.h>

void encrypt (uint32_t* v, uint32_t* k) {                       // 主要加密函数,试着搞定它
    uint32_t v0 = v[0], v1 = v[1], sum = 0;
    uint32_t delta = 0xd33b470;
    for (int i = 0; i < 32; i++) {
        sum += delta;
        v0 += ((v1<<4) + k[0]) ^ (v1 + sum) ^ ((v1>>5) + k[1]);
        v1 += ((v0<<4) + k[2]) ^ (v0 + sum) ^ ((v0>>5) + k[3]);
    }
    v[0] = v0;
    v[1] = v1;
}

void decrypt(uint32_t* v, uint32_t* k) {
	uint32_t v0 = v[0], v1 = v[1], sum = 0xd33b470*32, i;
	uint32_t delta = 0xd33b470;
	uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3];
	for (i = 0; i<32; i++) {
		v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
		v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
		sum -= delta;
	}
	v[0] = v0; v[1] = v1;
}

int main() {
    uint32_t k[4] = {1, 2, 3, 4};
    int8_t input[33] = {0x17, 0x65, 0x54, 0x89, 0xed, 0x65, 0x46, 0x32, 0x3d, 0x58, 0xa9, 0xfd, 0xe2, 0x5e,
0x61, 0x97, 0xe4, 0x60, 0xf1, 0x91, 0x73, 0xe9, 0xe9, 0xa2, 0x59, 0xcb, 0x9a, 0x99,
0xec, 0xb1, 0xe1, 0x7d};
    
    //scanf("%32s", input);
    for (int i = 0; i < 32; i+=8) {
        uint32_t v[2] = {*(uint32_t *)&input[i], *(uint32_t *)&input[i+4]};
        decrypt(v, k);
        for (int j = 0; j < 2; j++) {                           // 这一段主要是把 v 按单字节输出,另外可以了解一下 “大小端序” 在这题是如何体现的
            for (int k = 0; k < 4; k++) {
                printf("%c", v[j] & 0xff);
                v[j] >>= 8;
            }
        }
    }
    return 0;
}

[HGAME 2023 week1]a_cup_of_tea:

#include <stdio.h>
#include <string.h>
#include <emmintrin.h>
#include <stdint.h>

void decrypt(unsigned int *v, unsigned int *k) {
	unsigned int v0 = v[0],v1 = v[1];
	int delta = -1412567261;
	int sum =delta*32;
	unsigned int k0 = k[0],k1 = k[1],k2 = k[2],k3 = k[3];
	for (int i = 0; i < 32; i++) {
		v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
		v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
		sum -= delta;
	}
	v[0] = v0;
	v[1] = v1;
}

int __cdecl main() {
	int Buf2[8];
	unsigned int key[] = {0x12345678, 0x23456789, 0x34567890, 0x45678901};
	Buf2[0] = 778273437;
	Buf2[1] = -1051836401;
	Buf2[2] = -1690714183;
	Buf2[3] = 1512016660;
	Buf2[4] = 1636330974;
	Buf2[5] = 1701168847;
	Buf2[6] = -1626976412;
	Buf2[7] = 594166774;
	
	char buf[50] = {0};
	memcpy(buf, Buf2, sizeof Buf2);
	
	for(int i=0;i<=6;i+=2)
	{
		decrypt((unsigned int *)&buf+i, key);
	}
	
	printf("%s", buf);
	
	return 0;
}


http://www.kler.cn/a/283425.html

相关文章:

  • webpack loader全解析,从入门到精通(10)
  • 金价大跌,特朗普胜选或成导火索
  • 【2024最新】math-expression-evaluator 动态计算表达式的使用
  • 智享AI 无人自动直播的崛起 ,引领智能互动与自动带货新潮流!
  • 【C++】 list 与 string 基础与实现字符串操作
  • 【信号处理】基于联合图像表示的深度学习卷积神经网络
  • defineProps、defineEmits、 defineExpose的TS写法
  • python os获取当前git目录的git用户
  • python------python解释器,pycharm下载配置
  • jmespath用法总结
  • 如何用GPT进行编程辅助?
  • MM 2024 Oral: 大模型带你鉴赏世界名画!同济大学发布
  • 202408830配置WIN11自带的画图程序的画布为4K分辨率
  • 探索 HarmonyOS 中的高级文本自定义
  • Python自动化测试requests库深度详解
  • 实战OpenCV之绘制图形
  • [000-01-015].第03节:SpringBoot中数据源的自动配置
  • 项目环境依赖库导出-python
  • 【Docker】搭建docker的私有仓库
  • centos yum 源停用整改
  • 获取服务器时间
  • 【jvm】局部变量表
  • 轻量级冠军:NVIDIA 发布具有领先准确率的小语言模型
  • Java Excel转PDF(免费)
  • 替换后的最长重复字符(LeetCode)
  • 网络编程(1)