1
我想通過RC4的蠻力數組值來查找RC4的內部狀態,但我不知道如何強行使用它。如何蠻力在RC4上查找內部狀態?
#include <stdio.h>
#include <string.h>
typedef unsigned long ULONG;
void rc4_init(unsigned char *s, unsigned char *key, unsigned long Len)
{
int i = 0, j = 0;
char k[256] = { 0 };
unsigned char tmp = 0;
for (i = 0; i<256; i++) {
s[i] = i;
k[i] = key[i%Len];
}
for (i = 0; i<256; i++) {
j = (j + s[i] + k[i]) % 256;
tmp = s[i];
s[i] = s[j];
s[j] = tmp;
}
}
void rc4_crypt(unsigned char *s, unsigned char *Data, unsigned long Len)
{
int i = 0, j = 0, t = 0;
unsigned long k = 0;
unsigned char tmp;
for (k = 0; k<Len; k++) {
i = (i + 1) % 256;
j = (j + s[i]) % 256;
tmp = s[i];
s[i] = s[j];
s[j] = tmp;
t = (s[i] + s[j]) % 256;
Data[k] ^= s[t];
printf("%d\n ", Data[k] ^= s[t]); //May be I have to brute force here
}
}
int main()
{
unsigned char s[256] = { 0 }; //S-box
char key[256] = { "12345678" };
char pData[512] = "testRC4";
ULONG len = strlen(pData);
printf("key : %s\n", key);
printf("raw : %s\n", pData);
rc4_init(s, (unsigned char *)key, strlen(key));
rc4_crypt(s, (unsigned char *)pData, len);
printf("encrypt : %s\n", pData);
rc4_init(s, (unsigned char *)key, strlen(key));
rc4_crypt(s, (unsigned char *)pData, len);
printf("decrypt : %s\n", pData);
getchar();
return 0;
}
在行printf(「%d \ n」,Data [k]^= s [t]);顯示這樣的價值。
116,101,115,116,82,67,52
我不知道我有蠻力這個值還是什麼線我不得不修改爲發現內部蠻力RC4的狀態。請幫幫我。
'數據[K]^= S [噸]; printf(「%d \ n」,Data [k]^= s [t]);'打印'Data [k]'並且不修改它。你想要做什麼? – MikeCAT