如下的代码进行了一个简单的加密过程
#include<stdio.h> #include<string.h> int main() { int i; int len; char key[20]; char res[20]; char *num = "eastmount"; //密钥 char *right = "123456789"; //正确值 //请输入正确的密码 printf("please input the key:"); scanf("%s", &key); //判断 len = strlen(key); if(len<6 || len>10) { printf("Error, The length of the key is 6~10\n"); } else { //加密 for(i=0; i<len; i++) { res[i] = (key[i]^num[i]); //异或加密 } //printf("%s\n", res); if(strcmp(res, right)==0) { printf("You are right, Success.\n"); } else { printf("Error, please input the right key.\n"); } } return 0; }
IDA反汇编后得到代码如下
分析一下这个代码的意思,就是说定义了两个数组str1[]和str[],以及两个变量,v6和i,程序开始运行时首先需要输入密钥赋值给str[],讲str【】的长度赋值给v6,如果v6的长度在6-10之间继续下去,不是的话报错,将gcc2_compiled_【i】和str【i】异或的结果赋值给str1[i],如果这个结果是123456789,那么登录成功。
所以我们要搞清楚这个gcc2_compiled_的值,如下图,值为:eastmount
现在整理一下思路,就是a^b=c 已知a和c,求b。这个时候需要写一下脚本。
#include<stdio.h> int main(){ char a[] = "eastmountl"; char c[] = "123456789"; int i = 0; char b[9]; for(i = 0;i < 9;i++){ b[i] = (a[i]^c[i]); } b[i] = 0; printf("the key:%s",b); return 0; }
得到结果
我们验证一下
那么这样一个简单的解密就完成了,希望大家可以有所收获哦!