code:
/ ************************************************** *****************************
* Name: T-SQL MD5 algorithm implementation
* 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't')))
Drop function [dbo]. [MD5_M_ONBITS]
Go
/ ************************************************** *****************************
* Name: MD5_M_ONBITS
* DESCRIPTION: constant group
*********************************************************** *********************************** /
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 - 000000000000000000001111
WHEN 2 THEN 7 - 00000000000000000000000000000111
When 3 Then 15- 00000000000000000000000000000000000000000000000000000000001111
WHEN 4 THEN 31 - 00000000000000000000000000011111
When 5 Then 63 - 000000000000000000000000000000000000000000000000000000000000000000000000111111
WHEN 6 THEN 127 - 00000000000000000000000001111111
When 7 Then 255 - 000000000000000000000000000011111111
When 8 Then 511 - 00000000000000000000000000000000000000001111111111
When 9 Ten 1023 - 000000000000000000000000000000001111111111
When 10 Then 2047- 0000000000000000000000000000000000000000000081111111111
When 11 Then 4095 - 00000000000000000000000000111111111111
12im 8191 - 00000000000000000000000000000000000000000000000000000000000080000000000000000000000000000800000000000000000000800000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000008000000000000800000000000000008000000000000800000000000000000000000000000000000000000000000000000000000, 08111111111111
When 13 Ten 16383- 000000000000000000000011111111111111
When 14 Then 32767 - 000000000000000000000000000000000000000000000000000000000000-0000000000000000001111
191 131071 - 00000000000000101111111111111111111111
191 262143- 00000000000000000011111111111111111111
191 524287 - 00000000000010111111111111111111
19 death 1048575- @0000000000111111111111111111111111111111111111
When 20 dam 2097151 - 00000000001011111111111111111111
1211 4194303 - 00000000001111111111111111111111
121 8388607- 000000000111111111111111111111
When 23 Then 16777215- 00000000001111111111111111111111111111
When 24 Then 33554431 - 000000011111111111111111111111111111111
When 25 the 67108863 - 00000011111111111111111111111111
When 261 134217727 - 0000011111111111111111111111111
When 27 Then 268435455 - 0000111111111111111111111111111
121 536870911 - 00011111111111111111111
1291 1073741823 - 00111111111111111111111111111111
When 30 Ten 2147483647 - 011111111111111111111
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't'))
Drop Function [dbo]. [MD5_M_2POWER]
Go
/ ************************************************** *****************************
* Name: MD5_M_2POWER
* DESCRIPTION: constant group
*********************************************************** *********************************** /
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 - 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010
When 2 Then 4 - 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000
When 4 Then 16- 000000000000000000-00
When 5 Then 32 - 000000000000000000000000000
When 6 Then 64 - 000000000000000000002002
When 7 Then 128- 0000000000000000002002
WHEN 8 THEN 256 - 00000000000000000000000100000000
When 9 Then 512 - 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 million
When 10 Then 1024- 000000000000000000-00
When 11 Then 2048- 00000000000000000000-00
When 12 Then 4096- 000000000000000000-00
When 13 Then 8192 - 000000000000000000000000000002
When 14 Then 16384- 0000000000000000-00
14 death 32768- 00000000000000000000000000000000000000000000000000000000002
19 Then 65536- 0000000000000000-00
131 131072- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
191 262144- 0000000000000100000000000000200
19 death 524288- 000000000000000000000000000
When 20 Then 1048576- 0000000000010000000000002
When 21 Then 2097152 - 000000000000000000000000000000000
When 22 Then 4194304- 00000000010000000000002
When 23 treen 8388608 - 00000000100000000000000000000000
When 24 Then 16777216- @ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002
121 33554432 - 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020
When 26 Then 67108864- 00000100000000000000-00
127 Then 134217728- 0000000000000000002
121 268435456 - 0001000000000000000000000000-008
1991 536870912 - 001000000000000000000-008
WHEN 30 THEN 1073741824 - 010000000000000000200
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 & 0x00000000FFFFFFF 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't ')))
DROP FUNCTION [DBO]. [MD5_RSHIFT]
Go
/ ************************************************** *****************************
* Name: MD5_RSHIFT
* Description: MD5_RSHIFT
*********************************************************** *********************************** /
Create function dbo.md5_rshift
@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 & 0x00000000FFFFFFF AS BINARY (4)))
End
Go
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_rotateleft]') and xtype in (n'fn ', n'if', n't ')))
Drop Function [dbo]. [Md5_rotateleft]
Go
/ ************************************************** ************************************** Name: MD5_ROTATELEFT
* Description: MD5_ROTATELEFT
*********************************************************** *********************************** /
Create function dbo.md5_rotateleft
@IValue Int
, @ iShiftBits tinyint
)
Returns Int
With encryption
AS
Begin
Return (dbo.md5_lshift (@IValue, @ishiftbits) | dbo.md5_rshift (@IValue, (32 - @ishiftbits)))
End
Go
IF exists (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_addunsigned]') and xtype in (n'fn ', n'if ", n't')))
DROP FUNCTION [DBO]. [MD5_ADDUNSIGNED]
Go
/ ************************************************** *****************************
* Name: MD5_ADDUNSIGNED
* Description: MD5_ADDUNSIGNED
*********************************************************** *********************************** /
Create function dbo.md5_addunsigned
@IX INT
@ ≤ int
)
Returns Int
With encryption
AS
Begin
Declare @IRES BIGINT
Set @IRES = CAST (CAST (@ix as binary (8)) as bigint) Cast (Cast (@iy as binary (8)) as bigint
Return (Cast (@IRES & 0x00000000FFFFFFF AS BINARY (4)))
End
Go
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_f]') and xtype in (N'FN ', N'IF', N'TF ')))))
DROP FUNCTION [DBO]. [MD5_F]
Go
/ ************************************************** *****************************
* Name: MD5_F
* Description: MD5_F
*********************************************************** *********************************** /
CREATE FUNCTION DBO.MD5_F (
@X INT
@ y int
@ z int
)
Returns Int
With encryption
AS
Begin
Return ((@ x & @Y) | (~ @ x) & @z)) end
Go
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_g]') and xtype in (N'FN ', N'IF', N'TF '))))
DROP FUNCTION [DBO]. [MD5_G]
Go
/ ************************************************** *****************************
* Name: MD5_G
* Description: MD5_G
*********************************************************** *********************************** /
CREATE FUNCTION DBO.MD5_G (
@X INT
@ y int
@ z int
)
Returns Int
With encryption
AS
Begin
Return (@ x & @z) | (@Y & (~ @ z))))
End
Go
IF exists (select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_h]') and xtype in (n'fn ', n'if', n't ')))
DROP FUNCTION [DBO]. [MD5_H]
Go
/ ************************************************** *****************************
* Name: MD5_H
* Description: MD5_H
*********************************************************** *********************************** /
CREATE FUNCTION DBO.MD5_H (
@X INT
@ y int
@ z int
)
Returns Int
With encryption
AS
Begin
Return (@X ^ @Y ^ @z)
End
Go
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_i]') and xtype in (N'FN ', N'IF', N'TF ')))
Drop function [dbo]. [Md5_i]
Go
/ ************************************************** *****************************
* Name: MD5_i
* Description: MD5_i
*********************************************************** *********************************** /
CREATE FUNCTION DBO.MD5_I (
@X INT
@ y int
@ z int
)
Returns Int
With encryption
AS
Begin
Return (@X | (~ @ z)))))
End
Go
IF exists (select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_ff]') and xtype in (n'fn ', n'if ", n')) DROP FUNCTION [DBO] [Md5_ff]
Go
/ ************************************************** *****************************
* Name: MD5_FF
* Description: MD5_FF
*********************************************************** *********************************** /
Create function dbo.md5_ff (
@a int
, @ b int
, @ c int
, @ D int
@ x int
, @ s int
, @ ac int
)
Returns Int
With encryption
AS
Begin
Set @a = dbo.md5_addunsigned (@a, dbo.md5_addunsigned (dbo.md5_addunsigned (dbo.md5_f (@B, @c, @D), @x), @ac))
Set @a = dbo.md5_rotateleft (@a, @S)
Set @a = dbo.md5_addunsigned (@a, @B)
Return (@A)
End
Go
IF exists (select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_gg]') and xtype in (n'fn ', n'if ", n't')))
Drop Function [dbo]. [Md5_gg]
Go
/ ************************************************** *****************************
* Name: MD5_GG
* Description: MD5_GG
*********************************************************** *********************************** /
Create function dbo.md5_gg (
@a int
, @ b int
, @ c int
, @ D int
@ x int
, @ s int
, @ ac int
)
Returns Int
With encryption
AS
Begin
Set @a = dbo.md5_addunsigned (@a, dbo.md5_addunsigned (dbo.md5_addunsigned (dbo.md5_g (@B, @c, @D), @x), @ac))
Set @a = dbo.md5_rotateleft (@a, @S)
Set @a = dbo.md5_addunsigned (@a, @B)
Return (@A)
End
Go
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_hh]') and xtype in (N'FN ', N'IF', N'TF ')) DROP FUNCTION [DBO] [Md5_hh]
Go
/ ************************************************** *****************************
* Name: MD5_HH
* Description: md5_hh
*********************************************************** *********************************** /
CREATE FUNCTION DBO.MD5_HH (
@a int
, @ b int
, @ c int
, @ D int
@ x int
, @ s int
, @ ac int
)
Returns Int
With encryption
AS
Begin
Set @a = dbo.md5_addunsigned (@a, dbo.md5_addunsigned (dbo.md5_h (@B, @C, @D), @X), @ac))
Set @a = dbo.md5_rotateleft (@a, @S)
Set @a = dbo.md5_addunsigned (@a, @B)
Return (@A)
End
Go
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_ii]') and xtype in (N'FN ', N'IF', N'TF ')))
Drop function [dbo]. [Md5_ii]
Go
/ ************************************************** *****************************
* Name: MD5_II
* Description: MD5_II
*********************************************************** *********************************** /
CREATE FUNCTION DBO.MD5_II (
@a int
, @ b int
, @ c int
, @ D int
@ x int
, @ s int
, @ ac int
)
Returns Int
With encryption
AS
Begin
Set @a = dbo.md5_addunsigned (@a, dbo.md5_addunsigned (dbo.md5_addunsigned (dbo.md5_i (@B, @c, @D), @x), @ac))
Set @a = dbo.md5_rotateleft (@a, @S)
Set @a = dbo.md5_addunsigned (@a, @B)
Return (@A)
End
Go
IF exists (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_converttowordArray]') and xtype in (n'fn ', n'if ", n')) DROP FUNCTION [DBO] [MD5_CONVERTTOOWORDARRAY]
Go
/ ************************************************** *****************************
* Name: MD5_CONVERTTOWORDARRAY
* Description: MD5_CONVERTTOWORDARRAY
*********************************************************** *********************************** /
Create function dbo.md5_convertToWordArray (
@sorigmess varchar (8000) = ''
)
Returns @twordArray Table ([ID] Int Idnessity (0, 1), [Word] INT)
With encryption
AS
Begin
IF @sorigmess is null
Set @sorigmess = ''
Declare @ilenofmess Int
Declare @iwordArraylen Int
Declare @iposofword Int
Declare @iposofmess Int
Declare @icountofword Int
Set @ilenofmess = len (@sorigmess)
Set @iwordArraylen = (@ILENOFMESS 8) / 64 1) * 16
Set @icountofword = 0
While (@icountofword <@iwordArraylen)
Begin
INSERT INTO @TwordArray ([Word]) VALUES (0)
Set @icountofword = @icountofword 1
End
SELECT @iposofmess = 0, @Iposofword = 0, @icountofword = 0
While (@iposofmess <@ilenofmess)
Begin
Select @icountofword = @iposofmess / 4, @iposofword = @iposofmess% 4
Update @twordArray
Set [Word] = [Word] | dbo.md5_lshift (substring (@ sorigmess, @ iposofmess 1, 1), @ iposofword * 8)
Where [id] = @icountofword
Set @iposofmess = @iposofmess 1
End
Select @icountofword = @iposofmess / 4, @iposofword = @iposofmess% 4
Update @twordArray
Set [Word] = [Word] | dbo.md5_lshift (0x80, @ iposofword * 8)
Where [id] = @icountofword
Update @twordArray
Set [Word] = [Word] | dbo.md5_lshift (@ ilenofmess, 3)
Where [id] = @iWordArraylen - 2
Update @twordArray
Set [Word] = [Word] | dbo.md5_rshift (@ ilenofmess, 29)
Where [id] = @iWordArraylen - 1
Return
End
Go
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5_wordtohex]') and xtype in (n'fn ', n'if ", n't')))
DROP FUNCTION [DBO]. [MD5_WordTohex]
Go
/ ************************************************** *****************************
* Name: md5_wordtohex
* Description: MD5_WordTohex
*********************************************************** *********************************** /
Create function dbo.md5_wordtohex (
@IValue Int
)
Returns char (8)
With encryption
AS
Begin
Declare @SRES VARCHAR (8)
Declare @itmp Int
Declare @icount tinyint
SELECT @sres = '', @icount = 0
While (@ICOUNT <4)
Begin
Set @itmp = dbo.md5_rshift (@ iValue, @ iCount * 8) & 0x000000FF
Set @SRES = @sres case @itmp / 16 by 0 Then '0'
When 1 Ten '1'
When 2 Then '2'
When 3 Ten '3'
When 4 Ten '4'
When 5 Ten '5'
When 6 Then '6'
When 7 Ten '7'
When 8 Then '8'
When 9 Ten '9'
When 10 Ten 'A'
When 11 Then 'b'
When 12 Ten 'c'
When 13 Ten 'd'
When 14 Then 'e'
When 15 Then 'f'
ELSE 'END
Case @itmp% 16 when 0 Then '0'
When 1 Ten '1'
When 2 Then '2'
When 3 Ten '3'when 4 Then' 4 '
When 5 Ten '5'
When 6 Then '6'
When 7 Ten '7'
When 8 Then '8'
When 9 Ten '9'
When 10 Ten 'A'
When 11 Then 'b'
When 12 Ten 'c'
When 13 Ten 'd'
When 14 Then 'e'
When 15 Then 'f'
ELSE 'END
Set @icount = @icount 1
End
Return (@SRES)
End
Go
If EXISTS (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [Md5]') and xtype in (n'fn ', n'if ", n't')))
DROP FUNCTION [DBO]. [MD5]
Go
/ ************************************************** *****************************
* Name: MD5
* Description: MD5
*********************************************************** *********************************** /
Create function dbo.md5 (
@sorigmess nvarchar (4000)
)
Returns char (32)
With encryption
AS
Begin
- =================================================================
Declare @ s11 tinyint
Declare @ s12 tinyint
Declare @ s13 tinyint
Declare @ s14 tinyint
Declare @ s21 tinyint
Declare @ s22 tinyint
Declare @ s23 tinyint
Declare @ s24 tinyint
Declare @ s31 tinyint
Declare @ s32 tinyint
Declare @ s33 tinyint
Declare @ s34 tinyint
Declare @ s41 tinyint
Declare @ s42 tinyint
Declare @ s43 tinyint
Declare @ s44 tinyint
SELECT @ S11 = 7, @ S12 = 12, @ S13 = 17, @ S14 = 22
SELECT @ S21 = 5, @ S22 = 9, @ S23 = 14, @ S24 = 20
SELECT @ S31 = 4, @ S32 = 11, @ S33 = 16, @ S34 = 23
SELECT @ S41 = 6, @ S42 = 10, @ S43 = 15, @ S44 = 21
- =================================================================
Declare @a int
Declare @B INT
Declare @c Int
Declare @d int
Declare @AA Int
Declare @BB INT
Declare @CC INT
Declare @DD INT
SELECT @a = 0x67452301
, @ b = 0xefcdab89
, @ c = 0x98badcfe
@ d = 0x10325476
- =================================================================
Declare @SRES VARCHAR (32)
Set @sres = ''
Declare @iwordArraylen Int
Declare @iwordArraycount Int
Declare @ttmp table ([id] int, [word] int)
INSERT INTO @Ttmp Select * from dbo.md5_converttowordArray (@sorigmess)
Select @ iWordArraycount = 0, @iwordArraylen = count (*) from @ttmp
While (@iWordArraycount <@iwordArraylen)
Begin
SELECT @AA = @a, @BB = @B, @cc = @c, @dd = @d
Select @a = dbo.md5_ff (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 0), @ S11, 0xD76AA478)
SELECT @d = dbo.md5_ff (@D, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordaraycount 1), @ S12, 0xE8C7B756)
SELECT @c = dbo.md5_ff (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 2), @ S13, 0x242070db)
SELECT @B = dbo.md5_ff (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordaraycount 3), @ S14, 0xc1bdceee Select @a = dbo. MD5_FF (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 4), @ S11, 0xF57c0faf)
SELECT @d = dbo.md5_ff (@D, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordaraycount 5), @ S12, 0x4787c62a)
SELECT @c = dbo.md5_ff (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 6), @ S13, 0xA8304613)
SELECT @B = dbo.md5_ff (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 7), @ S14, 0xFD469501)
Select @a = dbo.md5_ff (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordaraycount 8), @ S11, 0x698098d8)
SELECT @d = dbo.md5_ff (@D, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 9), @ S12, 0x8b44f7af)
SELECT @c = dbo.md5_ff (@c, @D, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 10), @ S13, 0xffff5bb1)
SELECT @B = dbo.md5_ff (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 11), @ S14, 0x895cd7be)
Select @a = dbo.md5_ff (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 12), @ S11, 0x6b901122)
SELECT @d = dbo.md5_ff (@D, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordaraycount 13), @ S12, 0xFD987193) SELECT @c = dbo. MD5_FF (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 14), @ S13, 0xA679438E)
SELECT @B = dbo.md5_ff (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 15), @ S14, 0x49b40821)
Select @a = dbo.md5_gg (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 1), @ S21, 0xf61e2562)
SELECT @d = dbo.md5_gg (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 6), @ S22, 0xc040b340)
SELECT @c = dbo.md5_gg (@c, @D, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 11), @ S23, 0x265e5a51)
SELECT @B = dbo.md5_gg (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 0), @ S24, 0xE9B6C7AA)
SELECT @a = dbo.md5_gg (@a, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 5), @ S21, 0xD62F105D)
SELECT @d = dbo.md5_gg (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 10), @ S22, 0x2441453)
SELECT @c = dbo.md5_gg (@c, @D, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 15), @ S23, 0xD8A1E681)
SELECT @B = dbo.md5_gg (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordaraycount 4), @ S24, 0xE7D3FBC8) Select @a = dbo. MD5_GG (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 9), @ S21, 0x21e1cde6)
SELECT @d = dbo.md5_gg (@D, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 14), @ S22, 0xc33707d6)
SELECT @c = dbo.md5_gg (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 3), @ S23, 0xf4d50d87)
SELECT @B = dbo.md5_gg (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 8), @ S24, 0x455A14ed)
SELECT @a = dbo.md5_gg (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 13), @ S21, 0xA9E3E905)
SELECT @d = dbo.md5_gg (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 2), @ S22, 0xfcefa3f8)
Select @c = dbo.md5_gg (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 7), @ S23, 0x676f02d9)
SELECT @B = dbo.md5_gg (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 12), @ S24, 0x8D2A4C8A)
SELECT @a = dbo.md5_hh (@a, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 5), @ S31, 0xffa3942)
SELECT @d = dbo.md5_hh (@D, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 8), @ S32, 0x8771f681) select @c = dbo. MD5_HH (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 11), @ S33, 0x6d9d6122)
SELECT @B = dbo.md5_hh (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 14), @ S34, 0xFDE5380C)
Select @a = dbo.md5_hh (@a, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 1), @ S31, 0xA4bee44)
SELECT @d = dbo.md5_hh (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 4), @ S32, 0x4bdecfa9)
Select @c = dbo.md5_hh (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 7), @ S33, 0xF6bb4b60)
SELECT @B = dbo.md5_hh (@B, @C, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 10), @ S34, 0xbebfbc70)
Select @a = dbo.md5_hh (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 13), @ s31, 0x289b7ec6)
SELECT @d = dbo.md5_hh (@d, @a, @B, @C, (select [word] from @ttmp where [id] = @iwordArraycount 0), @ S32, 0xEAA127FA)
Select @c = dbo.md5_hh (@c, @D, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 3), @ S33, 0xD4ef3085)
SELECT @B = dbo.md5_hh (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordaraycount 6), @ S34, 0X4881D05) Select @a = dbo. MD5_HH (@a, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 9), @ S31, 0xD9D4D039)
Select @d = dbo.md5_hh (@d, @a, @B, @C, (select [word] from @ttmp where [id] = @iwordArraycount 12), @ S32, 0xE6DB99E5)
SELECT @c = dbo.md5_hh (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 15), @ S33, 0x1fa27cf8)
SELECT @B = dbo.md5_hh (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 2), @ S34, 0xc4ac5665)
Select @a = dbo.md5_ii (@a, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 0), @ S41, 0xF4292244)
Select @d = dbo.md5_ii (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 7), @ S42, 0x432AFF97)
Select @c = dbo.md5_ii (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 14), @ s43, 0xAb9423a7)
SELECT @B = dbo.md5_ii (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 5), @ S44, 0xFC93A039)
Select @a = dbo.md5_ii (@a, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 12), @ S41, 0x65559c3)
Select @d = dbo.md5_ii (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordaraycount 3), @ S42, 0x8f0cc92) Select @c = dbo. MD5_II (@c, @D, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 10), @ S43, 0xffeff47d)
SELECT @B = dbo.md5_ii (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 1), @ S44, 0x85845dd1)
Select @a = dbo.md5_ii (@a, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 8), @ S41, 0x6fa87e4f)
Select @d = dbo.md5_ii (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordArraycount 15), @ S42, 0xfe2CE6E0)
Select @c = dbo.md5_ii (@c, @d, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 6), @ S43, 0xA3014314)
SELECT @B = dbo.md5_ii (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordaraycount 13), @ S44, 0x4e0811A1)
Select @a = dbo.md5_ii (@A, @B, @c, @d, (select [word] from @ttmp where [id] = @iwordArraycount 4), @ s41, 0xf7537e82)
Select @d = dbo.md5_ii (@d, @a, @B, @c, (select [word] from @ttmp where [id] = @iwordaraycount 11), @ S42, 0xBD3AF235)
Select @c = dbo.md5_ii (@c, @D, @a, @B, (select [word] from @ttmp where [id] = @iwordArraycount 2), @ S43, 0x2AD7D2BB)
SELECT @B = dbo.md5_ii (@B, @c, @d, @a, (select [word] from @ttmp where [id] = @iwordArraycount 9), @ S44, 0XEB86D391) set @a = dbo. MD5_ADDUNSIGNED (@a, @AA)
Set @B = dbo.md5_addunsigned (@B, @BB)
Set @c = dbo.md5_addunsigned (@c, @cc)
Set @d = dbo.md5_addunsigned (@d, @dd)
Set @iwordArraycount = @iwordArrayCount 16
End
Set @SRES = dbo.md5_wordtohex (@a) dbo.md5_wordtohex (@B) dbo.md5_wordtohex (@c) dbo.md5_wordtohex (@D)
Set @SRES = Lower (@sres)
Return (@SRES)
End
Go
--Test
Set nocount on
SELECT DBO.MD5 ('') AS 'MD5 (' '') '
union
SELECT 'D41D8CD98F00B204E9800998ECF8427E'
Select dbo.md5 ('a') AS 'MD5 (' 'A' ')'
union
SELECT '0CC175B9C0F1B6A831C399E269772661'
Select dbo.md5 ('ABC') AS 'MD5 (' 'ABC') '
union
SELECT '900150983CD24FB0D6963F7D28E17F72'
Select dbo.md5 ('Message Digest') AS 'MD5 (' 'Message Digest' ')'
union
SELECT 'F96B697D7CB7938D525A2F31AAF161D0'
SELECT DBO.MD5 ('AbcdefghijklmnopqrStuvwxyz') AS 'MD5 (' 'AbcdefghijklmnopqrStuvwxyz' ')'
union
SELECT 'C3FCD3D76192E4007DFB496CCA67E13B'
select dbo.MD5 ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') as 'MD5 (' 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ')'
union
SELECT 'D174AB98D277D9F5A5611C2C9F419D9F'
select dbo.MD5 ( '12345678901234567890123456789012345678901234567890123456789012345678901234567890') as 'MD5 (' '12345678901234567890123456789012345678901234567890123456789012345678901234567890' ')' union
SELECT '57EDF4A22BE3C955AC49DA2E2107B67A'
SELECT DBO.MD5 ('I') AS 'MD5 (' I '' ')'
union
SELECT 'A31D0F25367EBE046897F8A939CA4A9F'