Re: text encryption

Posted by Annie on February 02, 2005


In Reply to: text encryption posted by tris on February 01, 2005

: the voters id gets saved into a
: seperate text file to the vote text file. i am trying to make
: it secure so if anyone looks at this voted.txt they will not
: see the names of the people who voted. and hence i want to
: encrypt the names (and decrypt to check they havent voted twice).

The easiest but weakest encryption is: add a fixed number to the code of each character.

Encryption:

for i := 1 to Length(S) do
   S[i] := Char(Ord(S[i] + 8); 

Decryption:

for i := 1 to Length(S) do
  S[i] := Char(Ord(S[i] - 8); 

If you have to encrypt short strings like names, this is maybe enough. A bit safer: add or subtract different numbers, depending form the place of the character in the string.

In both cases, make sure that an encrypted character code doesn't exceed 255. Look up in an ASCII table: the code for the highest character that you expect, subtract this from 255, and that's your maximum number that can be added.

Succes!
Annie


Delphi Tutorials -- by DelphiLand