Welcome to the Creatures Wiki! Log in and join the community.

Difference between revisions of "Talk:MNG files"

From Creatures Wiki
Jump to navigation Jump to search
Line 26: Line 26:
  
 
Does that code look alright? [[User:Dylan|Dylan]] 16:55, 7 Feb 2005 (PST)
 
Does that code look alright? [[User:Dylan|Dylan]] 16:55, 7 Feb 2005 (PST)
 +
 +
Since you're not using const, why not do it in-place? [[User:Bdonlan|bd_]] 18:48, 7 Feb 2005 (PST)
 +
<pre>
 +
#include <stdlib.h>
 +
#include <stdint.h>
 +
 +
uint8_t *scramble(uint8_t *data, uint32_t length)
 +
{
 +
    uint8_t hb  = 0x5;
 +
    uint8_t i;
 +
 +
 +
    for (i = 0; i < length; i++) {
 +
        data[i] ^= hb;
 +
        if (hb < 0x3F)
 +
            hb += 0xC1;
 +
        else
 +
            hb += (0xC1 - 0x100);
 +
    }
 +
   
 +
    return out;
 +
}
 +
</pre>

Revision as of 02:48, 8 February 2005

Since we have a VB and assembler example, why not a C example? C is very popular, and all.

#include <stdlib.h>
#include <stdint.h>

uint8_t *scramble(uint8_t *data, uint32_t length)
{
    uint8_t hb  = 0x5;
    uint8_t *out = (uint8_t *) malloc(sizeof(uint8_t) * length);
    uint8_t i;


    for (i = 0; i < length; i++) {
        out[i] = data[i] ^ hb;
        if (hb < 0x3F)
            hb += 0xC1;
        else
            hb += (0xC1 - 0x100);
    }
    
    return out;
}

Does that code look alright? Dylan 16:55, 7 Feb 2005 (PST)

Since you're not using const, why not do it in-place? bd_ 18:48, 7 Feb 2005 (PST)

#include <stdlib.h>
#include <stdint.h>

uint8_t *scramble(uint8_t *data, uint32_t length)
{
    uint8_t hb  = 0x5;
    uint8_t i;


    for (i = 0; i < length; i++) {
        data[i] ^= hb;
        if (hb < 0x3F)
            hb += 0xC1;
        else
            hb += (0xC1 - 0x100);
    }
    
    return out;
}