Re: Cross-platform encryption tool?
From: Dave Thompson (david.thompson1_at_worldnet.att.net)
Date: 08/22/05
- Next message: Mxsmanic: "Re: md5 collisions and speeding tickets"
- Previous message: dotnet123: "Re: Hushmail: questionable file"
- In reply to: tomstdenis_at_gmail.com: "Re: Cross-platform encryption tool?"
- Next in thread: tomstdenis_at_gmail.com: "Re: Cross-platform encryption tool?"
- Reply: tomstdenis_at_gmail.com: "Re: Cross-platform encryption tool?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Mon, 22 Aug 2005 04:01:00 GMT
On 15 Aug 2005 18:39:38 -0700, tomstdenis@gmail.com wrote:
<snip>
> If you don't need security I highly recommend this multi-pass XOR
> algorithm
>
> void encrypt(char *data, int len)
> {
> int x;
> x = 0; start1: while ((data[x++] ^= 0x55) && (x < len)) goto start1;
> x ^= len;
>
> // engage second pass
> x = 0; start1: while ((data[x++] ^= 0x11) && (x < len)) goto start1;
> x ^= len;
>
> // finally smear the bits in a third pass
> x = 0; start1: while ((data[x++] ^= 0x44) && (x < len)) goto start1;
> x ^= len;
> }
>
Assuming C (and not some Tom-private language):
Doesn't compile because label is duplicated in function scope. If you
fix that in the apparently intended way, or just change to proper
while loops, doesn't work correctly (for extremely small values of
"work") for data containing byte values 55 or 44 (ASCII 'U' or 'D') or
0 (which can't happen in C strings, but OP didn't say C strings, and
this uses explicit length which usually is done for nonstrings).
Length and index of arbitrary objects/buffers are usually best done in
size_t; int isn't always large enough. And for typical modern
(all-bits) ciphers -- which this arguably isn't -- at least ciphertext
and often plaintext is more appropriately declared as _unsigned_ char
(pointer), although systems where this actually matters are rare.
And if len = 0 may clobber a byte (outside that specification)
although such a call is even less useful than len > 0.
Personally, I think I prefer:
static const int passes = 7; /* "security parameter" */
void encrypt /* or decrypt */ (unsigned char * buf, size_t len)
{
int n = passes * 2; /* DOUBLE specified security */
int seed = (int)time(NULL) ^ getpid();
/* or some similar value for weird(er) systems */
while( n-- ) {
srand(seed);
for( size_t i = 0; i < len; i++ ) buf[i] ^= rand();
}
}
<VBG>
- David.Thompson1 at worldnet.att.net
- Next message: Mxsmanic: "Re: md5 collisions and speeding tickets"
- Previous message: dotnet123: "Re: Hushmail: questionable file"
- In reply to: tomstdenis_at_gmail.com: "Re: Cross-platform encryption tool?"
- Next in thread: tomstdenis_at_gmail.com: "Re: Cross-platform encryption tool?"
- Reply: tomstdenis_at_gmail.com: "Re: Cross-platform encryption tool?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|