Can we have a code improvement thread? It was pretty fun yesterday.
Post code you want to see /g/ try to improve, or try improving some code yourself.
Starting off with this taken from a thread yesterday, anons managed to get it down from 18 lines to 8 in the end (and made it much clearer to read too), can anyone do better though?void Rc4Ecb(RC4_STATE* rc4_state, void* inp, uint32_t inp_size) {
for (uint32_t i = 0; i < inp_size; i++) {
rc4_state->i++;
rc4_state->i &= 0xFF;
int r8 = rc4_state->S[rc4_state->i];
rc4_state->j += r8;
rc4_state->j &= 0xFF;
int r9 = rc4_state->S[rc4_state->j];
rc4_state->S[rc4_state->i] = (uint8_t)r9;
rc4_state->S[rc4_state->j] = (uint8_t)r8;
r8 += r9;
r8 &= 0xFF;
r8 = rc4_state->S[r8];
r9 = inp[i];
r8 ^= r9;
inp[i] = (uint8_t)r8;
}
}
Bump for interest
>much clearer
>function name seems to be just a random string
remote control? radio control? rancid carcass? rich cunt?
>no comments
>variable names are just r[number]
>not even returning anything so no hint there
>>57157212
that's not how outsourcing works
>>57157212
Are this threads the new "make my homework" threads?
>>57158635
>>57158765
If you read the OP properly I already said the code was improved yesterday, I just wanted to see if any other anons had a different take on it, or if any anons had any code they wanted /g/ to look at (maybe you're all sad cunts who just post "le witty homework remark" but some of us can actually enjoy coding)
https://archive.rebeccablacktech.com/g/?task=search&ghost=&search_text=RC4_STATE for proof, it's not a homework request, I was just trying to do something fun with /g/ for a change.
>>57158234
>much clearer
I was talking about the improved version, not the original one I posted
>function name seems to be just a random string
Eh, more like RC4 in ECB mode (aka Rc4Ecb)
>no comments
>variable names are just r[number]
>not even returning anything so no hint there
Well yeah, that's the point of this thread, to improve pieces of code.
>>57158948
I should also post the improved code for reference I guess, since I don't think it's showing in that archivevoid Rc4Ecb(RC4_STATE* rc4_state, void* inp, uint32_t inp_size) {
for (uint32_t idx = 0; idx < inp_size; idx++) {
uint8_t i = rc4_state->S[rc4_state->i += 1];
rc4_state->S[rc4_state->i] = rc4_state->S[rc4_state->j += i];
rc4_state->S[rc4_state->j] = i;
inp[idx] = (uint8_t)(rc4_state->S[(rc4_state->S[rc4_state->j] + rc4_state->S[rc4_state->i]) & 0xFF] ^ inp[idx]);
}
}
Again though, I was mostly hoping to maybe see if anyone else had a different take on improving it, or if they had some code they wanted /g/ to look into
>>57158234
>he's never heard of RC4
>he hasn't forged his own CipherSaber