eg:
CREATE FUNCTION fun_addmm(inpass varchar(10)) RETURNS varchar(11)
BEGIN
declare string_in varchar(39);
declare string_out varchar(78);
declare offset tinyint(2);
declare outpass varchar(30) default ';
declare len tinyint;
/*declare i tinyint;*/
/**/
set len=LENGTH(inpass);
if((len<=0) or (len>10)) then
return "";
end if;
set offset=(SECOND(NOW()) mod 39)+1; /*根据秒数取模*/
/*insert into testtb values(offset,'offset: ');*/
set string_out='YN8K1JOZVURB3MDETS5GPL27AXWIHQ94C6F0#$_'; /*密钥*/
set string_in='_$#ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
set outpass=CONCAT(outpass,SUBSTRING(string_out,offset,1));
/* insert into testtb values(2,outpass);*/
set string_out=CONCAT(string_out,string_out);
set @i=0;
REPEAT
set @i=@i+1;
set outpass=CONCAT(outpass,SUBSTR(string_out,INSTR(string_in,SUBSTRING(inpass,@i,1))+offset,1));
/* insert into testtb values(@i+2,outpass);*/
UNTIL (@i>=len)
end REPEAT;
return outpass;
END
(2)过程
CREATE PROCEDURE `pro_addmm`(IN inpass varchar(10),OUT outpass varchar(11))
BEGIN
declare string_in varchar(39);
declare string_out varchar(78);
declare offset tinyint(2);
declare len tinyint;
set outpass=';
set len=LENGTH(inpass);
if((len<=0) or (len>10)) then
set outpass=';
else
set offset=(SECOND(NOW()) mod 39)+1;
set string_out='YN8K1JOZVURB3MDETS5GPL27AXWIHQ94C6F0#$_';
set string_in='_$#ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
set outpass=CONCAT(outpass,SUBSTRING(string_out,offset,1));
set string_out=CONCAT(string_out,string_out);
set @i=0;
REPEAT
set @i=@i+1;
set outpass=CONCAT(outpass,SUBSTR(string_out,INSTR(string_in,SUBSTRING(inpass,@i,1))+offset,1));
UNTIL (@i>=len)
end REPEAT;
end if;
END