My favorites
|
Sign in
nateon-lib
Java implementation for nateon messenger
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
r3
Source path:
svn
/
trunk
/
src
/
rath
/
nateon
/
NateEncode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* @(#)NateEncode.java
*
* Copyright (c) 1998-2005 Jang-Ho Hwang,
* All Rights Reserved.
*
* $Id: NateEncode.java,v 1.1.1.1 2005/05/22 01:02:27 rath Exp $
*/
package rath.nateon;
import java.util.HashMap;
/**
* 네이트온 메신져 비밀번호 인코딩 클래스.
*
* @author Jang-Ho Hwang, rath@xrath.com
* @version 1.0.000, 2005/05/20
*/
public class NateEncode
{
private HashMap map = new HashMap();
private HashMap padMap = new HashMap();
private HashMap lenMap = new HashMap();
public NateEncode()
{
init();
}
private void init()
{
// Text map
for(int i=0; i<=7; i++)
{
map.put( String.valueOf(i), (7-i) + "d" );
padMap.put( String.valueOf(i), "01101000" );
}
map.put( "8", "fd" );
map.put( "9", "fd" );
padMap.put( "8", "01101000" );
padMap.put( "9", "01101000" );
map.put( "!", "6c" );
map.put( "@", "7a" );
map.put( "$", "3c" );
map.put( "%", "2c" );
map.put( "^", "9b" );
map.put( "&", "1c" );
map.put( "*", "dc" );
padMap.put( "!", "01100000" );
padMap.put( "@", "01100000" );
padMap.put( "$", "01100000" );
padMap.put( "%", "01100000" );
padMap.put( "^", "01100000" );
padMap.put( "&", "01100000" );
padMap.put( "*", "01100000" );
int start = 6;
for(int i='a'; i<='g'; i++)
{
map.put( String.valueOf((char)i), (start-(i-'a')) + "8");
map.put( String.valueOf((char)(i-0x20)), (start-(i-'a')) + "a");
padMap.put( String.valueOf((char)i), "01000000");
padMap.put( String.valueOf((char)(i-0x20)), "01010000");
}
start = 0x0f;
for(int i='h'; i<='o'; i++)
{
map.put( String.valueOf((char)i),
Integer.toHexString((start-(i-'h'))) + "8");
map.put( String.valueOf((char)(i-0x20)),
Integer.toHexString((start-(i-'h'))) + "a");
padMap.put( String.valueOf((char)i), "01000000");
padMap.put( String.valueOf((char)(i-0x20)), "01010000");
}
start = 7;
for(int i='p'; i<='w'; i++)
{
map.put( String.valueOf((char)i), (start-(i-'p')) + "9");
map.put( String.valueOf((char)(i-0x20)), (start-(i-'p')) + "b");
padMap.put( String.valueOf((char)i), "01001000");
padMap.put( String.valueOf((char)(i-0x20)), "01011000");
}
start = 0x0f;
for(int i='x'; i<='z'; i++)
{
map.put( String.valueOf((char)i),
Integer.toHexString((start-(i-'x'))) + "9");
map.put( String.valueOf((char)(i-0x20)),
Integer.toHexString((start-(i-'x'))) + "b");
padMap.put( String.valueOf((char)i), "01001000");
padMap.put( String.valueOf((char)(i-0x20)), "01011000");
}
// Length map
start = 3;
for(int i=20; i>=14; i--)
lenMap.put( new Integer(i), "f" + (start++) );
start = 0x0a;
for(int i=13; i>=8; i--)
lenMap.put( new Integer(i), "e" + Integer.toHexString(start++) );
lenMap.put( new Integer(7), "e0" );
lenMap.put( new Integer(6), "e1" );
}
public String encode( String password )
{
StringBuffer sb = new StringBuffer();
sb.append( lenMap.get(new Integer(password.length())) );
for(int i=0; i<password.length(); i++)
{
String s = password.substring(i, i+1);
String value = (String)map.get(s);
sb.append( value );
}
String value = sb.toString();
String lastChar = password.substring(password.length()-1, password.length());
String padRule = (String)padMap.get( lastChar );
int sum = 0;
int num = Integer.parseInt(
((String)map.get(lastChar)).substring(0, 1), 0x10 );
StringBuffer pad = new StringBuffer();
for(int i=0; i<8; i++)
{
int inc = padRule.charAt(i) - 0x30;
if( sum==0 )
{
pad.append( '0' );
if( num==0 )
pad.append('1');
else
pad.append( Integer.toHexString(num) );
sum = num;
continue;
}
sum = sum * 2 + inc;
int t = sum & 0xff;
String toAdd = Integer.toHexString(t);
if( toAdd.length()==1 )
pad.append( '0' );
pad.append(toAdd);
}
String toPad = pad.toString();
StringBuffer base = new StringBuffer();
base.append( toPad );
base.append( toPad );
base.append( toPad );
for(int i=0; i<value.length(); i++)
{
base.setCharAt(i, value.charAt(i));
}
return base.toString();
}
}
Show details
Hide details
Change log
r2
by xrathx on Nov 17, 2008
Diff
initial import
Go to:
/trunk/Test.java
/trunk/build.xml
/trunk/docs
/trunk/docs/allclasses-frame.html
/trunk/docs/allclasses-noframe.html
/trunk/docs/constant-values.html
/trunk/docs/deprecated-list.html
/trunk/docs/help-doc.html
/trunk/docs/index-files
...nk/docs/index-files/index-1.html
...k/docs/index-files/index-10.html
...k/docs/index-files/index-11.html
...k/docs/index-files/index-12.html
...k/docs/index-files/index-13.html
...k/docs/index-files/index-14.html
...k/docs/index-files/index-15.html
...k/docs/index-files/index-16.html
...nk/docs/index-files/index-2.html
...nk/docs/index-files/index-3.html
...nk/docs/index-files/index-4.html
...nk/docs/index-files/index-5.html
...nk/docs/index-files/index-6.html
...nk/docs/index-files/index-7.html
...nk/docs/index-files/index-8.html
...nk/docs/index-files/index-9.html
/trunk/docs/index.html
/trunk/docs/overview-frame.html
/trunk/docs/overview-summary.html
/trunk/docs/overview-tree.html
/trunk/docs/package-list
/trunk/docs/rath
/trunk/docs/rath/nateon
...ocs/rath/nateon/ChatChannel.html
/trunk/docs/rath/nateon/Debug.html
...rath/nateon/DispatchChannel.html
...docs/rath/nateon/NateEncode.html
...s/rath/nateon/NateOnChannel.html
...s/rath/nateon/NateOnMessage.html
...rath/nateon/NateOnMessenger.html
...k/docs/rath/nateon/NateUser.html
.../nateon/NotificationChannel.html
/trunk/docs/rath/nateon/event
.../nateon/event/NateOnAdapter.html
...nateon/event/NateOnListener.html
.../nateon/event/package-frame.html
...ateon/event/package-summary.html
...h/nateon/event/package-tree.html
...s/rath/nateon/package-frame.html
...rath/nateon/package-summary.html
...cs/rath/nateon/package-tree.html
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 4258 bytes, 161 lines
View raw file
Hosted by