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

Talk:MNG files

From Creatures Wiki
Revision as of 00:56, 8 February 2005 by Dylan (talk)
Jump to navigation Jump to search

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)