View Javadoc

1   //////////////////////////////////////////////////////////////////////////////
2   // dexterIM - Instant Messaging Framework
3   // Copyright (C) 2003  Christoph Walcher
4   //
5   // This program is free software; you can redistribute it and/or modify
6   // it under the terms of the GNU General Public License as published by
7   // the Free Software Foundation; either version 2 of the License, or
8   // (at your option) any later version.
9   //
10  // This program is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  // GNU General Public License for more details.
14  //
15  // You should have received a copy of the GNU General Public License
16  // along with this program; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  //////////////////////////////////////////////////////////////////////////////
19  package net.sf.dexterim.oscar.util;
20  
21  /***
22   * @author christoph
23   * TODO Document
24   */
25  public final class PasswordRoaster {
26    private static PasswordRoaster instance;
27     
28    private static final int[] roaster = { 
29      0xF3, 0x26, 0x81, 0xC4, 
30      0x39, 0x86, 0xDB, 0x92, 
31      0x71, 0xA3, 0xB9, 0xE6, 
32      0x53, 0x7A, 0x95, 0x7C 
33    };
34    
35    private PasswordRoaster() {
36    }
37    
38    public int[] roast(String password) {
39      
40      byte tmp[] = password.getBytes();
41      
42      int returnValue[] = new int[tmp.length];
43      
44      
45      for (int i=0; i<tmp.length; i++) {
46        int entry = (tmp[i] & 0xFF);
47        
48        returnValue[i] = (entry ^ roaster[i % roaster.length]);
49      }
50      
51      return returnValue;
52    }
53    
54    public static synchronized PasswordRoaster getInstance() {
55      if (instance == null) {
56        instance = new PasswordRoaster();
57      }
58      
59      return instance;
60    }
61  }