当前位置:文档之家› 简单的加密解密代码

简单的加密解密代码

函数名:gf_slock
参数说明:
string类型 1、source_string 待加密字符串
char 类型 2、lock_seed 加密密钥
注意事项:参数lock_seed如使用字符串,将自动截取第一个字符作为密钥。
功能:通过加密运算使字符串变为数字编码序列,从而实现加密;参数
中任何一个参数为空串将返回Null。
source_string可以为中文,但是lock_seed不能为中文
返回值:加密后的字符串
===============================================================*/
if source_string="" or lock_seed="" then return ""
int li_count,li_temp
string ls_locked=""
for li_count=1 to len(source_string)
choose case asc(mid(source_string,li_count,1))
case is < asc(lock_seed)
li_temp=asc(lock_seed) - asc(mid(source_string,li_count,1))
if li_temp>9 then
ls_locked=ls_locked+right(string(li_temp),1)+left(string(li_temp),1)+"0"
else
ls_locked=ls_locked+string(li_temp)+"s"+"0"
end if
continue
case asc(lock_seed)
ls_locked=ls_locked+"000"
continue
case is > asc(lock_seed)
li_temp=mod(asc(mid(source_string,li_count,1)),asc(lock_seed))
if li_temp>9 then
ls_locked=ls_locked+string(li_temp)+string(int(asc(mid(source_string,li_count,1))/asc(lock_seed)))
else
ls_locked=ls_locked+string(li_temp)+"b"+string(int(asc(mid(source_string,li_count,1))/asc(lock_seed)))
end if
continue

end choose
next
return ls_locked


end function

2.
字符串解密函数gf_sfree=====================
函数名:gf_sunlock
参数说明:
string类型 1、s_locked 待解密字符串
char 类型 2、s_lockseed 加密密钥
注意事项:参数s_lockseed如使用字符串,将自动截取第一个字符作为密钥。
功能:解密由gf_slock函数加密后的字符串;参数中任何一个参数为空串将返回Null。
s_lockseed不能为中文
返回值:解密后的字符串
===============================================================*/
if s_locked="" or s_lockseed="" then return ""
int li_loop,li_last
string ls_free,ls_temp
for li_loop=1 to len(s_locked) step 3
ls_temp=""
li_last=integer(mid(s_locked,li_loop+2,1))
if li_last=0 then
if integer(mid(s_locked,li_loop+1,1))=0 and integer(mid(s_locked,li_loop,1))=0 then
ls_free=ls_free+s_lockseed
continue
end if
if mid(s_locked,li_loop+1,1)='s' then
ls_free=ls_free+char(abs(integer(mid(s_locked,li_loop,1)) - asc(s_lockseed)))
continue
end if
ls_temp=mid(s_locked,li_loop+1,1)+mid(s_locked,li_loop,1)
ls_free=ls_free+char(abs(integer(ls_temp) - asc(s_lockseed)))
else
if mid(s_locked,li_loop+1,1)='b' then
ls_free=ls_free+char(integer(li_last)*asc(s_lockseed)+integer(mid(s_locked,li_loop,1)))
continue
end if
ls_temp=mi

d(s_locked,li_loop,2)
ls_free=ls_free+char(integer(ls_temp)+integer(li_last)*asc(s_lockseed))
end if

next
return ls_free

end function

相关主题
文本预览
相关文档 最新文档