![]() |
|
#1
|
|||
|
|||
![]()
Hi,
I have a Encryption and Decryption method. But the decryption method is not working for special characters like @, $ and #. Could you please suggest the changes so that it would work for @, $ and #. Below is the encryption/decryption routine. function nValEncrypt(xVal, j: Integer) : Integer; begin RESULT := xVal; if RESULT > 90 then RESULT := RESULT - 60 else if RESULT > 57 then RESULT := RESULT - 54 else RESULT := RESULT - 47; RESULT := RESULT + 5 + j; if RESULT > 62 then RESULT := RESULT - 62; if RESULT < 11 then RESULT := RESULT + 47 else if RESULT < 37 then RESULT := RESULT + 54 else RESULT := RESULT + 60; end; function fnEncryptPassword(psDescryptedPassword : String; pnMaxEncryptedLength : Integer) : String; var nDL,nSpacing, i, j : Integer; sEncryptedPassword, sEncryptedKey :String; begin sEncryptedPassword := EmptyStr; if psDescryptedPassword = EmptyStr then begin Result := EmptyStr; Exit; end; sEncryptedKey := 'ai! nDL := length(psDescryptedPassword); // nSpacing:=StrToInt(format('%2.0f',[(pnMaxEncryptedLength-nDL)/nDL])); nSpacing := Trunc((pnMaxEncryptedLength-nDL)/nDL); j := 1; while pnMaxEncryptedLength > 0 do begin sEncryptedPassword := sEncryptedPassword+ ///CHR(Max(ord(psDescryptedPassword[j]),0) + ord(sEncryptedKey[j])); //CHR(ord(psDescryptedPassword[j]) + 5 + j); CHR(nValEncrypt(ord(psDescryptedPassword[j]), j)); pnMaxEncryptedLength := pnMaxEncryptedLength - 1; i := 0; while((i < nSpacing) and (pnMaxEncryptedLength > 0)) do begin sEncryptedPassword :=sEncryptedPassword+ IntToStr(ord(sEncryptedKey[j])); i := i + 1; pnMaxEncryptedLength := pnMaxEncryptedLength-1; end; j := j + 1; end; Result := sEncryptedPassword; end; ------------------------------------------------------------------------------------ function nValDecrypt(xVal, j: Integer) : Integer; begin RESULT := xVal; if RESULT > 90 then RESULT := RESULT - 13 else if RESULT > 57 then RESULT := RESULT - 7; RESULT := RESULT - 52 - j; if RESULT < 1 then RESULT := RESULT + 62; if RESULT < 11 then RESULT := RESULT - 13 else if RESULT < 37 then RESULT := RESULT - 6; RESULT := RESULT + 60; end; function DecryptPassword(psEncryptedPassword : String): String; var nChar, i : Integer; sDecryptedPassword : String; begin RESULT := psEncryptedPassword; if RESULT <> EmptyStr then begin //sEncryptKey :='ai! begin nChar := nValDecrypt(ord(RESULT[i]),i); //Lennox 10/15/99 if nChar <> 0 then sDecryptedPassword := sDecryptedPassword + Char(nChar); end; //FOR RESULT := sDecryptedPassword; end; end; Last edited by avinash.lkr; 11-06-2018 at 02:25 PM. |
#2
|
|||
|
|||
![]()
Let me guess, you use a Unicode Delphi version.
Above code is Ansi based, so change all string to AnsiString and Char to AnsiChar and this should be fine. |
#3
|
|||
|
|||
![]()
instead you can use a modern library like lockbox or DCPCrypt
|
![]() |
Thread Tools | |
Display Modes | |
|
|