分享

PB加密解密方法

 冰冻三尺roy 2010-09-03
global type f_encrypt from function_object
end type

forward prototypes
global function string f_encrypt (string st_text, string st_key)
end prototypes

global function string f_encrypt (string st_text, string st_key);//**************************************************************
// Function:     uf_pub_encrypt()                *
// Descirption:  用给定的密钥加密字符串         *
// Parameters:   string   st_text   待加密字串      *
//               string   st_key    密钥        *
//                                               *
// Return:     <加密后字串>                        *
//                                               *
// Author:     rain                           *
// Date:       2002.11.05                        *
//**************************************************************


string st_textencrypt
long lg_textlen,lg_keylen,lg_key
long lg_loop

IF isnull(st_key) OR isnull(st_text) THEN RETURN ''

lg_keylen = len(st_key)
FOR lg_loop = 1 TO lg_keylen
lg_key = lg_key + (asc(mid(st_key,lg_loop,1)) * lg_loop)
IF lg_key > 255 THEN lg_key = lg_key - 255
NEXT

DO While lg_key > 255
lg_key = lg_key - 255
LOOP

LONG lg_cbyte

lg_textlen = Len(st_text)

FOR lg_loop = 1 TO lg_textlen
lg_cbyte = asc(mid(st_text,lg_loop,1)) + lg_key
IF lg_cbyte > 255 THEN lg_cbyte = lg_cbyte - 255
st_textencrypt = st_textencrypt + char(lg_cbyte)
lg_key = lg_key + lg_cbyte
IF lg_key > 255 THEN lg_key = lg_key - 255
NEXT

RETURN st_textencrypt
end function


//解密
global type f_decrypt from function_object
end type

forward prototypes
global function string f_decrypt (string st_text, string st_key)
end prototypes

global function string f_decrypt (string st_text, string st_key);//**************************************************************
// Function:     uf_pub_decrypt()                *
// Descirption:  用给定的密钥解密字符串,与uf_pub_encrypt相对 *
// Parameters:   string   st_text   待解密字串      *
//               string   st_key    密钥        *
//                                               *
// Return:     <解密后字串>                        *
//                                               *
// Author:     rain                           *
// Date:       2002.11.05                        *
//**************************************************************

string st_textdecrypt
IF isnull(st_key) OR isnull(st_text) THEN RETURN ''
long lg_textlen,lg_keylen,lg_key
long lg_loop

lg_keylen = len(st_key)

FOR lg_loop = 1 TO lg_keylen
lg_key = lg_key + (asc(mid(st_key,lg_loop,1)) * lg_loop)
IF lg_key>255 THEN lg_key = lg_key - 255
NEXT

DO While lg_key>255
lg_key = lg_key - 255
LOOP

lg_textlen = len(st_text)

long lg_cbyte
FOR lg_loop = 1 TO lg_textlen
lg_cbyte = asc(mid(st_text,lg_loop,1)) - lg_key
IF lg_cbyte<0 THEN lg_cbyte = lg_cbyte + 255
st_textdecrypt = st_textdecrypt + char(lg_cbyte)
lg_key = lg_key + asc(mid(st_text,lg_loop,1))
IF lg_key > 255 THEN lg_key = lg_key - 255
NEXT

RETURN st_textdecrypt
end function




    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多