Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Stream Cipher

Name: Anonymous 2007-11-21 16:10

Help make this stream cipher better!


#include <stdio.h>
#include <stdlib.h>

#define bit(b,v) ((v&(1<<((b)%32)))>>((b)%32))

int rule[] = { 0, 1, 1, 1, 1, 0, 0, 0 };

int main(int argc, char **argv)
{
    unsigned int c, i, b, nkey, key, len;

    if(argc < 3) exit(1);
    key = atoi(argv[1]);
    len = atoi(argv[2]);

    for(i=0; i<len; i++) {

        c = getchar();
        c ^= key;
        putchar(c);

        for(b=0, nkey=0; b<32; b++)
            nkey |= rule[
                bit(b-1,key) * 4 +
                bit(b  ,key) * 2 +
                bit(b+1,key) * 1 ] << b;
        key = nkey;
    }

    return 0;
}

Name: Anonymous 2007-11-21 17:35

>>7
getchar returns a 32-bit integer.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List