开心套餐 发表于 2007-4-18 23:17

PB中的加密解密的方法

第一次来这里,如果在这里能交几个好友,我会很开心的,我是刚学PB的,闲着没事把PB中加密解密的方法研究了一个,看来PB中加密解密的方法还是不复杂的,就做了以下几个函数。发给大家共享一下。<BR>我的<FONT color=#ee3d11>QQ:307679136,QQ群号:30657445 。</FONT>希望大家能多联系。共同提高。<BR><BR>/*******************************************************************<BR>函数名称:f_decryptpbpassword()<BR>参数:     as_orginalpassword string 原始密码<BR>返回值: string 解密后文本<BR>功能描述:解密PB数据库连接描述密码<BR>*******************************************************************/<BR> string ls_temp,ls_return=''<BR>integer i,li_count,li_ascii<BR>if len(as_orginalpassword) &lt; 2 or as_orginalpassword = '00' then return ''<BR> <BR>as_orginalpassword = left(reverse(as_orginalpassword),len(as_orginalpassword) - 2)<BR>li_count = ceiling(len(as_orginalpassword) / 2)<BR>for i = 1 to li_count<BR>       ls_temp = mid(as_orginalpassword,(i - 1) * 2 + 1,2)<BR>       li_ascii =of_hextodecimal(ls_temp)<BR>       ls_temp = char(li_ascii)       <BR>       ls_return = ls_return + ls_temp<BR>next<BR>return ls_return<BR> /*******************************************************************<BR>函数名称:f_encryptpbpassword()<BR>参数:     as_newpassword string 原始密码<BR>返回值: string 解密后文本<BR>功能描述:加密PB数据库连接描述密码<BR>*******************************************************************/<BR>string ls_temp,ls_return='00'<BR>integer i,li_count,li_ascii <BR>if len(as_newpassword)=0 or as_newpassword = '' then return '00'<BR>as_newpassword = reverse(as_newpassword)<BR>li_count = len(as_newpassword)<BR>for i = 1 to li_count<BR>       li_ascii  = asc(mid(as_newpassword,i,1))<BR>         ls_temp= of_decimaltohex(li_ascii)<BR>       ls_return =ls_temp+ls_return<BR>next<BR>return reverse(ls_return)<BR> /*******************************************************************<BR>函数名称:of_decimaltohex()<BR>参数:    as_decicmaldata  unsignedlong  十进制数<BR>返回值: string 十六进制数<BR>功能描述:十进制转十六进制<BR>*******************************************************************/<BR>string ls_hex,li_hex[ 0 to 15]<BR>unsignedlong  lul_decimal<BR>integer i<BR>for i = 0 To 9<BR>   li_hex[i] = string(i)<BR>next<BR>for i = 10 To 15<BR>    li_hex[i] =char(55+i)<BR>next <BR>do while   as_decicmaldata&gt;0<BR>lul_decimal=mod(as_decicmaldata,16)<BR>as_decicmaldata=int(as_decicmaldata/16)<BR>choose case lul_decimal<BR>    case 0 to 15<BR>        ls_hex=li_hex[lul_decimal]+ls_hex<BR>    case else<BR>        return lower(ls_hex)<BR>end choose<BR>loop<BR>return lower(ls_hex)<BR> /*******************************************************************<BR>函数名称:of_hextodecimal()<BR>参数:    as_hexdata string  十六进制数<BR>返回值: unsignedlong 十进制数<BR>功能描述:十六进制转十进制<BR>*******************************************************************/<BR>char        lch_char[]<BR>unsignedlong  lul_decimal=0<BR>integer li_dec[48 to 70], i, li_len<BR> <BR>for i = 48 To 57<BR>       li_dec[i] = i - 48<BR>next<BR> <BR>for i = 65 To 70<BR>       li_dec[i] = i - 55<BR>next <BR> <BR>as_hexdata = upper(as_hexdata)<BR>lch_char = as_hexdata<BR>li_len = len (as_hexdata)<BR> <BR>for i = 1 to li_len<BR>       choose case lch_char[i]<BR>       case '0' to '9', 'A' to 'F'<BR>              lul_decimal = lul_decimal * 16 + li_dec[asc(lch_char[i])]<BR>       case else<BR>              return lul_decimal<BR>       end choose    <BR>next<BR>return lul_decimal<BR>

huier 发表于 2007-4-19 15:21

非常感谢!

页: [1]

编程论坛