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

Pages: 1-

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 16:13

No curly braces make expert programmers cry

Name: Anonymous 2007-11-21 16:25

somehow, this looks like shenanigans, or some sort of espionage.

Name: Anonymous 2007-11-21 16:41

somehow, this looks like shemales, or some sort of ESPage.

Name: Anonymous 2007-11-21 16:57

It's a stream cipher, and you must specify a length in advance? What the bloody fuck? How about running until a EOF or something sensible instead?

Replace:

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

with:

while((c = getchar()) != EOF)

and trash i and len, you don't fucking need them in a stream  cipher.

Name: Anonymous 2007-11-21 16:59

>>5
Use lazy evaluation or GTFO ^________^;;

Name: Anonymous 2007-11-21 17:05

>>5

Actually, that won't work because the ciphertext could
contain any values, including EOF.

Name: Anonymous 2007-11-21 17:35

>>7
getchar returns a 32-bit integer.

Name: Anonymous 2007-11-21 19:19

>>7

quoting gets man page

---------------
fgetc()  reads  the  next  character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error.

getc() is equivalent to fgetc() except that it may be implemented as a macro  which evaluates stream more than once.

getchar() is equivalent to getc(stdin).
---------------

You don't get an EOF unless the stream reaches EOF or errors. The cast to int allows for values outside of 0-255. EOF happens to be value -1 in my libc.

Fail less.

Name: Anonymous 2007-11-21 22:24

Rule 30 cellular automata are only a reasonable choice if their space is unrestricted. By confining them in cyclical space you can reverse them if you get the state somewhere (see http://www.mathpages.com/home/kmath439/kmath439.htm ). Even more seriously, you can get the complete state by a known plaintext attack. Of course you get 8 bits for one known byte, but you can get on average 1.5 bits more for every consecutive byte:

xabcdefghy
.ijklmnop.


You can compute x from the following equation:
i = x^(a|b)
x = i^(a|b)

y can be computed iff h = 0:
p = g^(h|y)
p = g^y
y = p^g

For your 32 bits it would take on average 17 known bytes to fully crack it. Of course 32 bits are way too few to stop someone from bruteforcing it.

Name: Anonymous 2007-11-22 6:13

>>7
EOF is not a character
>>8
No, it returns an int. an int may be 16 or more bits in size.
>>9
The cast to int allows for values outside of 0-255.
There's no cast being done to 'int'.
It simply returns int.
If you really want it to be portable to ANY system you have to do:

for(clearerr(stream); (c = fgetc(stream)) != EOF && (ferror(stream) || feof(stream)));)


fuck you niggers

Name: Anonymous 2007-11-22 6:14

>>11
also, unmatching paren lol

Name: Anonymous 2007-11-22 8:30

>>11
I think he's talking about that happens inside fgetc on his system

Name: Anonymous 2007-11-22 8:30

It was a reply to ``There's no cast being done to 'int'.''

Name: Anonymous 2007-11-22 9:04

>>7
Hahaha oh wow, WTF

>>11 knows C

Name: Anonymous 2009-07-12 5:53

}else  {  { neat neat with they better! in most languages to languages for 0-255. There's to being result. have -e I have

Name: Anonymous 2010-11-14 22:52

Name: Anonymous 2011-02-03 1:05


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