MD5算法的T-SQL实现(FORSQL2000)(一)
2008-04-02 10:48:06来源:互联网 阅读 ()
/*****************************************************************************
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
* Name: T-SQL MD5算法实现
* Author: Rambo Qian
* Create Date: 2003-04-10
* Last Modified by: Rambo Qian
* Last Update Date: 2003-04-16
* Version: V1.0.00
*****************************************************************************/
GO
IF EXISTS(SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MD5_m_OnBits]') AND xtype IN(N'FN', N'IF', N'TF'))
DROP FUNCTION [dbo].[MD5_m_OnBits]
GO
/*****************************************************************************
* Name: MD5_m_OnBits
* Description: 常数组
*****************************************************************************/
CREATE FUNCTION dbo.MD5_m_OnBits(
@i TINYINT
)
RETURNS INT
WITH ENCRYPTION
AS
BEGIN
DECLARE @iRes INT
SELECT @iRes =
CASE @i
WHEN 0 THEN 1 -- 00000000000000000000000000000001
WHEN 1 THEN 3 -- 00000000000000000000000000000011
WHEN 2 THEN 7 -- 00000000000000000000000000000111
WHEN 3 THEN 15 -- 00000000000000000000000000001111
WHEN 4 THEN 31 -- 00000000000000000000000000011111
WHEN 5 THEN 63 -- 00000000000000000000000000111111
WHEN 6 THEN 127 -- 00000000000000000000000001111111
WHEN 7 THEN 255 -- 00000000000000000000000011111111
WHEN 8 THEN 511 -- 00000000000000000000000111111111
WHEN 9 THEN 1023 -- 00000000000000000000001111111111
WHEN 10 THEN 2047 -- 00000000000000000000011111111111
WHEN 11 THEN 4095 -- 00000000000000000000111111111111
WHEN 12 THEN 8191 -- 00000000000000000001111111111111
WHEN 13 THEN 16383 -- 00000000000000000011111111111111
WHEN 14 THEN 32767 -- 00000000000000000111111111111111
WHEN 15 THEN 65535 -- 00000000000000001111111111111111
WHEN 16 THEN 131071 -- 00000000000000011111111111111111
WHEN 17 THEN 262143 -- 00000000000000111111111111111111
WHEN 18 THEN 524287 -- 00000000000001111111111111111111
WHEN 19 THEN 1048575 -- 00000000000011111111111111111111
WHEN 20 THEN 2097151 -- 00000000000111111111111111111111
WHEN 21 THEN 4194303 -- 00000000001111111111111111111111
WHEN 22 THEN 8388607 -- 00000000011111111111111111111111
WHEN 23 THEN 16777215 -- 00000000111111111111111111111111
WHEN 24 THEN 33554431 -- 00000001111111111111111111111111
WHEN 25 THEN 67108863 -- 00000011111111111111111111111111
WHEN 26 THEN 134217727 -- 00000111111111111111111111111111
WHEN 27 THEN 268435455 -- 00001111111111111111111111111111
WHEN 28 THEN 536870911 -- 00011111111111111111111111111111
WHEN 29 THEN 1073741823 -- 00111111111111111111111111111111
WHEN 30 THEN 2147483647 -- 01111111111111111111111111111111
ELSE 0
END
RETURN(@iRes)
END
GO
IF EXISTS(SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MD5_m_2Power]') AND xtype IN(N'FN', N'IF', N'TF'))
DROP FUNCTION [dbo].[MD5_m_2Power]
GO
/*****************************************************************************
* Name: MD5_m_2Power
* Description: 常数组
*****************************************************************************/
CREATE FUNCTION dbo.MD5_m_2Power(
@i TINYINT
)
RETURNS INT
WITH ENCRYPTION
AS
BEGIN
DECLARE @iRes INT
SELECT @iRes =
CASE @i
WHEN 0 THEN 1 -- 00000000000000000000000000000001
WHEN 1 THEN 2 -- 00000000000000000000000000000010
WHEN 2 THEN 4 -- 00000000000000000000000000000100
WHEN 3 THEN 8 -- 00000000000000000000000000001000
WHEN 4 THEN 16 -- 00000000000000000000000000010000
WHEN 5 THEN 32 -- 00000000000000000000000000100000
WHEN 6 THEN 64 -- 00000000000000000000000001000000
WHEN 7 THEN 128 -- 00000000000000000000000010000000
WHEN 8 THEN 256 -- 00000000000000000000000100000000
WHEN 9 THEN 512 -- 00000000000000000000001000000000
WHEN 10 THEN 1024 -- 00000000000000000000010000000000
WHEN 11 THEN 2048 -- 00000000000000000000100000000000
WHEN 12 THEN 4096 -- 00000000000000000001000000000000
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇: SQL语法参考手册(转)
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash