formadmirer
asked on
VFP Encrypt Decrypt
Hi all. I was trying to find a simple way to encrypt/decrypt text and came across the following on a website:
The problem is it throws an error here:
cVal = cVal + CHR(ASC(SUBS(val1,i,1))+va l2)
in the Encrypt.
I would imagine it will as well in the decrypt although I haven't tried it yet.
I was wondering if anyone can see what the problem is, or, perhaps know of a simple text encrypt/decrypt alternative. Thanks!
* usage to encrypt: enCrypt ( text/variable/fields, number used in deCrypt )
* usage to decrypt: deCrypt ( text/variable/fields, any number number )
mytext = "I love Lucy"
enc_number = 394820348
decTxt = enCrypt( mytext, enc_number)
encTxt = decCrypt( decTxt, enc_number)
WAIT WINDOW "Your Text: " + mytext
WAIT WINDOW "Your Encrypted Text: " + encTxt
WAIT WINDOW "Your Decrypted Text: " + decTxt
FUNCTION enCrypt
PARAMETER val1, val2
cVal = ""
FOR i = 1 to Len(val1)
cVal = cVal + CHR(ASC(SUBS(val1,i,1))+val2)
NEXT i
reTurn LEFT(cVal,Len(val1))
FUNCTION decCrypt
PARAMETER val1, val2
cVal = ""
FOR i = 1 to Len(val1)
cVal = cVal + CHR(ASC(SUBS(val1,i,1))-val2)
NEXT i
reTurn LEFT(cVal,Len(val1))
The problem is it throws an error here:
cVal = cVal + CHR(ASC(SUBS(val1,i,1))+va
in the Encrypt.
I would imagine it will as well in the decrypt although I haven't tried it yet.
I was wondering if anyone can see what the problem is, or, perhaps know of a simple text encrypt/decrypt alternative. Thanks!
It is because the CHR function does not accept values more than 255.
This kind of encryption is weak because it increases the CHR by a constant. The first attempt would be to reverse it in a loop to get that constant.
I would suggest to take the nth character of the password and add it to the nth character of the string.
CHR(MOD(ASC(SUBSTR(cString ,n,1))+ASC (SUBSTR(cP assword,n, 1)),256))
You need the MOD 256 because the remainder is not more than 255.
This kind of encryption is weak because it increases the CHR by a constant. The first attempt would be to reverse it in a loop to get that constant.
I would suggest to take the nth character of the password and add it to the nth character of the string.
CHR(MOD(ASC(SUBSTR(cString
You need the MOD 256 because the remainder is not more than 255.
Makes me wonder where you look around. Take VFPEncryption.fll or even look into the samples of VFP, you find samples using windows (strong!) cryptogrphic functions.
Bye, Olaf.
Bye, Olaf.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
An answer to your second question: You have to add cipher50.fll into the project. More info: http://www.foxite.com/archives/cipher50fll-0000326377.htm
I would also recommend VFPencryption.FLL as suggested by Olaf.
I would also recommend VFPencryption.FLL as suggested by Olaf.
ASKER
This worked perfectly for my needs. Thank you so much!
ASKER
Open in new window
The problem is on compile FP throws an error 'Unable to find unknown Encrypt'
The cipher50.fll is in the location specified by Set Library so I'm not sure what the problem is.
Still looking for a simple encrypt/decrypt solution...