'参考namespace imports system imports microsoft.visualbasic imports system.collections imports system.configuration
namespace security public class crypt '加密字符串 public function encrypt(byval plainstr as string, byval key as string) as string dim strchar, keychar, newstr as string dim pos as integer dim i, intlen as integer dim side1, side2 as string pos = 1
for i = 1 to len(plainstr) strchar = mid(plainstr, i, 1) keychar = mid(key, pos, 1) newstr = newstr & chr(asc(strchar) xor asc(keychar)) if pos = len(key) then pos = 0 pos = pos + 1 next
if len(newstr) mod 2 = 0 then side1 = strreverse(left(newstr, (len(newstr) / 2))) side2 = strreverse(right(newstr, (len(newstr) / 2))) newstr = side1 & side2 end if
encrypt = newstr end function
'解密字符串 public function decrypt(byval plainstr as string, byval key as string) as string dim strchar, keychar, newstr as string dim pos as integer dim i as integer dim side1 as string dim side2 as string pos = 1
if len(plainstr) mod 2 = 0 then side1 = strreverse(left(plainstr, (len(plainstr) / 2))) side2 = strreverse(right(plainstr, (len(plainstr) / 2))) plainstr = side1 & side2 end if
for i = 1 to len(plainstr) strchar = mid(plainstr, i, 1) keychar = mid(key, pos, 1) newstr = newstr & chr(asc(strchar) xor asc(keychar)) if pos = len(key) then pos = 0 pos = pos + 1 next
decrypt = newstr end function end class end namespace