$PBExportHeader$f_psw_bczh.srf
global type f_psw_bczh from function_object
end type

forward prototypes
global function string f_psw_bczh (string obj_string, integer add_expr, string keystr)
end prototypes

global function string f_psw_bczh (string obj_string, integer add_expr, string keystr);//f_psw_BCzh(STRING obj_string,INT add_expr,STRING keystr) 三倍变长加密,可以用于任意字符串
//obj_string 目标的处理字符串
//add_expr 0 :加密,1:解密
//keystr 密钥数字字符串

IF IsNull(obj_string) THEN RETURN obj_string
Int LS_XX,STR_LEN,LS_YY
String RT_STRING = '',ZH_STR = '',FORMAT_STR
STR_LEN = Len(obj_string)
//IF STR_LEN=0 THEN RETURN ''

//FORMAT_STR=RIGHT(STRING(Pi(10)/1.11111,'0.###############'),15)
FORMAT_STR = keystr
IF Len(FORMAT_STR) > 0 THEN
	IF add_expr = 0 THEN
		FOR LS_YY = 1 To (STR_LEN/Len(FORMAT_STR))+1
			ZH_STR = ZH_STR+FORMAT_STR
		NEXT
	ELSE
		FOR LS_YY = 1 To ((STR_LEN/3)/Len(FORMAT_STR))+1
			ZH_STR = ZH_STR+FORMAT_STR
		NEXT
	END IF
END IF


IF add_expr = 0 THEN //ADD
	FOR LS_XX = 1 TO STR_LEN
		RT_STRING = RT_STRING+String(999 - Integer(Mid(ZH_STR,LS_XX,1))^2 * 9 - Asc(Mid (obj_string,LS_XX,1)) ,'000') //
	NEXT
	RT_STRING = Reverse(RT_STRING)
	IF RT_STRING = '' THEN RT_STRING = '3003003003'
ELSE //EXPR
	IF obj_string = '3003003003' THEN
		RT_STRING = ''
	ELSEIF obj_string = '' THEN
//		RT_STRING = '12233445'
		RT_STRING = ''
	ELSE
		obj_string = Reverse(obj_string)
		
		FOR LS_XX = 1 TO STR_LEN/3
			//MESSAGEBOX(STRINASC(Mid (obj_string,LS_XX*3 - 2,3)))
			IF Integer(Mid (obj_string,LS_XX*3 - 2,3)) = 0 THEN
				RT_STRING = RT_STRING+String(Asc(Mid (obj_string,LS_XX*3 - 2,3))*13)
			ELSE
				RT_STRING = RT_STRING+Char(999 - Integer(Mid(ZH_STR,LS_XX,1))^2 * 9 - Integer(Mid (obj_string,LS_XX*3 - 2,3))  ) //
			END IF
		NEXT
	END IF
END IF

RETURN RT_STRING

end function

