第一话:起源
首先啊,打了强网杯,关于强网杯还是要狠狠的吐槽一下的.难难难,只能说难啊
那么接下来的这里是解出来的butterfly,本来之前就想吐槽出题人来着,结果拖到现在了.
1 | |
可以看出来这里主要就是使用了MMXEncode来加密了文件.只需要把密钥放进去,密文最后就后就输出了.
解密脚本
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
int decrypt_file(const char* encrypted_file, const char* key_file, const char* output_file) {
FILE* f_enc = fopen(encrypted_file, "rb");
FILE* f_key = fopen(key_file, "rb");
if (!f_key) {
printf("错误:无法打开密钥文件 %s\n", key_file);
fclose(f_enc);
return 1;
}
FILE* f_out = fopen(output_file, "wb");
uint8_t key_buffer[32];
fclose(f_key);
uint64_t key = 0;
for (int i = 0; i < 8; i++) {
key |= ((uint64_t)key_buffer[i]) << (i * 8);
}
fseek(f_enc, 0, SEEK_END);
long file_size = ftell(f_enc);
fseek(f_enc, 0, SEEK_SET);
uint8_t* encrypted_data = (uint8_t*)malloc(file_size);
if (!encrypted_data) {
printf("错误:内存分配失败\n");
fclose(f_enc);
fclose(f_out);
return 1;
}
fclose(f_enc);
memcpy(decrypted_data, encrypted_data, file_size);
for (long i = 0; i <= file_size - 8; i += 8) {
uint64_t* block = (uint64_t*)(decrypted_data + i);
uint64_t encrypted = *block;
uint64_t temp = encrypted;
for (int j = 0; j < 8; j++) {
uint8_t* byte_ptr = (uint8_t*)&temp + j;
uint8_t key_byte = (key >> (j * 8)) & 0xFF;
*byte_ptr = (*byte_ptr - key_byte) & 0xFF;
}
temp = (temp >> 1) | (temp << 63);
uint64_t swapped = 0;
for (int j = 0; j < 4; j++) {
uint16_t word = (temp >> (j * 16)) & 0xFFFF;
word = ((word & 0xFF) << 8) | ((word & 0xFF00) >> 8);
swapped |= (uint64_t)word << (j * 16);
}
temp = swapped;
temp = temp ^ key;
*block = temp;
}
fclose(f_out);
free(encrypted_data);
free(decrypted_data);
return 0;
}
int main() {
int result = decrypt_file("encode.dat", "encode.dat.key", "decoded.txt");
if (result == 0) {
printf("\n解密完成!请检查 decoded.txt 文件。\n");
} else {
printf("\n解密失败!\n");
}
return result;
}
第一话:起源
https://boke-git-main-huang-chaos-projects.vercel.app/2025/10/17/第一话-起源/