[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Can we have a code improvement thread? It was pretty fun yesterday.

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 8
Thread images: 1

File: 1475003003535.jpg (100KB, 900x900px) Image search: [Google]
1475003003535.jpg
100KB, 900x900px
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 archive
void 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
Thread posts: 8
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.