KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > connection > StandardScrambler


1 /*****************************************************************************
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14
15  * The Original Software is the CVS Client Library.
16  * The Initial Developer of the Original Software is Robert Greig.
17  * Portions created by Robert Greig are Copyright (C) 2000.
18  * All Rights Reserved.
19
20  * Contributor(s): Robert Greig.
21  *****************************************************************************/

22 package org.netbeans.lib.cvsclient.connection;
23
24 /**
25  * Scrambles text (the password) using the standard scheme described in the
26  * CVS protocol version 1.10. This encoding is trivial and should not be
27  * used for security, but rather as a mechanism for avoiding inadvertant
28  * compromise.
29  * @author Robert Greig
30  */

31 public class StandardScrambler implements Scrambler {
32     /**
33      * The mapping array
34      */

35     private int[] shifts;
36
37     /**
38      * The single instance of this class (Singleton design pattern)
39      */

40     public static StandardScrambler instance;
41
42     /**
43      * Do not instantiate the scrambler directly. Use the getInstance() method
44      */

45     private StandardScrambler() {
46         int i;
47         shifts = new int[256];
48
49         for (i = 0; i < 32; ++i) {
50             shifts[i] = i;
51         }
52
53         shifts[i++] = 114;
54         shifts[i++] = 120;
55         shifts[i++] = 53;
56         shifts[i++] = 79;
57         shifts[i++] = 96;
58         shifts[i++] = 109;
59         shifts[i++] = 72;
60         shifts[i++] = 108;
61         shifts[i++] = 70;
62         shifts[i++] = 64;
63         shifts[i++] = 76;
64         shifts[i++] = 67;
65         shifts[i++] = 116;
66         shifts[i++] = 74;
67         shifts[i++] = 68;
68         shifts[i++] = 87;
69         shifts[i++] = 111;
70         shifts[i++] = 52;
71         shifts[i++] = 75;
72         shifts[i++] = 119;
73         shifts[i++] = 49;
74         shifts[i++] = 34;
75         shifts[i++] = 82;
76         shifts[i++] = 81;
77         shifts[i++] = 95;
78         shifts[i++] = 65;
79         shifts[i++] = 112;
80         shifts[i++] = 86;
81         shifts[i++] = 118;
82         shifts[i++] = 110;
83         shifts[i++] = 122;
84         shifts[i++] = 105;
85         shifts[i++] = 41;
86         shifts[i++] = 57;
87         shifts[i++] = 83;
88         shifts[i++] = 43;
89         shifts[i++] = 46;
90         shifts[i++] = 102;
91         shifts[i++] = 40;
92         shifts[i++] = 89;
93         shifts[i++] = 38;
94         shifts[i++] = 103;
95         shifts[i++] = 45;
96         shifts[i++] = 50;
97         shifts[i++] = 42;
98         shifts[i++] = 123;
99         shifts[i++] = 91;
100         shifts[i++] = 35;
101         shifts[i++] = 125;
102         shifts[i++] = 55;
103         shifts[i++] = 54;
104         shifts[i++] = 66;
105         shifts[i++] = 124;
106         shifts[i++] = 126;
107         shifts[i++] = 59;
108         shifts[i++] = 47;
109         shifts[i++] = 92;
110         shifts[i++] = 71;
111         shifts[i++] = 115;
112         shifts[i++] = 78;
113         shifts[i++] = 88;
114         shifts[i++] = 107;
115         shifts[i++] = 106;
116         shifts[i++] = 56;
117         shifts[i++] = 36;
118         shifts[i++] = 121;
119         shifts[i++] = 117;
120         shifts[i++] = 104;
121         shifts[i++] = 101;
122         shifts[i++] = 100;
123         shifts[i++] = 69;
124         shifts[i++] = 73;
125         shifts[i++] = 99;
126         shifts[i++] = 63;
127         shifts[i++] = 94;
128         shifts[i++] = 93;
129         shifts[i++] = 39;
130         shifts[i++] = 37;
131         shifts[i++] = 61;
132         shifts[i++] = 48;
133         shifts[i++] = 58;
134         shifts[i++] = 113;
135         shifts[i++] = 32;
136         shifts[i++] = 90;
137         shifts[i++] = 44;
138         shifts[i++] = 98;
139         shifts[i++] = 60;
140         shifts[i++] = 51;
141         shifts[i++] = 33;
142         shifts[i++] = 97;
143         shifts[i++] = 62;
144         shifts[i++] = 77;
145         shifts[i++] = 84;
146         shifts[i++] = 80;
147         shifts[i++] = 85;
148         shifts[i++] = 223;
149         shifts[i++] = 225;
150         shifts[i++] = 216;
151         shifts[i++] = 187;
152         shifts[i++] = 166;
153         shifts[i++] = 229;
154         shifts[i++] = 189;
155         shifts[i++] = 222;
156         shifts[i++] = 188;
157         shifts[i++] = 141;
158         shifts[i++] = 249;
159         shifts[i++] = 148;
160         shifts[i++] = 200;
161         shifts[i++] = 184;
162         shifts[i++] = 136;
163         shifts[i++] = 248;
164         shifts[i++] = 190;
165         shifts[i++] = 199;
166         shifts[i++] = 170;
167         shifts[i++] = 181;
168         shifts[i++] = 204;
169         shifts[i++] = 138;
170         shifts[i++] = 232;
171         shifts[i++] = 218;
172         shifts[i++] = 183;
173         shifts[i++] = 255;
174         shifts[i++] = 234;
175         shifts[i++] = 220;
176         shifts[i++] = 247;
177         shifts[i++] = 213;
178         shifts[i++] = 203;
179         shifts[i++] = 226;
180         shifts[i++] = 193;
181         shifts[i++] = 174;
182         shifts[i++] = 172;
183         shifts[i++] = 228;
184         shifts[i++] = 252;
185         shifts[i++] = 217;
186         shifts[i++] = 201;
187         shifts[i++] = 131;
188         shifts[i++] = 230;
189         shifts[i++] = 197;
190         shifts[i++] = 211;
191         shifts[i++] = 145;
192         shifts[i++] = 238;
193         shifts[i++] = 161;
194         shifts[i++] = 179;
195         shifts[i++] = 160;
196         shifts[i++] = 212;
197         shifts[i++] = 207;
198         shifts[i++] = 221;
199         shifts[i++] = 254;
200         shifts[i++] = 173;
201         shifts[i++] = 202;
202         shifts[i++] = 146;
203         shifts[i++] = 224;
204         shifts[i++] = 151;
205         shifts[i++] = 140;
206         shifts[i++] = 196;
207         shifts[i++] = 205;
208         shifts[i++] = 130;
209         shifts[i++] = 135;
210         shifts[i++] = 133;
211         shifts[i++] = 143;
212         shifts[i++] = 246;
213         shifts[i++] = 192;
214         shifts[i++] = 159;
215         shifts[i++] = 244;
216         shifts[i++] = 239;
217         shifts[i++] = 185;
218         shifts[i++] = 168;
219         shifts[i++] = 215;
220         shifts[i++] = 144;
221         shifts[i++] = 139;
222         shifts[i++] = 165;
223         shifts[i++] = 180;
224         shifts[i++] = 157;
225         shifts[i++] = 147;
226         shifts[i++] = 186;
227         shifts[i++] = 214;
228         shifts[i++] = 176;
229         shifts[i++] = 227;
230         shifts[i++] = 231;
231         shifts[i++] = 219;
232         shifts[i++] = 169;
233         shifts[i++] = 175;
234         shifts[i++] = 156;
235         shifts[i++] = 206;
236         shifts[i++] = 198;
237         shifts[i++] = 129;
238         shifts[i++] = 164;
239         shifts[i++] = 150;
240         shifts[i++] = 210;
241         shifts[i++] = 154;
242         shifts[i++] = 177;
243         shifts[i++] = 134;
244         shifts[i++] = 127;
245         shifts[i++] = 182;
246         shifts[i++] = 128;
247         shifts[i++] = 158;
248         shifts[i++] = 208;
249         shifts[i++] = 162;
250         shifts[i++] = 132;
251         shifts[i++] = 167;
252         shifts[i++] = 209;
253         shifts[i++] = 149;
254         shifts[i++] = 241;
255         shifts[i++] = 153;
256         shifts[i++] = 251;
257         shifts[i++] = 237;
258         shifts[i++] = 236;
259         shifts[i++] = 171;
260         shifts[i++] = 195;
261         shifts[i++] = 243;
262         shifts[i++] = 233;
263         shifts[i++] = 253;
264         shifts[i++] = 240;
265         shifts[i++] = 194;
266         shifts[i++] = 250;
267         shifts[i++] = 191;
268         shifts[i++] = 155;
269         shifts[i++] = 142;
270         shifts[i++] = 137;
271         shifts[i++] = 245;
272         shifts[i++] = 235;
273         shifts[i++] = 163;
274         shifts[i++] = 242;
275         shifts[i++] = 178;
276         shifts[i++] = 152;
277     }
278
279     /**
280      * Get an instance of the standard scrambler
281      */

282     public static Scrambler getInstance() {
283         if (instance == null) {
284             instance = new StandardScrambler();
285         }
286         return instance;
287     }
288
289     /**
290      * Scramble text, turning it into a String of scrambled data
291      * @return a String of scrambled data
292      */

293     public String JavaDoc scramble(String JavaDoc text) {
294         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("A"); //NOI18N
295

296         if (text != null) {
297             for (int i = 0; i < text.length(); ++i) {
298                 char ch = text.charAt(i);
299                 byte newCh = (byte)(shifts[(int)ch & 255] & 255);
300                 buf.append((char)newCh);
301             }
302         }
303         return buf.toString();
304     }
305 }
306
Popular Tags