返回列表 发帖

[原创文章] 关于国内某知名大学网站加密算法的研究

原创作者:柔肠寸断 [3.A.S.T]  http://www.3ast.com.cm
5 p. a: a% F1 H& C6 D: b原始出处:http://www.3ast.com.cm* y5 n6 l9 X& T- K6 g
+ X; }# `6 n$ |$ x) o, i3 e! x2 b
看不懂的直接绕过. [1 X$ {! m7 a4 C0 s% b2 L
加密前为:hwy1234560 O" \& P" v* f/ A
加密后为0F9C1C7A2EE76EBB5C1F4D7526CC4F883F4E6 m* ?- E- |5 b( y7 ^; e

% M8 O9 {! n% G* L5 Y7 k5 r+ u============================================, z1 b1 [- v; q, W4 [/ I% h
上面是当时自己校内的心情。现在已经解破出来了,分享给大家8 [2 b# D2 h6 e3 D1 R$ T* p
也就不隐瞒大家什么了,这个是国内某知名大学的后台加密算法
- w- ?1 |0 F8 b/ I9 ?以下是RSA算法文件
3 U! s* f/ A* Y0 z' {0 f2 _) X* y" x1 k* I: S0 @
文件名RSA.ASP
* f: n  V, \4 A- f- q  h# I===============================================' x" P. T% e$ O& a" k
<%
; K$ H( G% O6 C* V( hClass clsRSA , v  _7 w# x3 a! J1 Y7 Y$ E
Public PrivateKey   p0 _; q7 c$ J# _! A
Public PublicKey
7 l+ F5 R% y& P: BPublic Modulus
2 B: @2 |. A4 t4 ~8 l0 w) I7 `Public Function Crypt(pLngMessage, pLngKey) ( w1 k6 h1 |  z  U' ]* @& `* T
On Error Resume Next
1 U) h: X3 b. R1 kDim lLngMod
" S( x) ^; e5 G" ]/ hDim lLngResult 1 g5 `( D! q: j6 U9 G
Dim lLngIndex
% x3 P4 F+ R$ L: A% a3 P: g  MIf pLngKey Mod 2 = 0 Then / X7 A5 |; G# i: z: v8 O# X& G
lLngResult = 1 + U$ N) w" R/ ~3 L4 X. y( q# n
For lLngIndex = 1 To pLngKey / 2 : u6 M& g% d/ ]
lLngMod = (pLngMessage ^ 2) Mod Modulus 8 ~  J' C" \5 N* ~9 N
' Mod may error on key generation " g1 _- Q2 I+ Z! ~
lLngResult = (lLngMod * lLngResult) Mod Modulus
' `5 o2 B2 _  o& R. L9 ~! sIf Err Then Exit Function
" [2 s) Y- N, HNext
1 r. d+ M1 }1 L+ n( ~8 E& M" ?Else
: g; I+ ~/ [; BlLngResult = pLngMessage - E% K1 w5 r& `9 y, Y$ k4 @" Q
For lLngIndex = 1 To pLngKey / 2
  h! B. o% a! r0 o2 p+ @* [  JlLngMod = (pLngMessage ^ 2) Mod Modulus   }" ]1 q% {( ~& `/ \# h: X
On Error Resume Next ! ]" F+ h- ?3 D$ d
' Mod may error on key generation
6 D1 }* j  j* i& Z9 d4 t. \lLngResult = (lLngMod * lLngResult) Mod Modulus 0 f3 n: r& O8 s2 u0 h
If Err Then Exit Function
) C2 h8 R! \7 b" jNext ( U! B% `3 e7 @! E
End If
0 _: [) N2 N, z& p4 d8 vCrypt = lLngResult : [/ G$ n/ G6 m1 L+ W
End Function" q2 g: K: A0 @3 C( t

& R3 U+ l" u2 G. e8 Y7 b3 mPublic Function Encode(ByVal pStrMessage)
! B) L9 v9 K* }Dim lLngIndex
3 C* E5 I0 D! i3 ~+ s3 }/ c# W. eDim lLngMaxIndex
/ H, v9 n. R9 z& W. sDim lBytAscii
: T7 F4 h" d2 ~$ i/ n* yDim lLngEncrypted ) T% t3 `4 a+ S2 u  _# p. a# W7 p
lLngMaxIndex = Len(pStrMessage)
2 \2 n$ I8 ~* \, fIf lLngMaxIndex = 0 Then Exit Function 6 Z7 [. y+ j! l
For lLngIndex = 1 To lLngMaxIndex : F# \1 K2 x6 q. ~/ N" [  |
lBytAscii = Asc(Mid(pStrMessage, lLngIndex, 1)) ( r4 l' k& D" d  Z8 i
lLngEncrypted = Crypt(lBytAscii, PublicKey)
. O; v, Q4 b  [! i, h$ x. rEncode = Encode & NumberToHex(lLngEncrypted, 4) 0 v) K6 z( ?" V8 x2 H
Next
) l6 C9 o9 e0 C9 q' ]" Y) Q* R% BEnd Function
. Z6 z4 r5 j; J# u. g7 v3 G5 kPublic Function Decode(ByVal pStrMessage)
: ]1 ^7 O, q5 H, u$ z, Q: wDim lBytAscii
) H& e# {3 t1 p3 QDim lLngIndex
& R: h7 S' n, U' IDim lLngMaxIndex 4 w3 ^$ M6 Y1 @/ K
Dim lLngEncryptedData # x: }$ Y' p2 B" C* Z( Z
Decode = "" 0 f( f2 C! M8 \
lLngMaxIndex = Len(pStrMessage)
# T6 Z% w2 f: a: vFor lLngIndex = 1 To lLngMaxIndex Step 4 : N- ~8 E$ ?+ K: H% L
lLngEncryptedData = HexToNumber(Mid(pStrMessage, lLngIndex, 4))
# h6 y4 T/ p: z# }  flBytAscii = Crypt(lLngEncryptedData, PrivateKey) ' {9 R$ J9 |9 f3 V: F* [
Decode = Decode & Chr(lBytAscii)
. _0 J- Y$ E3 i( ^: a  c2 D# XNext
5 i+ o  M; s' |7 j2 _' A/ bEnd Function
; O' t4 m$ @& O4 c/ GPrivate Function NumberToHex(ByRef pLngNumber, ByRef pLngLength)
* |8 q9 Q0 I  z* O- dNumberToHex = Right(String(pLngLength, "0") & Hex(pLngNumber), pLngLength) 1 @. T5 H& I' Q- O- B
End Function 7 }. W5 y! O8 C0 ~% ^
Private Function HexToNumber(ByRef pStrHex) 1 G& v  @8 {1 V! R$ X
HexToNumber = CLng("&h" & pStrHex) 3 x' r: K8 `1 [
End Function " y& p% G" G: u* c& h
End Class
% C' G4 [; J( ]function Encryptstr(Message) 8 @& R7 o# I& K# A' ?
Dim LngKeyE 5 b" t( z9 o! f3 W$ ]! A
Dim LngKeyD
" a/ B! l, e& @- m/ @, oDim LngKeyN 4 j) X! \) J( B/ [* l
Dim StrMessage
9 n+ i& h4 k% {" nDim ObjRSA # [; w4 I. ]/ v2 u
LngKeyE = "32823"
; K9 R6 n6 A) zLngKeyD = "20643"
  O! F( O6 ~* q/ ~5 Z- HLngKeyN = "29893" 0 \# x5 }! T6 X( T- u1 d' X
StrMessage = Message - o( V- J1 k1 }2 G4 p, \
Set ObjRSA = New clsRSA
( i5 l4 ^- \, `; M5 n8 aObjRSA.PublicKey = LngKeyE 8 y$ N% [7 \: w7 d8 d
ObjRSA.Modulus = LngKeyN 7 O8 A+ s& `) t+ ~# m
Encryptstr = ObjRSA.Encode(StrMessage) 2 _7 i4 J2 r' k( {% H
Set ObjRSA = Nothing - D1 J# g: Y! W8 h+ U
end function. N; l7 W, l3 W3 q
Function Decryptstr(Message)
* t! Q; y- S7 M% g0 y' nDim LngKeyE
/ E; T8 ?0 M$ LDim LngKeyD : t' k5 L, p% g/ \. O
Dim LngKeyN
" x2 _" e0 g& ]Dim StrMessage
  S8 B1 i" N# m; I6 o5 B7 R; w& r# G& KDim ObjRSA
6 y, w! V2 ^' U  |0 o+ X9 BLngKeyE = "32823"
# h/ o. d$ @: k- U. BLngKeyD = "20643" " F% x8 i2 p: m1 _
LngKeyN = "29893" # j! f) Q- Q3 u- D$ O% \# [" ~8 B
StrMessage = Message
' H+ Q- }) j5 |Set ObjRSA = New clsRSA
; t. Y' k& @' a% s0 X  DObjRSA.PrivateKey =LngKeyD
) T# _$ U! S+ e3 a3 S* |3 C' fObjRSA.Modulus=LngKeyN & q) x' K' m3 Y+ Y2 x/ }- u
decryptstr=ObjRSA.Decode(StrMessage) 4 K3 Y% @* {9 r8 d# c" v
Set ObjRSA = Nothing
$ @! Z% u5 r; Eend function ; `! k- h7 h5 ~! j2 ^1 Q
%>4 e* V+ [- W; ?, K) J
===============================================
( E- H' x$ f7 _7 a; v3 r$ J+ ]; r  m* S/ b+ a9 f" w" c2 [6 c1 u$ B
还有一个用于测试这段代码的test.asp
, @9 Q% e0 u; ?4 o有兴趣的自己搭建个IIS测试下
, p, E7 _3 e* r' Q; j" O. y7 I) V9 c# e<!--#INCLUDE FILE="RSA.asp"-->
) g5 V! `9 g) f8 Q<%$ m3 b( |5 \* Y& s: K
function Encryptstr(Message) % c$ @; Y3 T0 G6 P
Dim LngKeyE
! C1 J8 a: Z7 `+ vDim LngKeyD + ?8 E& a; M0 `% E* I
Dim LngKeyN   Q7 Z2 ?- a/ y
Dim StrMessage + Y( c+ z1 X. }) y5 F3 [
Dim ObjRSA 5 }$ S- x: a8 Z3 r* V4 Q
LngKeyE = "32823"
" A- `0 w) m! sLngKeyD = "20643" ; D, c2 O8 ?5 [
LngKeyN = "29893"
( D+ p; b7 d( Y% T1 q* N6 W, Z) `StrMessage = Message , Q+ a2 y2 Q9 ~7 H4 v9 V! O
Set ObjRSA = New clsRSA 9 `  g2 Q) d6 n* u. y
ObjRSA.PublicKey = LngKeyE ; @3 @: f/ E. F, R8 u# Y
ObjRSA.Modulus = LngKeyN
4 f# a% i1 q. m  J; SEncryptstr = ObjRSA.Encode(StrMessage) # N( X7 \* ~) w1 y1 u7 O
Set ObjRSA = Nothing
! l% l' ^9 a( W$ |# Fend function : I9 ~. V) f4 J6 y) i4 K& E& m  r
function decryptstr(Message) , ^% Z, H, z8 }) a2 ?
Dim LngKeyE 4 y$ A- X% _/ X7 z* d7 j
Dim LngKeyD 8 v# D. l; g/ P0 E, K! D$ Y
Dim LngKeyN . ?* b' w8 B5 g0 A7 B, R
Dim StrMessage
: s* d! p3 T+ u; o; {Dim ObjRSA ) L0 Z! o7 N7 k7 P: R
LngKeyE = "32823"
! g' X& p, ~: Z2 l/ _2 ^LngKeyD = "20643" 0 |; e1 K& y0 \2 }
LngKeyN = "29893" " {9 @! D9 E4 ^
StrMessage = Message + I: f% Y+ n: Z8 a0 f' }
Set ObjRSA = New clsRSA : U* Y- [/ K8 a/ [4 t
ObjRSA.PrivateKey =LngKeyD
+ S9 b, ]! a( b/ D* ]! aObjRSA.Modulus=LngKeyN / s5 n5 v  C9 h  Z; K# i
decryptstr=ObjRSA.Decode(StrMessage) + e. X. K, ^+ Y2 H) x! ~$ z
Set ObjRSA = Nothing 8 `: q' z) m2 h2 x% D5 S# {
end function
" U& ?- ?; |7 v1 T% zdim last,first
' h6 y/ ]$ i2 c. D8 \% |first="!@#$%^&*()"
$ [! e7 f3 P; e7 ~7 oResponse.Write "加密前为:"&first
* v% c: P" A% P+ m5 C' ?1 wlast=Encryptstr(first) * x% C) w2 }, H; @8 f& c3 n
Response.Write "加密后为"&last - _8 ~8 [. w2 p- q  x: j9 s
Response.Write "解密后为" &decryptstr(last) $ E* ~) [, n6 M" s7 M8 [8 y
%> ==============================================# u0 V" z( I" Y, T" j% J/ s! i
剩下的就是字符的对照表了
( b# u8 @/ z2 O/ m' Z+ I% s===================字符集================
$ `9 M% G3 r  I* w1_____6EBB5 y1 N8 M# C4 q; t/ A* }8 ^+ \
2_____5C1F% H7 V/ K3 N% q( K, B2 c5 r" P; r* P
3_____4D75& b" F& x( b& m+ C! P( s/ j3 h( b% @
4_____26CC. K% }1 d1 ?! q  B
5_____4F88- j( [. G" S* @1 n1 v: C
6_____3F4E
3 Z+ D, ~) Q! Z3 T, ~# {7_____0A9D3 {5 G" ?$ @) |/ }% ^
8_____1A1C
1 R( }/ T) @* i9_____6D204 d6 |+ I1 l: N" S0 G
0_____1089' o- T6 j( B+ J' s; l
a_____0F3E
( {& i9 l, l' nb_____3159
- `( m2 W; Q# S; Fc_____3517, M6 f( v+ k7 H# o6 F: K& p
d_____419C& O: [* W8 v) @9 K# r. P
e_____615C2 }7 }: i& n% O6 \
f_____556F
: J4 ~, P2 s  A& x' J, ?" }g_____2B7F
1 A: t4 U& o' ~5 S! E# s. P& Kh_____0F9C1 q! U8 ]) y* I1 G
i_____00FA
2 f  A. H' l. w( r( n0 w( C' vj_____5A50
- m  K- V9 [" q; I9 ]k_____28504 f( f9 X1 ]& r9 v
l_____3E7B8 d6 `9 [/ @4 O* \7 V; e: O
m_____71C5! j  z: X+ W% @% ]+ B
n_____1FC8
# Z6 i- ~" A% c0 R4 P+ Yo_____74C1
- J# i6 r, x( ?. u8 t% tp_____5FB8
/ l, G- i* i* \$ g2 z, yq_____6085. }" ?7 S$ Y5 r, g
r_____3AC4
6 M- c# H; A3 Ws_____2F50/ Q# ^; q1 _7 ?& M
t_____36F8
$ g& e$ s2 d6 O8 {- _u_____7010' Q2 x. d" `( H9 H5 L3 s
v_____0B42
3 o% \9 M' n* y2 r' G8 kw_____1C7A! @  ?. A7 |1 S4 D3 c& a
x_____16F8
! e$ t! b7 _7 x* B6 ?2 c( W+ Ly_____2EE7/ k+ ~" I1 R/ u7 r
z_____5CF3. ]: h, u7 N. `6 d- j2 ~
!_____6233
: N' G3 y9 z- G0 ^4 H: R5 E@_____3A45  e  u1 z! S7 Z$ g
#_____2291
; x- @/ d2 A4 j$_____5D5C* C7 Z8 s) ~0 H* T4 @
%_____09B9
, J1 H) Q$ g6 W/ M; \^_____43EA
3 U  \* B) Z; E" d3 W&_____62B9
/ R1 h  i5 I4 s*_____6301
: ^. n0 n- L1 r) ^(_____4659
/ U7 ^6 |0 W! O7 p. S8 b3 C4 _)_____5C82
希望做站长本人的学生请点击
http://www.3ast.com/viewthread.php?tid=13841
QQ790653916只负责SEO以及收费教学等方面联系,他人勿扰

于智者同行,你会不同凡响;与高人为伍,你会登上巅峰

收藏了。。。。。。。。

TOP

返回列表