Data library encryption and decryption technology, one of FoxPro

Source: Internet
Author: User
Tags exit chr fread
Encryption | decryption
Data library encryption and decryption technology, one of FoxPro
Author: ccbzzp

In reality, the security of the data is very important, especially in a very important department like the bank,
So the encryption of the data is particularly important, and in the long term, the pen is always the encryption and decryption of the various numbers.
Write the law, I hope to help you, and we also explore together, learn together, and progress together!

FoxPro provides some low-level file operation functions for the user, using these low-level operational functions, you can actually operate on low-level files, and these low-level functions are mainly: FCLOSE (), Fcreate (), FEOF (), Ferror (), Fflush (), FGETS ( ), FOPEN (), FPUTS (), FREAD (), fseek (), Strtofile (), and so on, the specific usage of these functions is not specifically described here, and these functions are used in the following articles.

1. Data encryption

The following is an example of modifying a user's password to explain:

Program Chang_password Click () content:

IF VARTYPE (M.id_man) <> ' C '. OR. VARTYPE (M.ID_PSD) <> ' C '
=messagebox (' You haven't registered! No more password, ', 0+48+0, ' info tip! ') =6
Return
ELSE
SELECT &father_table.
LOCATE for Alltrim (Id_man) ==alltrim (M.id_man);
. and.

Alltrim (this. Parent.encrypt_data. CLICK (Id_psd,m.id_man)) ==alltrim (M.ID_PSD);
. and.! DELETED ()
IF FOUND ()
IF Alltrim (m.new_password1) ==alltrim (M.NEW_PASSWORD2)
REPLACE &father_table ... ID_PSD with

this. Parent.encrypt_data. CLICK (M.new_password1,m.id_man)
=messagebox (' Password changes are more successful! ', 0+48+0, ' Information tips! ')
ELSE
=messagebox (' Password doesn't change! Two new codes are inconsistent! ', 0+48+0, ' info tip!

')
ENDIF
ELSE
=messagebox (' Password doesn't change! Old password wrong! ', 0+48+0, ' info tip! ')
ENDIF
ENDIF
this. PARENT. Release ()




Program Encrypt_data Click () content:

Lparameters Encrypt_password, ENCRYPT_CHR
Encrypt_chr=alltrim (UPPER (ENCRYPT_CHR))
encrypt_chr1= ' 340821960120581 '
Encrypt_long=len (ENCRYPT_CHR1)
Encrypt_chr2=left (Encrypt_chr+encrypt_chr+encrypt_chr+encrypt_chr,encrypt_long)
This.return_data= '
For I=1 to Encrypt_long step 1
ALTERATION_CHR=CHR (Bitxor (ASC (SUBST (encrypt_chr1,i,1)), ASC (SUBST (encrypt_chr2,i,1)))


THIS.RETURN_DATA=THIS.RETURN_DATA+CHR (Bitxor (ASC (SUBST (encrypt_password,i,1)), ASC (Alterati

ON_CHR)))
ENDfor
Return This.return_data


2. In the data library file to encrypt
If there is a number of data library file C:\USERS. DBF;

Handle1=fopen ("C:\USERS.") DBF ")
IF handle1<0
MESSAGEBOX ("No specified file found ...", 0+64, "info tip!")
Return
ENDIF
I=1
Handle2=fcreate ("C:\USERS.") DBF ")
Do While. T.
=fseek (HANDLE1,I*32)
Retasc=fread (handle1,32)
IF ASC (RETASC) =13
EXIT
ENDIF
I=i+1
Enddo
=fseek (handle1,0)
Retstr=fread (HANDLE,I*32)
=fwrite (HANDLE2,RETSTR)
X=i*32
J=0
Do While. Not. FEOF (HANDLE1)
=fseek (HANDLE1,X+J)
Retasc=fread (handle1,1)
IF ASC (RETASC) >253
CH=CHR (255-ASC (RETASC))
ELSE
CH=CHR (ASC (RETASC) +2)
ENDIF
=fwrite (Handle2,ch)
J=j+1
Enddo
MESSAGEBOX ("Encryption successful ...", 0+64, "info tip!")
=fclose (HANDLE1)
=fclose (HANDLE2)
Return



3. In the data library file to decrypt
If there is a number of data library file C:\USERS. DBF;

Handle1=fopen ("C:\USERS.") DBF ")
IF handle1<0
MESSAGEBOX ("No specified file found ...", 0+64, "info tip!")
Return
ENDIF
Handle2=fcreate ("C:\USERS.") DBF ")
I=1
Do While. T.
=fseek (HANDLE1,I*32)
Retasc=fread (handle1,32)
IF ASC (RETASC) =13
EXIT
ENDIF
I=i+1
Enddo
=fseek (handle1,0)
Retstr=fread (HANDLE,I*32)
=fwrite (HANDLE2,RETSTR)
X=i*32
J=0
Do While. Not. FEOF (HANDLE1)
=fseek (HANDLE1,X+J)
Retasc=fread (handle1,1)
IF ASC (RETASC) <2
CH=CHR (255-ASC (RETASC))
ELSE
CH=CHR (ASC (RETASC)-2)
ENDIF
=fwrite (Handle2,ch)
J=j+1
Enddo
MESSAGEBOX ("Decryption successful ...", 0+64, "info tip!")
=fclose (HANDLE1)
=fclose (HANDLE2)
Return


Please indicate the above if you want to download it.

To continue ...


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.