|
-
January 20th, 2009, 04:03 AM
#1
Adequate encryption?
Hi
I would like to be able to encrypt a double precision number and then save it to a binary file. Does anyone know whether or not it is secure to encrypt individual numbers? I'm guessing it is far more safer to encrypt a larger block of data.
Cheers
Robbie
-
January 20th, 2009, 04:36 AM
#2
Re: Adequate encryption?
Of course. It doesn't make sense to encrypt a single number. If you want to do something at "number" level, mingle the bits. For instance switch bit 34 with 6, 8 with 9, 9 with 10, 10 with 1, XOR bits 45, 21 and 51, etc.
-
January 20th, 2009, 02:19 PM
#3
Re: Adequate encryption?
That's also why most encryption algorithms use blocks of data. When a block is not filled they often require you to pad the data with some padding byte to ensure 1 block.
-
January 20th, 2009, 03:21 PM
#4
Re: Adequate encryption?
It all depends on what you are trying to accomplish. A stream cypher like RC4 would work but might be overkill. A simple XOR with a static password might be sufficient. 8 chars is 64 bits. memcpy or cast your double to char and XOR character-wise:
Code:
double d=3.14159265;
unsigned char *p,pw[]="abcdefgh";
p=(unsigned char *)&d;
for(int i=0;i<8;i++){
p[i]^=pw[i];
}
To decrypt, just run it through again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|