我正在用PB做程序的加密,誰可以给我一份字符串加密数字的算法的源码,另外问一下PB中
把数字转化成16进制的数有什么函数,万分感谢,急!请大家发到我邮箱里去
zhouxiang6@netease.com 因为不常上网.
$PBExportHeader$gf_get_token.srf
$PBExportComments$去掉分隔符
global type gf_get_token from function_object
end type
forward prototypes
global function string gf_get_token (ref string p_string, string p_seperator)
end prototypes
global function string gf_get_token (ref string p_string, string p_seperator);int vPos
string vsRet=""
vPos=pos(P_string,p_seperator)
if vPos >= 1 then
vsRet=left(p_string,vpos - 1)
P_string=right(p_string,Len(p_string) - vPos - Len(p_seperator)+1)
//去掉分隔符
ELSE
vsRet=p_string
p_string=""
end if
return vsRet
end function
$PBExportHeader$gf_passexpress.srf
$PBExportComments$字符串加密
global type gf_passexpress from function_object
end type
forward prototypes
global function integer gf_passexpress (ref string pspass)
end prototypes
global function integer gf_passexpress (ref string pspass);//功能:将指定的口令经一定算法加密
// 参数:psPass 指定的口令
// 返回:—1,1成功与否
// 算法描述:
// 只允许vsPass中包含字母,如为其它字符,则出错返回
// 求出vsPass中各位的ASCII值之和对26取模,存入变量viMod中
// 将vsPass中各位的ASCII值加viMod然后分别对26取模,求出商值及余数
// 将各余数据加66转换字母
// 任意求出两字母vcBegin,vcEnd,要求该两字母ASCII之差能为viMod
// 求vsPass中各字符对应的另一字母,该字母ASCII码为vcBegin的ASCII码加
// 各位字符上面求出的商值
// 将6求出的字母分别加求出字母倒值后形成新口令的中间部分
// 形成加密后口令为:vcBegin++vcEnd
int i,viTemp,viAscSum,viSumMod,viDev,viMod,viMaxMod
char vcChar,vcBegin,vcEnd
string vsModStr,vsDevStr,vsTemp
/*检查口令是否合法,如不合法则返回*/
psPass=trim(psPass)
if len(psPass)>30 then
MessageBox("提示","字符串长度不能大于30!")
return -1
end if
viAscSum=0
for i=1 to len(psPass)
vcChar=mid(psPass,i,1)
viTemp=asc(vcChar)
if viTemp>asc(z) OR (viTemp>asc(Z) and viTemp<asc(a)) OR viTemp<asc(0) OR (viTemp>asc(9) and viTemp<asc(A) )then
MessageBox("提示","字符串中只能包含字母和数字!")
return -1
end if
viAscSum=viAscSum+viTemp
next
viSumMod=mod(viAscSum,26)
viMaxMod=viSumMod
vsModStr=""
vsDevStr=""
for i=1 to len(psPass)
vcChar=mid(psPass,i,1)
viTemp=asc(vcChar)+viSumMod
viDev=viTemp/26
viMod=viTemp - viDev*26
if viDev>viMaxMod then
viMaxMod=viDev
end if
vsModStr=vsModStr+","+char(viMod+65)
vsdevStr=vsDevStr+","+string(viDev)
next
vsModStr=mid(vsModStr,2)
vsDevStr=mid(vsDevStr,2)
/*随机求出ASCII码差值能表示viMaxMod的任意两字母*/
viTemp=rand(26 - viMaxMod)
vcBegin=char(viTemp+64)
vcEnd=char(viTemp+viSumMod+64)
vsTemp=""
do while vsDevStr<>""
vcChar=gf_get_token(vsDevStr,",")
viTemp=asc(vcBegin)+integer(vcChar)
vsTemp=vsTemp+","+char(viTemp)
loop
vsDevStr=mid(vsTemp,2)
/*形成加密口令*/
psPass=""
i=0
do while vsDevStr<>"" and vsModStr<>""
i++
if mod(i,2)=1 then
psPass=gf_get_token(vsDevStr,",")+gf_get_token(vsModStr,",")+psPass
else
psPass=gf_get_token(vsModStr,",")+gf_get_token(vsDevStr,",")+psPass
end if
loop
psPass=vcBegin+psPass+vcEnd
return 1
end function
$PBExportHeader$gf_passexpand.srf
$PBExportComments$口令解密
global type gf_passexpand from function_object
end type
forward prototypes
global function integer gf_passexpand (ref string pspass)
end prototypes
global function integer gf_passexpand (ref string pspass);// 功能:将指定的口令经一定算法解密
// 参数:psPass 指定的口令
// 返回:-1,1成功与否
// 算法描述:根据gfPassCompress 的加密算法反向解密
int i,viTemp,viCz,viNum
char vcBegin,vcEnd,vcFirst,vcSecond
string vsTemp,vsPass
/*求出变码差值*/
vcBegin=left(psPass,1)
vcEnd=right(psPass,1)
viCz=asc(vcEnd) - asc(vcBegin)
psPass=mid(psPass,2)
psPass=left(psPass,len(psPass) - 1)
viNum=0
for i=len(psPass) to 1 step -2
viNum++
if mod(viNum,2)=1 then
vcFirst=mid(psPass,i - 1,1)
vcSecond=mid(psPass,i,1)
else
vcFirst=mid(psPass,i ,1)
vcSecond=mid(psPass,i - 1,1)
end if
viTemp=(asc(vcFirst) - asc(vcBegin))*26+(asc(vcSecond) - 65) - viCz
vsTemp=char(viTemp)
vsPass=vsPass+vsTemp
next
psPass=vsPass
return 1
end function
人家的加密原理最好不要用,你自己还是设计一套吧!!!反正就是字符串处理。