分享
 
 
 

MD5算法的T-SQL实现(FORSQL2000)(一)

王朝mssql·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

/*****************************************************************************

* 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

WHEN 13 THEN 8192

-- 00000000000000000010000000000000

WHEN 14 THEN 16384

-- 00000000000000000100000000000000

WHEN 15 THEN 32768

-- 00000000000000001000000000000000

WHEN 16 THEN 65536

-- 00000000000000010000000000000000

WHEN 17 THEN 131072

-- 00000000000000100000000000000000

WHEN 18 THEN 262144

-- 00000000000001000000000000000000

WHEN 19 THEN 524288

-- 00000000000010000000000000000000

WHEN 20 THEN 1048576

-- 00000000000100000000000000000000

WHEN 21 THEN 2097152

-- 00000000001000000000000000000000

WHEN 22 THEN 4194304

-- 00000000010000000000000000000000

WHEN 23 THEN 8388608

-- 00000000100000000000000000000000

WHEN 24 THEN 16777216

-- 00000001000000000000000000000000

WHEN 25 THEN 33554432

-- 00000010000000000000000000000000

WHEN 26 THEN 67108864

-- 00000100000000000000000000000000

WHEN 27 THEN 134217728

-- 00001000000000000000000000000000

WHEN 28 THEN 268435456

-- 00010000000000000000000000000000

WHEN 29 THEN 536870912

-- 00100000000000000000000000000000

WHEN 30 THEN 1073741824

-- 01000000000000000000000000000000

ELSE 0

END

RETURN(@iRes)

END

GO

IF EXISTS(SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MD5_LShift]') AND xtype IN(N'FN', N'IF', N'TF'))

DROP FUNCTION [dbo].[MD5_LShift]

GO

/*****************************************************************************

* Name: MD5_LShift

* Description: MD5_LShift

*****************************************************************************/

CREATE FUNCTION dbo.MD5_LShift(

@iValue

INT

,@iShiftBits

TINYINT

)

RETURNS INT

WITH ENCRYPTION

AS

BEGIN

DECLARE @iRes

BIGINT

SET @iRes = CAST(@iValue AS BINARY(8))

SET @iRes = @iRes * dbo.MD5_m_2Power(@iShiftBits)

RETURN(CAST(@iRes & 0x00000000FFFFFFFF AS BINARY(4)))

END

GO

IF EXISTS(SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MD5_RShift]') AND xtype IN(N'FN', N'IF', N'TF'))

DROP FUNCTION [dbo].[MD5

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有