Re: Help: Randomizing a List of Numbers
From: Tom St Denis (tomstdenis_at_iahu.ca)
Date: 07/21/04
- Next message: Scott Wilber: "Re: "All random number generators eventually exhibit periodicity"?????"
- Previous message: Bill Emerson: "Re: Help: Randomizing a List of Numbers"
- In reply to: Bill Emerson: "Re: Help: Randomizing a List of Numbers"
- Next in thread: Bill Emerson: "Re: Help: Randomizing a List of Numbers"
- Reply: Bill Emerson: "Re: Help: Randomizing a List of Numbers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 21 Jul 2004 19:52:50 GMT
Bill Emerson wrote:
> In sci.crypt, Tom St Denis wrote:
>> Bill Emerson wrote:
>>> Thank you very much, Tim. That looks like a variation of the Fisher
>>> Yates Shuffle, which I found in every language under the sun except C.
>>
>> Now some fun... Tim's shuffle Tom style
>>
>> void shuffle(
>> int N,int A[])
>> {for
>> (int
>> i=N-
>> 1;i>
>> 0;
>> --i )
>>
>> {int
>> k=rn
>> (i);
>> int tmp=A[i];
>> A[i]=A[k];A[k]
>>=tmp
>> ;}}
>>
>>
>> See the two rotated T's ;-)
>>
>> Ok lame... at least this compiles.... muahahaha
>>
>> Tom
>
> Not lame at all. Not from here.
>
> Tell me, Tom, how do I XOR a string of bytes with a random string
> of bits in C? Say I have a message with 100 words/4000 bytes. I have
> the output on /dev/random that I can first convert to ascii and put
> in a text file. Or is that right?
>
> Pretty please? :-\ I'm looking at Section 2.9 in K&R but haven't
> got it yet.
Read about the fact that "char"s are integer types ;-)
int a = '5';
char b = '5';
Store the same number in a and b.
So you can just read a character (say with fgetc) from your pad (/dev/random
I guess? but you still have to store that somewhere!) and xor it against a
byte you read from your plaintext...
^ is the XOR operator in C.
quickref/crashcourse...
XOR ^
OR |
AND &
Logical OR ||
Logical AND &&
Logical operators are for testing statements e.g. && would be for "this AND
this must be true". The single operators e.g. & are for bitwise operations
e.g.
int a = 0xFF;
int b = 0x1F0;
b = b & a; // b now equals 0xF0
&& are short cutted too for instance
if (0 && somefunc()) { printf("hello"); }
the function somefunc() will never get called. Increments ++ and --, e.g.
a++ and --b. If they appear before they are "pre-" ops otherwise they are
post ops. E.g
int a,b;
a = 4;
b = a++; // stores 4 in b, a now equals 5
b = --a; // stores 4 in b, a now equals 4
b = ++a; // stores 5 in b, a now equals 5
You can also shorthand assignments operations... e.g
a = a + 4;
a += 4; // these two are the same
;-)
Muahahahah
- Next message: Scott Wilber: "Re: "All random number generators eventually exhibit periodicity"?????"
- Previous message: Bill Emerson: "Re: Help: Randomizing a List of Numbers"
- In reply to: Bill Emerson: "Re: Help: Randomizing a List of Numbers"
- Next in thread: Bill Emerson: "Re: Help: Randomizing a List of Numbers"
- Reply: Bill Emerson: "Re: Help: Randomizing a List of Numbers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|