This is the implementation method of SHA-256 encryption in the ASP.
I am looking for the implementation method of SHA-512 encryption in ASP. If you have source code, you will send a buddy, thank you!
Yesoce@163.com
<%
Private m_lonbits (30)
Private M_L2Power (30)
Private K (63)
PRIVATE CONST BITS_TO_A_BYTE = 8
Private const bytes_to_a_word = 4
PRIVATE const bits_to_a_word = 32
m_lonbits (0) = ClNG (1)
M_lonbits (1) = CLNG (3)
M_lonbits (2) = CLNG (7)
M_lonbits (3) = CLNG (15)
M_lonbits (4) = CLNG (31)
M_lonbits (5) = clng (63)
M_lonbit (6) = CLNG (127)
M_lonbits (7) = CLNG (255)
M_lonbits (8) = CLNG (511)
m_lonbits (9) = CLNG (1023)
M_lonbits (10) = CLNG (2047)
M_lonbits (11) = clng (4095)
M_lonbits (12) = CLNG (8191)
m_lonbits (13) = CLNG (16383)
M_lonbits (14) = CLNG (32767)
M_lonbits (15) = CLNG (65535)
M_lonbits (16) = CLNG (131071)
M_lonbits (17) = CLNG (262143)
M_lonbits (18) = CLNG (524287)
M_lonbits (19) = clng (1048575)
M_lonbits (20) = CLNG (2097151)
M_lonbits (21) = clng (4194303)
M_lonbits (22) = CLNG (8388607)
M_lonbits (23) = CLNG (16777215)
M_LONBITS (24) = CLNG (33554431)
M_LONBITS (25) = CLNG (67108863)
M_lonbits (26) = CLNG (134217727)
M_lonbit (27) = CLNG (268435455)
M_lonbit (28) = CLNG (536870911)
M_lonbits (29) = CLNG (1073741823)
M_lonbits (30) = clng (2147483647)
m_l2power (0) = CLNG (1)
M_L2Power (1) = CLNG (2)
M_L2Power (2) = CLNG (4)
M_L2Power (3) = CLNG (8)
M_L2Power (4) = CLNG (16)
M_L2Power (5) = CLNG (32)
M_L2Power (6) = CLNG (64)
M_L2Power (7) = clng (128)
M_L2Power (8) = CLNG (256)
M_L2Power (9) = CLNG (512)
M_L2Power (10) = CLNG (1024)
M_L2Power (11) = CLNG (2048)
M_L2Power (12) = CLNG (4096)
M_L2Power (13) = clng (8192)
M_L2Power (14) = clng (16384) M_L2Power (15) = CLNG (32768)
M_L2Power (16) = CLNG (65536)
m_l2power (17) = CLNG (131072)
M_L2Power (18) = CLNG (262144)
M_L2Power (19) = CLNG (524288)
M_L2Power (20) = clng (1048576)
M_L2Power (21) = CLNG (2097152)
M_L2Power (22) = CLNG (4194304)
M_L2Power (23) = CLNG (8388608)
M_L2Power (24) = CLNG (16777216)
M_L2Power (25) = CLNG (33554432)
M_L2Power (26) = CLNG (67108864)
M_L2Power (27) = CLNG (134217728)
M_L2Power (28) = CLNG (268435456)
M_L2Power (29) = CLNG (536870912)
M_L2Power (30) = CLNG (1073741824)
K (0) = & h428a2f98
K (1) = & h71374491
K (2) = & HB5C0FBCF
K (3) = & HE9B5DBA5
K (4) = & h3956c25b
K (5) = & h59f111f1
K (6) = & H923F82A4
K (7) = & HAB1C5ED5
K (8) = & HD807AA98
K (9) = & h12835B01
K (10) = & H243185BE
K (11) = & H550C7DC3
K (12) = & h72be5d74
K (13) = & H80DEB1FE
K (14) = & h9bdc06a7
K (15) = & hc19bf174
K (16) = & HE49B69C1
K (17) = & hefbe4786
K (18) = & HFC19DC6
K (19) = & h240ca1cc
K (20) = & H2DE92C6F
K (21) = & H4A7484AA
K (22) = & H5CB0A9DC
K (23) = & h76f988da
K (24) = & h983e5152
K (25) = & ha831c66d
K (26) = & hb00327c8
K (27) = & HBF597FC7
K (28) = & hc6e00bf3
K (29) = & hd5a79147
K (30) = & h6ca6351
K (31) = & H14292967
K (32) = & H27B70A85
K (33) = & h2e1b2138
K (34) = & H4D2C6DFC
K (35) = & h53380d13
K (36) = & h650A7354
K (37) = & H766A0ABB
K (38) = & h81c2c92e
K (39) = & H92722C85
K (40) = & ha2bfe8a1
K (41) = & ha81a664bk (42) = & hc24b8b70
K (43) = & HC76C51A3
K (44) = & hd192e819
K (45) = & HD6990624
K (46) = & HF40E3585
K (47) = & H106AA070
K (48) = & H19A4C116
K (49) = & h1e376c08
K (50) = & h2748774c
K (51) = & H34B0BCB5
K (52) = & h391c0cb3
K (53) = & h4ed8aa4a
K (54) = & h5b9cca4f
K (55) = & H682E6FF3
K (56) = & h748f82ee
K (57) = & h78a5636f
K (58) = & h84c87814
K (59) = & h8cc70208
K (60) = & H90Befffa
K (61) = & ha4506ceb
K (62) = & hbef9a3f7
K (63) = & hc67178f2
Private function lshift (Lvalue, iShiftBits)
IF iShiftBits = 0 THEN
Lshift = LVALUE
EXIT FUNCTION
Elseif ishiftBits = 31 THEN
IF Lvalue and 1 THEN
Lshift = & h80000000
Else
Lshift = 0
END IF
EXIT FUNCTION
Elseif IshiftBits <0 or iShiftBits> 31 THEN
Err.raise 6
END IF
IF (LValue and M_L2Power (31 - IshiftBits)) THEN
Lshift = ((Lvalue and M_lonbits (31 - (iShiftBits 1))) * m_l2power (iShiftBits)) or & h80000000
Else
Lshift = ((Lvalue and M_Lonbits) * m_l2power (iShiftBits))
END IF
END FUNCTION
Private function Rshift (Lvalue, IshiftBits)
IF iShiftBits = 0 THEN
Rshift = LVALUE
EXIT FUNCTION
Elseif ishiftBits = 31 THEN
If Lvalue and & H80000000 THEN
Rshift = 1
Else
Rshift = 0
END IF
EXIT FUNCTION
Elseif IshiftBits <0 or iShiftBits> 31 THEN
Err.raise 6
END IF
Rshift = (LValue and & H7ffffe) / M_L2Power (iShiftBits)
IF (Lvalue and & H80000000) THEN
Rshift = (RSHIFT OR (& H400000 / M_L2Power (IshiftBits - 1)))
END IF
END FUNCTION
Private function addunsigned (lx, ly) DIM LX4
DIM LY4
DIM LX8
DIM LY8
DIM LRESULT
Lx8 = lx and & h80000000
LY8 = ly and & h80000000
LX4 = lx and & h40000000
LY4 = Ly and & H40000000
LRESULT = (lx and & h3ffffff) (Ly and & H3FFFFFF)
IF lx4 and ly4 Then
Lresult = LRESULT XOR & H80000000 XOR LX8 XOR LY8
Elseif Lx4 or Ly4 Then
If LRESULT AND & H40000000 THEN
LResult = LRESULT XOR & HC0000000 XOR LX8 XOR LY8
Else
Lresult = LRESULT XOR & H40000000 xor LX8 XOR LY8
END IF
Else
LResult = LRESULT XOR LX8 XOR LY8
END IF
Addunsigned = LRESULT
END FUNCTION
Private function CH (X, Y, Z)
CH = ((x and y) xor ((not x) and z))
END FUNCTION
Private function Maj (x, y, z)
MAJ = (x and y) xor (x and z) xor (y and z))
END FUNCTION
Private function s (x, n)
S = (Rshift (x, (n and m_lonbits (4))) or lshift (x, (32 - (n and m_lonbits (4)))))))))))))))))
END FUNCTION
Private function r (x, n)
R = RSHIFT (x, clng (n and m_lonbits (4))))
END FUNCTION
Private function sigma0 (x)
Sigma0 = (S (x, 2) xor s (x, 13) xor s (x, 22))
END FUNCTION
Private function sigma1 (x)
Sigma1 = (S (x, 6) xor s (x, 11) xor s (x, 25))
END FUNCTION
Private function gamma0 (x)
Gamma0 = (S (x, 7) xor s (x, 18) xor r (x, 3))
END FUNCTION
Private function gamma1 (x)
Gamma1 = (s (x, 17) xor s (x, 19) xor r (x, 10))
END FUNCTION
Private function convertToWordArray (SMESSAGE)
Dim LMessageLength
Dim lnumberofwords
Dim lwordArray ()
DIM LBYTEPSITION
DIM LBYTECOUNT
Dim lwordcount
DIM LBYTE
Const modulus_bits = 512
Const congruent_bits = 448
LMessageLength = Len (SMESSAGE)
lNumberOfWords = (((lMessageLength ((MODULUS_BITS - CONGRUENT_BITS) / BITS_TO_A_BYTE)) / (MODULUS_BITS / BITS_TO_A_BYTE)) 1) * (MODULUS_BITS / BITS_TO_A_WORD) ReDim lWordArray (lNumberOfWords - 1)
lbyteposition = 0
lbytecount = 0
DO Until Lbytecount> = LMESSAGELENGTH
LWORDCOUNT = lbytecount / bytes_to_a_word
LbytePosition = (3 - (lbytecount mode_to_a_word)) * bits_to_A_BYTE
Lbyte = ASCB (MID (SMESSAGE, LBYTECUNT 1, 1))
LWordArray (lwordcount) = lwordArray (lwordcount) or lshift (lbyte, lbyteposition)
lbytecount = lbytecount 1
Loop
LWORDCOUNT = lbytecount / bytes_to_a_word
LbytePosition = (3 - (lbytecount mode_to_a_word)) * bits_to_A_BYTE
LWordArray (lwordcount) = lwordArray (lwordcount) or lshift (& H80, lbyteposition)
LWordArray (lnumberofwords - 1) = lshift (LMessageLength, 3)
LWordArray (lnumberofwords - 2) = RSHIFT (LMessageLength, 29)
ConvertToWordArray = LWORDARRAY
END FUNCTION
Public Function SHA256 (SMESSAGE)
DIM Hash (7)
DIM M
DIM W (63)
DIM A
DIM B
DIM C
DIM D
DIM E
DIM F
DIM G
DIM H
DIM I
DIM J
DIM T1
DIM T2
Hash (0) = & h6a09e667
Hash (1) = & hbb67ae85
Hash (2) = & H3C6EF372
Hash (3) = & ha54ff53a
Hash (4) = & h510e527f
Hash (5) = & h9b05688c
Hash (6) = & H1F83D9AB
Hash (7) = & h5be0cd19
M = ConvertToWordArray (SMESSAGE)
For i = 0 to Ubound (m) STEP 16
A = Hash (0)
B = Hash (1)
C = Hash (2)
D = Hash (3)
E = Hash (4)
f = Hash (5)
g = hash (6)
h = hash (7)
For j = 0 to 63
IF j <16 THEN
W (j) = m (J i)
Else
W (j) = addunsigned (AddunSigned (W (J - 2)), W (J - 7)), GAMMA0 (W (J - 15))), W (J - 16)) End IF
T1 = addunsigned (addunsigned (addunsigned (H, Sigma1 (E)), CH (E, F, G)), K (J)), W (J))
T2 = addunsigned (Sigma0 (A), Maj (A, B, C))
h = g
g = f
f = e
E = addunsigned (d, t1)
D = C
C = B
B = a
A = addunsigned (T1, T2)
NEXT
Hash (0) = addunsigned (a, hash (0))
Hash (1) = addunsigned (b, hash (1))
Hash (2) = addunsigned (c, hash (2))
Hash (3) = addunsigned (D, Hash (3))
Hash (4) = addunsigned (e, hash (4))
Hash (5) = addunsigned (f, hash (5))
Hash (6) = addunsigned (g, hash (6))
Hash (7) = addunsigned (h, hash (7))
NEXT
SHA256 = LCase (Right ("00000000" & HEX (Hash (0)), 8) & Right ("00000000" & HEX (Hash (1)), 8) & Right ("00000000" & HEX (Hash (2) ), 8) & right ("00000000" & hex (Hash (3)), 8) & Right ("00000000" & HEX (Hash (4)), 8) & Right ("00000000" & HEX (Hash (5) )), 8) & right ("00000000" & hex (hash (6)), 8) & right ("00000000" & hex (hash (7)), 8))
END FUNCTION
%>