1. 介绍 2. 数据解密
使用C语言算法实现一个简单的RC4加解密
#include "RC4.h" #include <malloc.h> static char IS_INIT = 0; static unsigned char *temp = NULL, *output = NULL, *key = NULL, *sbox = NULL; void initializationRC4(int srcSize, int pwdSize) { if (srcSize == 0 || pwdSize == 0) return; temp = (char *)malloc(128 * sizeof(char)); key = (char *)malloc(256 * sizeof(char)); sbox = (char *)malloc(256 * sizeof(char)); output = (char *)malloc(srcSize * sizeof(char)); IS_INIT = 1; } void freeRC4Source() { if (IS_INIT == 0) return; free(key);key = NULL; free(sbox);sbox = NULL; free(temp);temp = NULL; free(output);output = NULL; IS_INIT = 0; } char *getOutputStreamPointer() { return output; } char *RC4_Encrypt(char *src, short srcSize, char *passwd, short pwdSize) { if (IS_INIT == 0) initializationRC4(srcSize, pwdSize); // generate key box for (int i = 0; i < 256; i++) { key[i] = (int)passwd[i % pwdSize]; sbox[i] = i; } int j = 0; for (int i = 0; i < 256; i++) { j = (j + sbox[i] + key[i]) % 256; _itoa(sbox[i], temp, 10); sbox[i] = sbox[j]; sbox[j] = atoi(temp); } int a = 0, b = 0, c = 0; for (int i = 0; i < srcSize; i++) { a = (a + 1) % 256; b = (b + sbox[a]) % 256; _itoa(sbox[a], temp, 10); sbox[a] = sbox[b]; sbox[b] = atoi(temp); c = (sbox[a] + sbox[b]) % 256; output[i] = src[i] ^ sbox[c]; } return output; } 3. 工具编译 rc4launch 用法 ./rc4launch -[参数] src pwd参数为 十六进制(x) 和 字符串(s)
e.g.
./rc4launch -sx hello rc4 # 输入值为字符串,输出为16进制 ./rc4launch -ss hello rc4 # 输入值为字符串,输出为字符串 #...pwd即是密码但被加密了,auth_tag是请求的时间戳也即是密钥

f20bbe5dfff02a21d3a8e0bc744dff3.png (18.07 KB, 下载次数: 8)
下载附件
2023-3-15 18:37 上传

f0b803f54bb261cc73f113c1e385326.png (22.84 KB, 下载次数: 2)
下载附件
2023-3-15 18:37 上传
4. 项目代码RC4算法实现
程序启动器

2023-3-15 18:29 上传
点击文件名下载附件























查看全部评分