001: /*
002: ** Java cvs client library package.
003: ** Copyright (c) 1997-2002 by Timothy Gerard Endres
004: **
005: ** This program is free software.
006: **
007: ** You may redistribute it and/or modify it under the terms of the GNU
008: ** Library General Public License (LGPL) as published by the Free Software
009: ** Foundation.
010: **
011: ** Version 2 of the license should be included with this distribution in
012: ** the file LICENSE.txt, as well as License.html. If the license is not
013: ** included with this distribution, you may find a copy at the FSF web
014: ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the Free
015: ** Software Foundation at 59 Temple Place - Suite 330, Boston, MA 02111 USA.
016: **
017: ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
018: ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
019: ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
020: ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
021: ** REDISTRIBUTION OF THIS SOFTWARE.
022: **
023: */
024:
025: package com.ice.cvsc;
026:
027: import java.io.*;
028: import java.lang.*;
029: import java.text.*;
030: import java.util.*;
031:
032: /**
033: * The CVSProject class implements the concept of a local
034: * CVS project directory. A local project directory can be
035: * thought of as a local source code working directory that
036: * contains a CVS directory containing CVS administration files.
037: *
038: * Combined with CVSClient; sh[i++] = this class provides everything
039: * you need to communicate with a CVS Server and maintain
040: * local working directories for CVS repositories.
041: *
042: * @version $Revision: 2.2 $
043: * @author Timothy Gerard Endres, <a href="mailto:time@ice.com">time@ice.com</a>.
044: * @see CVSClient
045: *
046: */
047:
048: /*
049: * From src/scramble.c in the cvs distribution.
050: *
051: * Map characters to each other randomly and symmetrically, A <--> B.
052: *
053: * We divide the ASCII character set into 3 domains: control chars (0
054: * thru 31), printing chars (32 through 126), and "meta"-chars (127
055: * through 255). The control chars map _to_ themselves, the printing
056: * chars map _among_ themselves, and the meta chars map _among_
057: * themselves. Why is this thus?
058: *
059: * No character in any of these domains maps to a character in another
060: * domain, because I'm not sure what characters are legal in
061: * passwords, or what tools people are likely to use to cut and paste
062: * them. It seems prudent not to introduce control or meta chars,
063: * unless the user introduced them first. And having the control
064: * chars all map to themselves insures that newline and
065: * carriage-return are safely handled.
066: *
067: static unsigned char
068: shifts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
069: 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 114, 120,
070: 53, 79, 96, 109, 72, 108, 70, 64, 76, 67, 116, 74, 68, 87, 111, 52,
071: 75, 119, 49, 34, 82, 81, 95, 65, 112, 86, 118, 110, 122, 105, 41, 57,
072: 83, 43, 46, 102, 40, 89, 38, 103, 45, 50, 42, 123, 91, 35, 125, 55,
073: 54, 66, 124, 126, 59, 47, 92, 71, 115, 78, 88, 107, 106, 56, 36, 121,
074: 117, 104, 101, 100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48, 58, 113,
075: 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85, 223, 225, 216,
076: 187, 166, 229, 189, 222, 188, 141, 249, 148, 200, 184, 136, 248, 190,
077: 199, 170, 181, 204, 138, 232, 218, 183, 255, 234, 220, 247, 213, 203,
078: 226, 193, 174, 172, 228, 252, 217, 201, 131, 230, 197, 211, 145, 238,
079: 161, 179, 160, 212, 207, 221, 254, 173, 202, 146, 224, 151, 140, 196,
080: 205, 130, 135, 133, 143, 246, 192, 159, 244, 239, 185, 168, 215, 144,
081: 139, 165, 180, 157, 147, 186, 214, 176, 227, 231, 219, 169, 175, 156,
082: 206, 198, 129, 164, 150, 210, 154, 177, 134, 127, 182, 128, 158, 208,
083: 162, 132, 167, 209, 149, 241, 153, 251, 237, 236, 171, 195, 243, 233,
084: 253, 240, 194, 250, 191, 155, 142, 137, 245, 235, 163, 242, 178, 152 };
085: *
086: *
087: */
088:
089: public class CVSScramble extends Object {
090: static public final String RCS_ID = "$Id: CVSScramble.java,v 2.2 2003/07/27 01:08:32 time Exp $";
091: static public final String RCS_REV = "$Revision: 2.2 $";
092:
093: static private int[] shifts;
094:
095: static {
096: int i;
097: int[] sh = new int[256];
098:
099: for (i = 0; i < 32; ++i) {
100: sh[i] = i;
101: }
102:
103: sh[i++] = 114;
104: sh[i++] = 120;
105: sh[i++] = 53;
106: sh[i++] = 79;
107: sh[i++] = 96;
108: sh[i++] = 109;
109: sh[i++] = 72;
110: sh[i++] = 108;
111: sh[i++] = 70;
112: sh[i++] = 64;
113: sh[i++] = 76;
114: sh[i++] = 67;
115: sh[i++] = 116;
116: sh[i++] = 74;
117: sh[i++] = 68;
118: sh[i++] = 87;
119: sh[i++] = 111;
120: sh[i++] = 52;
121: sh[i++] = 75;
122: sh[i++] = 119;
123: sh[i++] = 49;
124: sh[i++] = 34;
125: sh[i++] = 82;
126: sh[i++] = 81;
127: sh[i++] = 95;
128: sh[i++] = 65;
129: sh[i++] = 112;
130: sh[i++] = 86;
131: sh[i++] = 118;
132: sh[i++] = 110;
133: sh[i++] = 122;
134: sh[i++] = 105;
135: sh[i++] = 41;
136: sh[i++] = 57;
137: sh[i++] = 83;
138: sh[i++] = 43;
139: sh[i++] = 46;
140: sh[i++] = 102;
141: sh[i++] = 40;
142: sh[i++] = 89;
143: sh[i++] = 38;
144: sh[i++] = 103;
145: sh[i++] = 45;
146: sh[i++] = 50;
147: sh[i++] = 42;
148: sh[i++] = 123;
149: sh[i++] = 91;
150: sh[i++] = 35;
151: sh[i++] = 125;
152: sh[i++] = 55;
153: sh[i++] = 54;
154: sh[i++] = 66;
155: sh[i++] = 124;
156: sh[i++] = 126;
157: sh[i++] = 59;
158: sh[i++] = 47;
159: sh[i++] = 92;
160: sh[i++] = 71;
161: sh[i++] = 115;
162: sh[i++] = 78;
163: sh[i++] = 88;
164: sh[i++] = 107;
165: sh[i++] = 106;
166: sh[i++] = 56;
167: sh[i++] = 36;
168: sh[i++] = 121;
169: sh[i++] = 117;
170: sh[i++] = 104;
171: sh[i++] = 101;
172: sh[i++] = 100;
173: sh[i++] = 69;
174: sh[i++] = 73;
175: sh[i++] = 99;
176: sh[i++] = 63;
177: sh[i++] = 94;
178: sh[i++] = 93;
179: sh[i++] = 39;
180: sh[i++] = 37;
181: sh[i++] = 61;
182: sh[i++] = 48;
183: sh[i++] = 58;
184: sh[i++] = 113;
185: sh[i++] = 32;
186: sh[i++] = 90;
187: sh[i++] = 44;
188: sh[i++] = 98;
189: sh[i++] = 60;
190: sh[i++] = 51;
191: sh[i++] = 33;
192: sh[i++] = 97;
193: sh[i++] = 62;
194: sh[i++] = 77;
195: sh[i++] = 84;
196: sh[i++] = 80;
197: sh[i++] = 85;
198: sh[i++] = 223;
199: sh[i++] = 225;
200: sh[i++] = 216;
201: sh[i++] = 187;
202: sh[i++] = 166;
203: sh[i++] = 229;
204: sh[i++] = 189;
205: sh[i++] = 222;
206: sh[i++] = 188;
207: sh[i++] = 141;
208: sh[i++] = 249;
209: sh[i++] = 148;
210: sh[i++] = 200;
211: sh[i++] = 184;
212: sh[i++] = 136;
213: sh[i++] = 248;
214: sh[i++] = 190;
215: sh[i++] = 199;
216: sh[i++] = 170;
217: sh[i++] = 181;
218: sh[i++] = 204;
219: sh[i++] = 138;
220: sh[i++] = 232;
221: sh[i++] = 218;
222: sh[i++] = 183;
223: sh[i++] = 255;
224: sh[i++] = 234;
225: sh[i++] = 220;
226: sh[i++] = 247;
227: sh[i++] = 213;
228: sh[i++] = 203;
229: sh[i++] = 226;
230: sh[i++] = 193;
231: sh[i++] = 174;
232: sh[i++] = 172;
233: sh[i++] = 228;
234: sh[i++] = 252;
235: sh[i++] = 217;
236: sh[i++] = 201;
237: sh[i++] = 131;
238: sh[i++] = 230;
239: sh[i++] = 197;
240: sh[i++] = 211;
241: sh[i++] = 145;
242: sh[i++] = 238;
243: sh[i++] = 161;
244: sh[i++] = 179;
245: sh[i++] = 160;
246: sh[i++] = 212;
247: sh[i++] = 207;
248: sh[i++] = 221;
249: sh[i++] = 254;
250: sh[i++] = 173;
251: sh[i++] = 202;
252: sh[i++] = 146;
253: sh[i++] = 224;
254: sh[i++] = 151;
255: sh[i++] = 140;
256: sh[i++] = 196;
257: sh[i++] = 205;
258: sh[i++] = 130;
259: sh[i++] = 135;
260: sh[i++] = 133;
261: sh[i++] = 143;
262: sh[i++] = 246;
263: sh[i++] = 192;
264: sh[i++] = 159;
265: sh[i++] = 244;
266: sh[i++] = 239;
267: sh[i++] = 185;
268: sh[i++] = 168;
269: sh[i++] = 215;
270: sh[i++] = 144;
271: sh[i++] = 139;
272: sh[i++] = 165;
273: sh[i++] = 180;
274: sh[i++] = 157;
275: sh[i++] = 147;
276: sh[i++] = 186;
277: sh[i++] = 214;
278: sh[i++] = 176;
279: sh[i++] = 227;
280: sh[i++] = 231;
281: sh[i++] = 219;
282: sh[i++] = 169;
283: sh[i++] = 175;
284: sh[i++] = 156;
285: sh[i++] = 206;
286: sh[i++] = 198;
287: sh[i++] = 129;
288: sh[i++] = 164;
289: sh[i++] = 150;
290: sh[i++] = 210;
291: sh[i++] = 154;
292: sh[i++] = 177;
293: sh[i++] = 134;
294: sh[i++] = 127;
295: sh[i++] = 182;
296: sh[i++] = 128;
297: sh[i++] = 158;
298: sh[i++] = 208;
299: sh[i++] = 162;
300: sh[i++] = 132;
301: sh[i++] = 167;
302: sh[i++] = 209;
303: sh[i++] = 149;
304: sh[i++] = 241;
305: sh[i++] = 153;
306: sh[i++] = 251;
307: sh[i++] = 237;
308: sh[i++] = 236;
309: sh[i++] = 171;
310: sh[i++] = 195;
311: sh[i++] = 243;
312: sh[i++] = 233;
313: sh[i++] = 253;
314: sh[i++] = 240;
315: sh[i++] = 194;
316: sh[i++] = 250;
317: sh[i++] = 191;
318: sh[i++] = 155;
319: sh[i++] = 142;
320: sh[i++] = 137;
321: sh[i++] = 245;
322: sh[i++] = 235;
323: sh[i++] = 163;
324: sh[i++] = 242;
325: sh[i++] = 178;
326: sh[i++] = 152;
327:
328: CVSScramble.shifts = sh;
329: }
330:
331: public static String scramblePassword(String password, char selector) {
332: if (selector == 'A') {
333: StringBuffer buf = new StringBuffer("A");
334:
335: for (int i = 0; i < password.length(); ++i) {
336: char ch = password.charAt(i);
337:
338: byte newCh = (byte) (CVSScramble.shifts[((int) ch & 255)] & 255);
339:
340: buf.append((char) newCh);
341: }
342:
343: return buf.toString();
344: } else {
345: return null;
346: }
347: }
348:
349: public static String unScramblePassword(String scramble) {
350: char selector = scramble.charAt(0);
351:
352: if (selector == 'A') {
353: // This method is symmetrical.
354: String pass = CVSScramble.scramblePassword(scramble
355: .substring(1), 'A');
356:
357: return pass.substring(1); // Drop the 'A' spec...
358: } else {
359: return null;
360: }
361: }
362:
363: }
|