返回列表 发帖

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

原创作者:柔肠寸断 [3.A.S.T]  http://www.3ast.com.cm
( ^. m% x8 e2 }. w原始出处:http://www.3ast.com.cm+ y( r2 a3 E* [' Q+ J. Q: m5 h: L

' M6 z$ c0 u- ]1 i看不懂的直接绕过; O5 u4 u8 T# g
加密前为:hwy123456
' @8 a$ a4 Z8 M+ i/ R加密后为0F9C1C7A2EE76EBB5C1F4D7526CC4F883F4E
0 [' r8 _% `  ?, A) c6 }, e: g. E6 W+ V/ h$ Z, l: E" @5 D
============================================! t& ?3 G) X# Z$ _7 Y/ O* A4 F' @
上面是当时自己校内的心情。现在已经解破出来了,分享给大家6 @; ~, C  t2 O, ~% l+ s  T) V
也就不隐瞒大家什么了,这个是国内某知名大学的后台加密算法
- k  z. E  }# Q; B* p1 x; R8 Y以下是RSA算法文件
, |( F7 \: Q4 c2 ^
3 o3 G) T! a2 c% Y5 C0 r0 _& I2 @文件名RSA.ASP
6 s; T0 G" u9 @, u===============================================
  q$ l; Z3 a. S' u) O<% ( \0 y) N) ?% ?; n
Class clsRSA / r) @; n/ g: Z: i
Public PrivateKey
3 t7 ]6 e* o! g% vPublic PublicKey + s2 Y- B0 {! K/ W( `8 X8 P
Public Modulus 4 _! \) Q# Q" x
Public Function Crypt(pLngMessage, pLngKey)
' v$ G' K) b  E7 t' ]1 SOn Error Resume Next $ {' @( G) u8 f+ e
Dim lLngMod
' C& [/ a$ H  L5 Q9 _Dim lLngResult
  T# v$ p0 H" H( U4 y" zDim lLngIndex ; D9 r9 I9 K% K+ ]
If pLngKey Mod 2 = 0 Then
/ u; k& Q' b* d0 a8 Q1 b: D! Y/ klLngResult = 1
6 M, I1 ~1 V+ n. tFor lLngIndex = 1 To pLngKey / 2 * x' {8 O* n* b
lLngMod = (pLngMessage ^ 2) Mod Modulus ! Z# @: w5 }5 T
' Mod may error on key generation
) \, K, [( v; d5 Z0 F0 O2 HlLngResult = (lLngMod * lLngResult) Mod Modulus 2 S4 p+ [2 ^  v3 K; u8 o
If Err Then Exit Function
* R# B4 {/ C7 {# Z& I2 ?Next
) ], \* H) g5 G' g. a2 mElse - ~7 M5 M! w& O. W# z! }
lLngResult = pLngMessage   p6 j; M/ u' i  c" E4 r/ ?- U
For lLngIndex = 1 To pLngKey / 2
- Y' l0 S1 ^$ ZlLngMod = (pLngMessage ^ 2) Mod Modulus 1 ]6 M4 }! T& f/ s
On Error Resume Next
1 K- }0 ~5 a! {- n1 W9 q; t' Mod may error on key generation 8 I* V- }4 Z" h8 ^5 f
lLngResult = (lLngMod * lLngResult) Mod Modulus
) v8 y; [3 v& A1 c- \2 G" m9 @If Err Then Exit Function ( {: A9 f( [/ z  ^* g- ]
Next 9 z% i$ \( X# Q4 M( h
End If 9 X) R2 g# Q7 R& S  ]
Crypt = lLngResult % b/ X; W* i4 f/ B( V( _* w4 j3 |$ ]
End Function: H7 z6 o+ \& i+ C& B

! B3 l# p2 J* ^0 I' p( e+ TPublic Function Encode(ByVal pStrMessage)
( K# \: {: E: ]5 @- zDim lLngIndex 6 V* f9 a% V, h" ?
Dim lLngMaxIndex . e% c" K, o7 B; b% v6 N: D! `
Dim lBytAscii + m: M& c) {1 _
Dim lLngEncrypted 6 Q$ U/ Q# v) d  [. R9 [
lLngMaxIndex = Len(pStrMessage) 7 \$ L, `5 w: B, J
If lLngMaxIndex = 0 Then Exit Function * |. K) Y+ x" l
For lLngIndex = 1 To lLngMaxIndex
$ h9 v' O+ C4 K4 X2 VlBytAscii = Asc(Mid(pStrMessage, lLngIndex, 1))
/ F9 _  O- k7 q0 N+ nlLngEncrypted = Crypt(lBytAscii, PublicKey) - T# J; s9 ?2 Q1 y8 @- M0 G
Encode = Encode & NumberToHex(lLngEncrypted, 4)
; r% t9 S  Z+ q$ o: uNext 1 ^9 E! O2 K3 n2 J5 ]) X/ F
End Function # ^. U# e, L7 O3 \5 r
Public Function Decode(ByVal pStrMessage) 9 ~2 e3 D. `4 H
Dim lBytAscii
% @6 {4 s( w5 p$ L: gDim lLngIndex ' S4 c& T, V. A  }8 g- ?7 M
Dim lLngMaxIndex
9 Y/ n* U) f# ~( FDim lLngEncryptedData
' C1 X8 J* X0 r# p, @0 s/ r' ^7 FDecode = "" / D7 S! f( H  T) i2 O
lLngMaxIndex = Len(pStrMessage) 7 [: b# y" {3 B; M4 S) S7 {
For lLngIndex = 1 To lLngMaxIndex Step 4 ! y0 y* e" v) j3 k
lLngEncryptedData = HexToNumber(Mid(pStrMessage, lLngIndex, 4)) : ]5 w  @( D: v/ V; g2 o# X5 m
lBytAscii = Crypt(lLngEncryptedData, PrivateKey)
& X, f' h# M9 i6 ?5 bDecode = Decode & Chr(lBytAscii) , ]5 ?) ^: ]# v7 e, D
Next
6 t& N- i4 u2 ?/ s7 OEnd Function
) S, u+ t3 G( |- {Private Function NumberToHex(ByRef pLngNumber, ByRef pLngLength) 5 A( W7 x9 D- }
NumberToHex = Right(String(pLngLength, "0") & Hex(pLngNumber), pLngLength)
  X  f0 \1 L" `- {End Function : \1 z; d3 a  w( ?
Private Function HexToNumber(ByRef pStrHex) 5 l6 b- Y& y5 R( Q
HexToNumber = CLng("&h" & pStrHex)
, ^: D* M2 O1 B# S) XEnd Function ! n5 O, R  y" G9 ?7 [4 Z; v
End Class . f  u( p) I4 }; J( u; A, g6 s4 E/ B
function Encryptstr(Message)
& }! y1 G" A" ]$ ^, HDim LngKeyE
4 m/ @! H( f# I5 O0 M6 J1 xDim LngKeyD 8 S+ v: L' Z# E9 i& u5 E* z0 Z
Dim LngKeyN , p" q0 W# N2 M) r' |
Dim StrMessage 5 E8 c/ f6 y$ y0 _
Dim ObjRSA
( @8 {/ `# }; n. K3 s7 i8 `& JLngKeyE = "32823" , {, y% k& K& N6 ^
LngKeyD = "20643" 2 p! M! A, |3 ]
LngKeyN = "29893" * n2 ]3 k, ]1 x2 A! v0 P9 A9 y0 f
StrMessage = Message ' o* D4 _+ y7 e0 n' n% Z. t5 M/ W
Set ObjRSA = New clsRSA
5 r. c+ J, G/ C9 s3 y! a# xObjRSA.PublicKey = LngKeyE
" b5 G8 I( }4 c/ z" E- ]( oObjRSA.Modulus = LngKeyN 9 b$ y! E8 Q/ r6 n5 x
Encryptstr = ObjRSA.Encode(StrMessage)
0 f& {* c9 x% a: ]) P9 o2 ISet ObjRSA = Nothing
# z7 c! |3 Z! k& pend function
9 Z& H- D. i; K! b: GFunction Decryptstr(Message) ( o9 {7 l% J4 d! N
Dim LngKeyE
/ _( z+ D+ m, Z! |) E' iDim LngKeyD 9 n& L. r" s0 Y( P3 f! b" p+ h
Dim LngKeyN , t$ Y  {" H* ~& Q) U6 L
Dim StrMessage 3 z/ X1 R1 Q8 H
Dim ObjRSA
8 y" [2 y4 [' e' FLngKeyE = "32823"
6 N' H' S$ l# jLngKeyD = "20643" 8 G! x2 T% v1 ]4 w
LngKeyN = "29893"
+ b; l; z/ Y2 O3 R; W5 T+ |8 SStrMessage = Message
  P5 i) y6 P8 e# Z. d$ u. @/ b: gSet ObjRSA = New clsRSA 5 Z* t/ U! g$ G& o) @# P
ObjRSA.PrivateKey =LngKeyD & B  E5 o$ b: G* O0 T
ObjRSA.Modulus=LngKeyN . {0 @5 r8 U* w7 Q
decryptstr=ObjRSA.Decode(StrMessage) 2 G/ a* U" d; {1 a
Set ObjRSA = Nothing % g1 o+ ]2 J# s3 ~5 C# z
end function
: T: Q3 V8 F# {4 r%>
1 V2 \* \* o# ]6 }: L===============================================0 J3 ?* A- O. F  k$ ?, w8 ?

9 H. r' X+ h# l7 p7 S- N还有一个用于测试这段代码的test.asp0 {9 j" I/ f$ B% j1 a/ j6 p
有兴趣的自己搭建个IIS测试下" Q; d; q+ `( Q$ F
<!--#INCLUDE FILE="RSA.asp"--> $ i& P7 X7 }) k9 C7 ~
<%
3 R) r+ _* s2 b- wfunction Encryptstr(Message)
7 \# i& r- L% ?+ bDim LngKeyE
2 H" n& [0 S  e7 Y9 f0 Z3 MDim LngKeyD
/ L. M" [1 O$ a! LDim LngKeyN . x' ~2 Q0 z. X9 b+ M; U7 c
Dim StrMessage 5 O/ R# a& v: L; y) J8 N
Dim ObjRSA + q7 T4 F1 c8 r
LngKeyE = "32823" - `/ ]$ f5 f3 a% S! k" _8 G
LngKeyD = "20643" 5 K( b/ Q9 e; c& ^: O% i
LngKeyN = "29893"
  H* n1 U; \9 e5 d- W+ {( ^0 oStrMessage = Message
8 H' ?1 R* O$ q: n5 o, [0 [Set ObjRSA = New clsRSA
9 Z7 b, ^+ Q, MObjRSA.PublicKey = LngKeyE
) |/ o- P& }. LObjRSA.Modulus = LngKeyN
  M: M! y6 z2 w+ A, X* \Encryptstr = ObjRSA.Encode(StrMessage)
; w: Z0 r8 G7 B, B0 ~* CSet ObjRSA = Nothing ) V1 ?9 t+ q% y: M
end function - g( a+ t7 ?- n: u) _/ N
function decryptstr(Message) 6 \) X7 }, \. ?
Dim LngKeyE # d+ L3 E2 C+ o0 f3 _- d# v
Dim LngKeyD
5 x# O; J& n( Q% \' }" pDim LngKeyN 1 M  v9 f: W( @9 J+ |
Dim StrMessage 5 l8 l8 y$ P& a* i3 G  m
Dim ObjRSA % X+ S+ b6 V1 T  _- a- H
LngKeyE = "32823" ( W  u4 G% z3 W' E% _2 }
LngKeyD = "20643"
' g' K1 n4 C2 u" f2 n- nLngKeyN = "29893"
6 _7 o7 v$ f' ?+ I  K# o; ~4 ~StrMessage = Message
  ~) S- l4 _& L8 ~Set ObjRSA = New clsRSA 9 z  @4 t; C, G6 D4 \$ l9 j
ObjRSA.PrivateKey =LngKeyD
, _  m1 Z% }& ?7 ?ObjRSA.Modulus=LngKeyN : F! X) M8 u' v/ y+ k9 f- G" E
decryptstr=ObjRSA.Decode(StrMessage)
+ W2 q, O3 j+ {  i! b# }6 gSet ObjRSA = Nothing 4 E% s( S7 Z. J7 W, @+ I+ n- \; {& S
end function ; ]! b! x4 k" e0 s
dim last,first
! D# c( L: M( A/ e8 `4 n8 Ufirst="!@#$%^&*()" & E/ k* U  U9 Y! K
Response.Write "加密前为:"&first
" C3 V6 |2 U2 `- |* Plast=Encryptstr(first)
3 U' r' S# G1 R" yResponse.Write "加密后为"&last
. s5 D9 F: U% a: N( {Response.Write "解密后为" &decryptstr(last)
" C& j' ]3 V6 f  H2 r& s- ]9 U8 g%> ==============================================7 |: T- f1 ^6 I1 g: {
剩下的就是字符的对照表了
1 s2 `6 ^' v; R5 X1 I===================字符集================9 R, U0 U. H* t( X3 B' `1 n* ]
1_____6EBB
5 a  w3 i) T* c2_____5C1F) b1 J' V; Q' `
3_____4D75
: B0 v  l* G7 T2 ?4_____26CC
. F7 I" r  \  x4 z9 b  a1 H+ ]5_____4F88
# R; D& N) {" ]* G6_____3F4E- a  U4 N! a& f
7_____0A9D
3 l6 f6 b, c& x8_____1A1C
# q3 L1 e8 n+ l9 e  I3 i+ h0 s: j' y8 F9_____6D20
+ X2 O! p0 x* {0 n2 {, R0_____1089
% j/ k3 j2 y# J2 fa_____0F3E* o4 Y- O4 k/ f6 N- Q8 @
b_____3159
2 v6 f/ u. h' U& Pc_____3517
+ }6 o; L2 T0 T7 l2 @1 Yd_____419C3 d7 [- `; x, B! h
e_____615C! z5 p$ w8 A- S
f_____556F
* y& ]) q; n! E8 tg_____2B7F
9 ?$ J, G; c0 @) C. B  |h_____0F9C
+ o8 K  B2 m) ni_____00FA
+ t/ H! N5 b+ G9 G8 D$ s1 vj_____5A501 `% o: z  B8 z5 _+ {
k_____2850$ }" h2 R5 u  B. g9 V
l_____3E7B! c: S6 C2 }7 W! q6 L$ q- [
m_____71C5  S5 G( \. ?, l
n_____1FC83 g2 p. j5 b8 O" l
o_____74C1
& k' w# N5 v/ B8 c5 Qp_____5FB8
3 o7 P1 u7 o' z6 ]1 l5 R2 sq_____6085
5 g: v; \8 Q, C- }+ p0 Tr_____3AC4% X+ n7 K; p. d% d& L
s_____2F50
- l( x( y" Z$ `' f+ Mt_____36F8' L' H) D* q! W" F  _
u_____7010
1 i1 L' @+ ]; u+ ~v_____0B42
7 ?* \. k. Q/ e7 sw_____1C7A2 ?* y. P  K' d7 p
x_____16F8' k/ |1 t7 z2 O: ?
y_____2EE7. R" x2 ^% i5 `" h* K
z_____5CF3
7 N# G) H, a. Y5 J! m, s!_____6233! L+ t! N8 o3 {/ v! S0 ]  m
@_____3A45
% j$ O, e+ _0 t#_____2291
# Q; t: f: p4 [% m/ u) p$_____5D5C8 g2 n% N) r& Y% z  k% s
%_____09B90 e' L: J: S  B' g: h, Y/ r
^_____43EA
& u& n5 V6 S9 z7 m8 j- R&_____62B9
( E9 ]6 Y' b1 s+ {*_____6301; r. h0 O8 t; x: T3 H1 I2 c; E
(_____4659
  o- R) e7 u1 [1 f)_____5C82
希望做站长本人的学生请点击
http://www.3ast.com/viewthread.php?tid=13841
QQ790653916只负责SEO以及收费教学等方面联系,他人勿扰

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

收藏了。。。。。。。。

TOP

返回列表