Solved

Encrypt string and decrypt string

Posted on 2000-02-21
14
329 Views
Last Modified: 2012-05-04
Hi

i have value in edit box some i want to encrypt, and be able to decypt it again

Esk
0
Comment
Question by:esk
  • 4
  • 2
  • 2
  • +6
14 Comments
 
LVL 2

Accepted Solution

by:
aubs earned 100 total points
ID: 2543116
Why not just add an offset to each character in the edit box:

function encrypt(str: string):String;
var
  i: integer;
begin
  for i:= 1 to length(str) do
    str[i]:= chr(ord(str[i]) + 100);
  result:= str;
end;

function decrypt(str: string):String;
var
  i: integer;
begin
  for i:= 1 to length(str) do
    str[i]:= chr(ord(str[i]) - 100);
  result:= str;
end;

Here's another...

function EnDeCrypt(s:string): String;
                      var
                      i: integer;
                      begin
                        for i:= 1 to length(s) do
                        begin
                          if s[i]< '[' then //must be uppercase
                           s[i]:= chr(155 - ord(s[i]))
                          else
                           s[i]:= chr(219 - ord(s[i]));
                        end;
                        Result:= s;
                      end;

                      It can be used to encrypt and decrypt by simply swapping characters within the alphabet.
                      a to z,
                      b to y,
                      c to x,...
                      l to o,
                      m to n,
                      n to m,
                      o to l, etc. similarly for uppercase A to Z etc


                      155 = ASCII 'A' + ASCII 'Z'
                      219 = ASCII 'a' + ASCII 'z'

Aubs
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2543180
Esk : Have a look at my TEncrypt component...

http://www.freehomepages.com/secretdelphi/

(Suprised you didn't ask me about this in the 1st place!)

John.
0
 
LVL 6

Expert Comment

by:edey
ID: 2543328
Just how secure do want this to be?
Do you have to worry about leaving un-encrypted values in ram/on disk?

GL
Mike
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2543369
0
 
LVL 17

Expert Comment

by:inthe
ID: 2543516
this was posted in another q some time ago. it is similar to aubs first comment :
using a random number up to 26 is used to offset each char. This way the string returned will always be readable, but much harder to decrypt because the offset is different every time.

You may want to alter the seed value, but there is no real advantage to this. MAKE SURE THE SEED IS THE SAME FOR ENCRYPTION AND DECRYTION!

function EncryptPassword(password: string): string;
var
i: integer;
begin
RandSeed:= 9999;
for i:= 1 to length(password) do
password[i]:= chr(ord(password[i]) + random(26));
Result:= Password;
end;

function DecryptPassword(s: string): string;
var
i: integer;
begin
s:='';
RandSeed:= 9999;
for i:= 1 to length(s) do
s[i]:= chr(ord(s[i]) - random(26));
Result:= s;
end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2543908
The 'cryptlib' I mentioned before is not the right one. This one is:

http://www3.ewebcity.com/joep/cryptlib.zip
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2544362
you can also use random chars up to 255 and then pass the number to HEX and to string, that way it's always readable also, but is double lenght than original
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:TheNeil
ID: 2545418
esk,

It all depends what you want to do with the data. If you're going to encrypt the data into a file, and then decrypt it back when you read it out then there are better solutions than aubs. But if you actually want to encrypt the data as the user enters it then the code already supplied will do the job.

Bear in mind that aubs system isn't too complex of difficult to crack. Personally I'd go for a password overlay system. Basically it involves combining characters as ASCII values from a password. The encrypted text changes according to the password. It's not foolproof but is a little more advanced that what you've already been told.

If you want encryption and decryption routines for this then just ask

The Neil
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2546504
you can also use  Microsofts CryptoAPI

http://www.DelphiZine.com/features/1999/02/di199902mb_f/di199902mb_f.asp

Regards, Zif.
0
 

Author Comment

by:esk
ID: 2550651
Jaymol, can you sent me demo at esk10000@hotmail.com

homesite did not work here!!!

Esk
0
 

Author Comment

by:esk
ID: 2550672
aubs, your functions won't work
0
 

Author Comment

by:esk
ID: 2550677
aubs, this works, my compiler was $%/%&
0
 
LVL 2

Expert Comment

by:aubs
ID: 2550804
So does it work or does it not work?

Aubs
0
 

Author Comment

by:esk
ID: 2551835
It works

thanks
Esk
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ddeman not working in activex 3 93
Delphi XE2 application frozen on Windows 10 10 277
When i run adoquery my application freezes 26 150
CheckListBox usage 3 51
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now