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