Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: gsoft/util/SecurityObfuscator.java


1   /*************************************************************************
2   Copyright (C) 2003  Steve Gee
3   stevesgee@cox.net
4   
5   This program is free software; you can redistribute it and/or
6   modify it under the terms of the GNU General Public License
7   as published by the Free Software Foundation; either version 2
8   of the License, or (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  
20  package gsoft.util;
21  
22  public class SecurityObfuscator {
23  
24  //-- This REALLY REALLY should be changed ;)
25    private String obfusticatorKey = "ABCDEFG123";
26    private char temp = ' ';
27    private int nIndex = 0;
28    private int bIndex = 0;
29    private StringBuffer strBuffer = new StringBuffer();
30    private int encLen;
31  
32    public SecurityObfuscator(){
33      encLen = obfusticatorKey.length();
34    }
35  
36    public void setHashMap(String hashMap){
37      obfusticatorKey = hashMap;
38      encLen = obfusticatorKey.length();
39    }
40  
41    public String obfuscator(String strToEnc){
42      strBuffer.setLength(0);
43      temp = ' ';
44      nIndex = 0;
45      bIndex = 0;
46      for (nIndex = 0; nIndex < strToEnc.length(); nIndex++) {
47        for (bIndex = 0; bIndex < encLen; bIndex++) {
48          int x = strToEnc.charAt(nIndex) ^ obfusticatorKey.charAt(bIndex);
49          temp = (char) x;
50        }
51        strBuffer.append(temp);
52      }
53      return strBuffer.toString();
54    }//end obfuscator
55  
56    public String reverseObfuscator(String obfusticatedString){
57      strBuffer.setLength(0);
58      temp = ' ';
59      nIndex = 0;
60      bIndex = 0;
61      for (nIndex = 0; nIndex < obfusticatedString.length(); nIndex++){
62        for (bIndex = 0; bIndex < encLen; bIndex++){
63          int x = obfusticatedString.charAt(nIndex) ^ obfusticatorKey.charAt(bIndex);
64          temp = (char) x;
65        }
66        strBuffer.append(temp);
67      }
68      return strBuffer.toString();
69    }
70  
71  }