|
- public class JavaCrackMe03 { 5 {, B2 S9 E1 N2 j% J4 c3 L- Z
- public static char[] szSrc = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
# l+ \$ `4 w+ z7 X1 A& W; N - public static char[] szKey = new char[]{'b', 'f', 'd', 'j', 'z', 'e', 'r', 'm', 'i', 'a', 'k', 'x', 'v', 'h', 'c', 'g', 'o', 'p', 'l', 'q', 's', 'n', 't', 'u', 'w', 'y'};
) L" B# ~5 i9 Z s+ C - public static int getIndex(char[] arr, char ch) { 7 h, {, Q7 j2 \, E s
- for(int i = 0; i < arr.length; ++i) {
( m/ W1 {, j/ {1 b! }" t - if(ch == arr[i]) {
2 _; ^" G R0 ?# T- U4 } - return i;
, ^& @3 s( A; d1 D6 S6 p4 F6 h1 p - } % x2 \7 q6 x+ f1 G8 ]
- } : }# |; t- S1 ?4 A4 j
- return -1; % Z+ Q/ }3 ^, S5 w! r9 d
- } 8 ?9 ~* \7 e' \2 g% v
- public static String encode(String string) { 9 a, K- W( }/ H
- StringBuffer stringbuffer = new StringBuffer();
& M( a/ D' K& V; k - for(int i = 0; i < string.length(); ++i) {0 g# H8 k. }! k- W) J
- char ch = string.charAt(i); 1 c: F! g) a1 k1 D- l
- int m = getIndex(szSrc, ch);5 x7 f5 M2 ~0 g7 Q% t
- stringbuffer.append(szKey[m]); # N3 H% L3 S5 e
- }
7 d; z0 K6 [) J5 b6 E# _# B; A - System.out.println("密文:" + stringbuffer);
& d5 R i; C! J3 O& D7 ?& h: K - return new String(stringbuffer);, o* U5 p+ Y" C7 G0 `4 L" U& l3 T& d
- } , R2 y, s; }+ g; |9 B& e5 E
- public static String DeCode(String string) {
1 M6 P) J8 K. `4 a: R - StringBuffer stringbuffer = new StringBuffer();
, e) x8 s' l i8 R* J& u! s( E - for(int i = 0; i < string.length(); ++i) {
Z& W1 M- Y$ J9 n - char ch = string.charAt(i);
* ?7 d5 C# v' X2 U8 K - int m = getIndex(szKey, ch);
3 Y# }$ V' f6 Q1 i - stringbuffer.append(szSrc[m]);
' `& T T% U+ Z7 p: S0 x: H - } $ m/ M# t- d/ Y( B. D( i( H& Q
- System.out.println("明文:" + stringbuffer);$ x/ _& H+ o* u% l( Y0 G \
- return new String(stringbuffer);
9 Q) f* D7 p# |0 H$ T6 ^8 g - } ' `* \/ V- C1 V) P4 P9 k
- public static void main(String []args)
/ {" V2 _- w- a - { ( t" O8 l* w% M6 A0 Z, q
- encode("java");
/ e4 ]6 t7 A: K' R9 M - DeCode("abnb");
7 f" \$ l; o3 Q$ _$ M$ ? - }- i$ d/ F+ c+ t- V Y
- }
" j: E4 E8 F1 {. Q
复制代码 |
|