RC4 - 绿城杯easy_re
//https://blog.csdn.net/qq_38130747/article/details/88602061
#include "stdio.h"
int main(int argc, char *argv[], char **env) {
int b[256] = {0};
int s[256] = {0};
char key[10] = "tallmewhy";
char flag[42] = {0xF5, 0x8C, 0x8D, 0xE4, 0x9F, 0xA5, 0x28, 0x65, 0x30, 0xF4, 0xEB, 0xD3, 0x24, 0xA9, 0x91, 0x1A,
0x6F, 0xD4, 0x6A, 0xD7, 0x0B, 0x8D, 0xE8, 0xB8, 0x83, 0x4A, 0x5A, 0x6E, 0xBE, 0xCB, 0xF4, 0x4B,
0x99, 0xD6, 0xE6, 0x54, 0x7A, 0x4F, 0x50, 0x14, 0xE5, 0xEC};
int i, j, n, w, t;
int v9 = 0;
int v8 = 0;
for (int i = 0; i < 256; ++i) {
b[i] = key[i % 9]; // %9是 tellmewhy 的长度
s[i] = i;
}
for (i = 0; i < 256; ++i) {
v9 = s[i];
v8 = (v8 + b[i] + v9) % 256;
s[i] = s[v8];
s[v8] = v9 ^ 0x37; // 多了个步骤
}
for (w = 0, v8 = 0, i = 0; w < 42; w++) {
i = (i + 1) % 256;
v8 = (v8 + s[i]) % 256;
v9 = s[i];
s[i] = s[v8];
s[v8] = v9;
t = (s[i] + s[v8]) % 256;
flag[i - 1] ^= s[t]; // s[t]是最后的密钥
}
for (i = 0; i < 42; ++i) {
putchar(flag[i]);
}
return 0;
}