网络开发 调用API函数 报表打印 常用技术 经验汇总 控件使用 软件工程 数据处理
您的位置:首页 >> vfp教程 >> 网上文摘 >> 数据处理 >> 正文

给数据库加\解密的函数
出处:网络

PARAMETERS filename,x &&filename为文件(含路径)x=8时为加密其它为解密

IF AT(".",filename)=0
filename=filename+".dbf"
ENDIF
cipher=CHR(255)+CHR(234)+CHR(119)+CHR(120)+CHR(103)+CHR(45)+CHR(99)+CHR(38)+CHR(63)
IF x=8 &&加密
handle=FOPEN(filename,2)
IF handle=-1 &&判断文件能否打开
FCLOSE(handle)
RETURN
ENDIF
old_byte=FREAD(handle,1) &&读出文件头一个字节
IF (ASC(old_byte)+9)>255 &&改写头一个字节(ASCII值加9)
new_byte=CHR(ASC(old_byte)+9-256)
ELSE
new_byte=CHR(ASC(old_byte)+9)
ENDIF
FSEEK(handle,0)
FWRITE(handle,new_byte) &&写回文件
FCLOSE(handle) &&关闭文件
strtofile(cipher,filename,.t.)
ELSE &&解密
handle=FOPEN(filename,2)
IF handle=-1 &&判断文件能否打开
FCLOSE(handle)
RETURN
ENDIF
fseek(handle,-9,2)
IF FREAD(handle,9)<>cipher
FCLOSE(handle)
RETURN
ENDIF
FSEEK(handle,0)
old_byte=FREAD(handle,1) &&读出文件头一个字节
IF ASC(old_byte)<9 &&改写头一个字节(ASCII值加9)
new_byte=CHR(ASC(old_byte)-9+256)
ELSE
new_byte=CHR(ASC(old_byte)-9)
ENDIF
FSEEK(handle,0)
FWRITE(handle,new_byte) &&写回文件
SET COMPATIBLE ON
FCHSIZE(handle,(FSIZE(filename)-9))
FCLOSE(handle) &&关闭文件
SET COMPATIBLE ON
ENDIF

[返回]

     

首页 | 设为首页 | 加入收藏 | 关于本站 | 友情链接 | 版权声明

     
 
Copyright© www.bianceng.cn Powered by 编程入门网 All Rights Reserved
吉ICP备06005558号