if exists(select 1 from sysobjects where name='f_get_descry')
  drop function f_get_descry
go

--½âÃÜ´¢Öµ¿¨º¯Êý
create   function f_get_descry(@as_source varchar(50))
returns  decimal(16,4)
as
begin 
if @as_source is null or @as_source='' return 0
declare @i int,@ll_len int
declare @ls_text varchar(50),@ls_result varchar(50)
select @ls_text=ltrim(rtrim(@as_source))
select @ll_len=len(@ls_text)
select @ls_result=''
select @i=1
while @i<=@ll_len
begin
select @ls_result=@ls_result+char(ascii(substring(@ls_text,@i,1)) - (2 * (@ll_len - @i - 2)))
select @i=@i+1
end
select @ls_result = reverse(@ls_result)
return cast(@ls_result as decimal(16,4))/10000
end
go

if exists(select 1 from sysobjects where name='f_get_encrypt')
  drop function f_get_encrypt
go

--¼ÓÃÜ
create    function [dbo].[f_get_encrypt](@as_source varchar(50))
returns  varchar(50)
as
begin 
	if @as_source is null or @as_source='' return NULL

	declare @i int,@ll_len int
	declare @ls_text varchar(50),@ls_result varchar(50)

	select @ls_text=ltrim(rtrim(@as_source))	
	select @ll_len=len(@ls_text)
	select @ls_text = reverse(@ls_text)
	select @ls_result=''
	set @i=1
	while @i<=@ll_len
	begin
		select @ls_result=@ls_result+char(ascii(substring(@ls_text,@i,1)) + (2 * (@ll_len - @i - 2)))
		select @i=@i+1
	end

	return @ls_result
end
go