主要问题是:
Tool.java:508: <identifier> expected
    static private Vector<Integer> getCode(String data, int len) {
                         ^
Tool.java:698: ';' expected

 static private Vector<Integer> getCode(String data, int len) {
        Vector<Integer> v = new Vector<Integer>();
     if (len >= data.length()) { 
     v.add(new Integer(-1));
     v.add(new Integer(len));
     return v;
     }
        int c = (int)hex2dec(data.charAt(len++), data.charAt(len++));        int code;
        if(bitsLeftOver) {
            code = (leftOver<<8)+c;
        } else {
         int d = (int)hex2dec(data.charAt(len++), data.charAt(len++));
            code = (c<<4)+(d>>4);
            leftOver = d&15;
        }
        bitsLeftOver = !bitsLeftOver;
        v.add(new Integer(code));
        v.add(new Integer(len));
        return v;
    } static public String LZW2base(String data) {
        
int codeUsed = 256;
        int[] s = new int[4096];
        Element[] h = new Element[4096];
        
        String result = "";
        int len = 0;        bitsLeftOver = false;
        leftOver = 0;
        Vector<Integer> v = getCode(data, len); 
        int pcode = v.get(0).intValue();
        len = v.get(1).intValue();
        int ccode;
        
        if(pcode>=0){
            s[0] = pcode;
            result += (char)(s[0]);
            int size = 0;            do{
                v = getCode(data, len);
                ccode = v.get(0).intValue();
                len = v.get(1).intValue();
                
                
                if(ccode<0)break;
                
                if(ccode<codeUsed){
                    int code = ccode;
                    size = -1;
                    while(code>=256){
                        s[++size]=h[code].suffix;
                        code = h[code].prefix;
                    }
                    s[++size]=code;
                    
                    for(int i=size; i>=0; i--)
                        result += (char)s[i];
                
                    if(codeUsed<4096) {
                        h[codeUsed++] = new Element(pcode, s[size]);
                    }
                }
                else{
                    h[codeUsed++] = new Element(pcode, s[size]);                    int code = ccode;
                    size = -1;
                    while(code>=256){
                        s[++size]=h[code].suffix;
                        code = h[code].prefix;
                    }
                    s[++size]=code;
                    
                    for(int i=size; i>=0; i--)
                        result += (char)s[i];
                }
                pcode = ccode;
            }while(true);
        }
        
        
return result;
}

static public String base2string(String data) {
int remainder = 0, i, a, b, c, d;
String result; while (data.length() % 4 > 0) {
data = 'A' + data;
} if (data.charAt(data.length() - 2) == '=') {
remainder = 1;
data = data.substring(0, data.length() - 2) + (char) (0)
+ (char) (0);
} else if (data.charAt(data.length() - 1) == '=') {
remainder = 2;
data = data.substring(0, data.length() - 1) + (char) (0);
} result = "";
for (i = 0; i < data.length() / 4; i++) {
a = Tool.indexOfBase(data.charAt(i * 4));
b = Tool.indexOfBase(data.charAt(i * 4 + 1));
c = Tool.indexOfBase(data.charAt(i * 4 + 2));
d = Tool.indexOfBase(data.charAt(i * 4 + 3)); result = result + (char) ((a << 2 & 0xfc) | (b >> 4 & 0x03));
result = result + (char) ((b << 4 & 0xf0) | (c >> 2 & 0x0f));
result = result + (char) ((c << 6 & 0xc0) | (d & 0x3f));
} if (remainder == 1) {
result = result.substring(0, result.length() - 2);
} else if (remainder == 2) {
result = result.substring(0, result.length() - 1);
} return result;
}

static public BigInteger genSeed(int length) {

char[] charset = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

int l = (length + 3) / 4;
BigInteger base = new BigInteger("2").pow(length);

String result = "";
for (int i = 0; i < l; i++) {
int index = (int)(Math.random() * 16); 
result = result + charset[index];
}

return new BigInteger(result, 16).mod(base);
}

static public BigInteger genLess(BigInteger max) {
BigInteger result = genSeed(max.bitLength());

for (int i = max.bitLength(); i >= 0; i--)
if (Math.random() * 2 >= 1) {
result.clearBit(i);
break;
}

return result;
}

static public BigInteger sha(BigInteger message) {
MessageDigest md;
try {
byte[] mb = message.toByteArray();
byte[] data = new byte[mb.length - 1];
for (int i = 1; i < mb.length; i++) 
data[i - 1] = mb[i]; md = MessageDigest.getInstance("SHA-1");
md.update(data);
byte[] digest = md.digest();

String result = "";
for (int i = 0; i < digest.length; i++) 
result = result + dec2hex(digest[i]); return new BigInteger(result, 16);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
    } static public String saperateString(String data, int step) {
String result = "";
for (int t = 0, i = data.length() - 1; i >= 0; i--, t++) {
if (t == step) {
result = " " + result;
t = 0;
}
result = data.charAt(i) + result;
}
return result;
}}
这只是从508行开始的代码

解决方案 »

  1.   

    以下是全部代码:
    //package src;import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.math.BigInteger;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.Hashtable;
    import java.util.Random;
    import java.util.Vector;import javax.swing.BorderFactory;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.border.TitledBorder;class Element{
        int prefix;
        int suffix;    public Element(int prefix, int suffix){
            this.prefix = prefix;
            this.suffix = suffix;
        }
    }public class Tool {
    static public Dimension buttonSize = new Dimension(100, 28);
    static public Dimension buttonSize2 = new Dimension(130, 28);
    static private int leftOver = 0;
    static private boolean bitsLeftOver = false;


    static public char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
    '9', 'A', 'B', 'C', 'D', 'E', 'F' }; static public char base64[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
    'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
    'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
    'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
    'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
    '8', '9', '+', '/' }; static public String dec2hex(int data) {
    int a, b, c, d; if (data > 0xff) {
    return null;
    }// a = (data >> 12) & 0x000f;
    // b = (data >> 8) & 0x000f;
    c = (data >> 4) & 0x000f;
    d = data & 0x000f;
    //return "" + hex[a] + hex[b] + hex[c] + hex[d];
    return "" + hex[c] + hex[d];
    }// static public int hex2dec(char a, char b, char c, char d) {
    // int ra, rb, rc, rd = 0;
    // if ((a >= 'A') && (a <= 'F')) {
    // ra = (int) (a - 'A' + 10);
    // } else {
    // ra = (int) (a - '0');
    // }
    // if ((b >= 'A') && (b <= 'F')) {
    // rb = (int) (b - 'A' + 10);
    // } else {
    // rb = (int) (b - '0');
    // }
    // if ((c >= 'A') && (c <= 'F')) {
    // rc = (int) (c - 'A' + 10);
    // } else {
    // rc = (int) (c - '0');
    // }
    // if ((d >= 'A') && (d <= 'F')) {
    // rd = (int) (d - 'A' + 10);
    // } else {
    // rd = (int) (d - '0');
    // }
    // return ((ra << 12) | (rb << 8) | (rc << 4) | rd);
    // }
    // static public String dec2hex(byte data) {
    // byte a, b;
    // a = (byte) (data >> 4 & 0x0f);
    // b = (byte) (data & 0x0f);
    // return "" + hex[a] + hex[b];
    // } static public int hex2dec(char a, char b) {
    int ra, rb;
    if ((a >= 'A') && (a <= 'F')) {
    ra = (byte) (a - 'A' + 10);
    } else {
    ra = (byte) (a - '0');
    }
    if ((b >= 'A') && (b <= 'F')) {
    rb = (byte) (b - 'A' + 10);
    } else {
    rb = (byte) (b - '0');
    }
    return ((ra << 4) | rb);
    } static public int indexOfBase(char ch) {
    if ((ch >= 'A') && (ch <= 'Z')) {
    return (int) (ch - 'A');
    } else if ((ch >= 'a') && (ch <= 'z')) {
    return (int) (ch - 'a' + 26);
    } else if ((ch >= '0') && (ch <= '9')) {
    return (int) (ch - '0' + 26 + 26);
    } else if (ch == '+') {
    return 62;
    } else if (ch == '/') {
    return 63;
    }
    return 0;
    } static public void add2bag(JPanel pane, Component com, int gx, int gy,
    int gw, int gh, int pos, int fill) {
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = gbc.weighty = 100;
    gbc.gridx = gx;
    gbc.gridy = gy;
    gbc.gridwidth = gw;
    gbc.gridheight = gh;
    gbc.anchor = pos;
    gbc.fill = fill;
    pane.add(com, gbc);
    } static public File selectFile(Component parent, String ext, String des,
    boolean isOpen) {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File("."));
    fc.setFileFilter(new KeyFilter(ext, des));
    int re;
    if (isOpen) {
    re = fc.showOpenDialog(parent);
    } else {
    re = fc.showSaveDialog(parent);
    }
    if (re == JFileChooser.APPROVE_OPTION) {
    return fc.getSelectedFile();
    } else {
    return null;
    }
    } static public String readFile(Component parent, File file) {
    if (file == null) {
    return null;
    }
    try {
    FileInputStream in = new FileInputStream(file.getPath());
    byte[] data = new byte[in.available()];
    in.read(data);
    in.close();
    return new String(data);
    } catch (Exception e) {
    JOptionPane.showMessageDialog(parent, "文件读取失败");
    return null;
    }
    } static public void writeFile(Component parent, File file, String str) {
    if (file == null) {
    return;
    }
    try {
    FileOutputStream out = new FileOutputStream(file.getPath());
    byte[] data = str.getBytes();
    out.write(data);
    out.close();
    } catch (Exception e) {
    JOptionPane.showMessageDialog(parent, "文件写入失败");
    }
    } static public BigInteger string2big(String data) {
    String result = "";
    for (int i = 0; i < data.length(); i++) {
    byte bs = (byte) data.charAt(i);
    if ((bs & 0x80) > 0)
    result = result + "1";
    else
    result = result + "0";
    if ((bs & 0x40) > 0)
    result = result + "1";
    else
    result = result + "0";
    if ((bs & 0x20) > 0)
    result = result + "1";
    else
    result = result + "0";
    if ((bs & 0x10) > 0)
    result = result + "1";
    else
    result = result + "0";
    if ((bs & 0x08) > 0)
    result = result + "1";
    else
    result = result + "0";
    if ((bs & 0x04) > 0)
    result = result + "1";
    else
    result = result + "0";
    if ((bs & 0x02) > 0)
    result = result + "1";
    else
    result = result + "0";
    if ((bs & 0x01) > 0)
    result = result + "1";
    else
    result = result + "0";
    }
    return new BigInteger(result, 2);
    } static public String big2string(BigInteger data) {
    String result = "";
    byte[] bs = data.toByteArray();
    result = new String(bs);
    return result;
    }

    static public String string2hex(String data) {
    String result = "";
    String charset = "0123456789ABCDEF";

    int i, t, j, k;
    for (i = t = 0; i < data.length(); i++) {
    t = (int) data.charAt(i);
    j = (t & 0x0F);
    k = (t & 0xF0) >> 4;
    result += charset.charAt(k);
    result += charset.charAt(j);
    }

    return result;
    } static public String hex2string(String data) {
    String result = "";

    int i, t, j, k;
    char ch1, ch2;
    for (i = 0; i < data.length() / 2; i++) {
    ch1 = data.charAt(i + i);
    ch2 = data.charAt(i + i + 1);

    if ((ch1 >= '0') && (ch1 <= '9')) 
    j = (int)(ch1 - '0');
    else 
    j = (int)(ch1 - 'A') + 10;

    if ((ch2 >= '0') && (ch2 <= '9')) 
    k = (int)(ch2 - '0');
    else 
    k = (int)(ch2 - 'A') + 10;

    t = (j << 4) + k; result += (char)t;
    }

    return result;
    } static public String string2base(String data) {
      

  2.   

    int remainder = data.length() % 3;
    int i, t, j, k;
    String st = data, result = ""; if (remainder == 2) {
    st = st + (char) (0);
    } else if (remainder == 1) {
    st = st + (char) (0) + (char) (0);
    } for (i = t = 0; i < st.length() / 3; i++) {
    t = (int) st.charAt(i * 3);
    j = (int) st.charAt(i * 3 + 1);
    k = (int) st.charAt(i * 3 + 2); result += Tool.base64[(t >> 2) & 0x3f];
    result += Tool.base64[((t & 0x03) << 4) | ((j & 0xf0) >> 4)];
    result += Tool.base64[((j & 0x0f) << 2) | ((k & 0xc0) >> 6)];
    result += Tool.base64[k & 0x3f];
    } if (remainder == 1) {
    result = result.substring(0, result.length() - 2) + "==";
    } else if (remainder == 2) {
    result = result.substring(0, result.length() - 1) + "=";
    }
    return result;
    } static public String big2base(BigInteger data) {
    String result = "";
    String st = data.toString(2);
    String temp; while (st.length() % 24 > 0) {
    st = "0" + st;
    } while (st.length() > 0) {
    temp = "00" + st.substring(0, 6); st = st.substring(6);
    BigInteger val = new BigInteger(temp, 2);
    result = result + base64[val.intValue()];
    }
    return result;
    } static public BigInteger base2big(String data) {
    String temp, result = "";
    int i, t; for (i = 0; i < data.length(); i++) {
    char ch = data.charAt(i);
    for (t = 0; t < base64.length; t++) {
    if (base64[t] == ch) {
    break;
    }
    }
    if (t == base64.length) {
    t = 0;
    }
    temp = Integer.toBinaryString(t);
    while (temp.length() < 8) {
    temp = "0" + temp;
    }
    result = result + temp.substring(2);
    }
    return new BigInteger(result, 2);
    } static public BigInteger genRandom(BigInteger minNumber,
    BigInteger maxNumber) {
    Random ran = new Random();
    BigInteger min = minNumber;
    BigInteger max = maxNumber; while (min.compareTo(max) < 0) {
    if (ran.nextInt() > 0) {
    max = min.add(max).divide(new BigInteger("2"));
    } else {
    min = min.add(max).divide(new BigInteger("2")).add(
    BigInteger.ONE);
    }
    }
    return min;
    } static public JPanel addSpace(Component com) {
    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    p.add(com);
    return p;
    } static public JPanel addTitle(Component com, String title) {
    JPanel p = new JPanel(new BorderLayout());
    p.add(com);
    p.setBorder(new TitledBorder(title));
    return p;
    } static public String bytes2string(byte[] data) {
    String result = "";
    for (int i = 0; i < data.length; i++) {
    if ((data[i] & 0x80) > 0) {
    result = result + "1";
    } else {
    result = result + "0";
    }
    if ((data[i] & 0x40) > 0) {
    result = result + "1";
    } else {
    result = result + "0";
    }
    if ((data[i] & 0x20) > 0) {
    result = result + "1";
    } else {
    result = result + "0";
    }
    if ((data[i] & 0x10) > 0) {
    result = result + "1";
    } else {
    result = result + "0";
    }
    if ((data[i] & 0x08) > 0) {
    result = result + "1";
    } else {
    result = result + "0";
    }
    if ((data[i] & 0x04) > 0) {
    result = result + "1";
    } else {
    result = result + "0";
    }
    if ((data[i] & 0x02) > 0) {
    result = result + "1";
    } else {
    result = result + "0";
    }
    if ((data[i] & 0x01) > 0) {
    result = result + "1";
    } else {
    result = result + "0";
    }
    }
    return result;
    } static public byte[] string2bytes(String data) {
    String st = data, temp;
    while (st.length() % 8 > 0) {
    st = "0" + st;
    }
    byte[] result = new byte[st.length() / 8];
    for (int i = 0; i < result.length; i++) {
    temp = st.substring(0, 8);
    st = st.substring(8);
    int j = 0;
    for (int t = 0; t < 8; t++) {
    j = j << 1;
    if (temp.charAt(t) == '1') {
    j = j | 1;
    }
    }
    result[i] = (byte) j;
    }
    return result;
    } static public String base2LZW(Component parent, String data) {
    Hashtable table = new Hashtable();
            for(int i=0; i< 256; i++)
                table.put(new Integer(i), new Integer(i));        leftOver = 0;
            bitsLeftOver = false;
            
            int codeUsed = 256;        int len = 0;
            String result = "";
            
            if(len < data.length()){
             int c = (int)data.charAt(len++);    
             int pcode = c;
                
                while(len < data.length()){
                 c = (int)data.charAt(len++);
                    int k = (pcode<<8)+c;
                    Integer e = (Integer)table.get(new Integer(k));
                    if(e==null){
                        String temp = Tool.genCode(pcode);
                     result += temp;
                        if(codeUsed<4096) {
                            table.put(new Integer((pcode<<8)+c), new Integer(codeUsed++));
                        }
                        pcode = c;
                    } else { 
                     pcode = e.intValue();
                    }
                }            String temp = Tool.genCode(pcode);
                result += temp;
                if(bitsLeftOver)
                 result += dec2hex(leftOver << 4);
            }
            return result;
    }

    static public String genCode(int data) {
            int c,d;
            if(bitsLeftOver){
                d = data & 255;
                c = (leftOver << 4)+(data >> 8);
                bitsLeftOver = false;
                return dec2hex(c) + "" + dec2hex(d);
            }
            else{
                leftOver = data & 15;
                c = data >> 4;
                bitsLeftOver = true;
                return dec2hex(c);
            }
    }
      

  3.   

        static private Vector<Integer> getCode(String data, int len) {
            Vector<Integer> v = new Vector<Integer>();
         if (len >= data.length()) { 
         v.add(new Integer(-1));
         v.add(new Integer(len));
         return v;
         }
            int c = (int)hex2dec(data.charAt(len++), data.charAt(len++));        int code;
            if(bitsLeftOver) {
                code = (leftOver<<8)+c;
            } else {
             int d = (int)hex2dec(data.charAt(len++), data.charAt(len++));
                code = (c<<4)+(d>>4);
                leftOver = d&15;
            }
            bitsLeftOver = !bitsLeftOver;
            v.add(new Integer(code));
            v.add(new Integer(len));
            return v;
        } static public String LZW2base(String data) {
            
    int codeUsed = 256;
            int[] s = new int[4096];
            Element[] h = new Element[4096];
            
            String result = "";
            int len = 0;        bitsLeftOver = false;
            leftOver = 0;
            Vector<Integer> v = getCode(data, len); 
            int pcode = v.get(0).intValue();
            len = v.get(1).intValue();
            int ccode;
            
            if(pcode>=0){
                s[0] = pcode;
                result += (char)(s[0]);
                int size = 0;            do{
                    v = getCode(data, len);
                    ccode = v.get(0).intValue();
                    len = v.get(1).intValue();
                    
                    
                    if(ccode<0)break;
                    
                    if(ccode<codeUsed){
                        int code = ccode;
                        size = -1;
                        while(code>=256){
                            s[++size]=h[code].suffix;
                            code = h[code].prefix;
                        }
                        s[++size]=code;
                        
                        for(int i=size; i>=0; i--)
                            result += (char)s[i];
                    
                        if(codeUsed<4096) {
                            h[codeUsed++] = new Element(pcode, s[size]);
                        }
                    }
                    else{
                        h[codeUsed++] = new Element(pcode, s[size]);                    int code = ccode;
                        size = -1;
                        while(code>=256){
                            s[++size]=h[code].suffix;
                            code = h[code].prefix;
                        }
                        s[++size]=code;
                        
                        for(int i=size; i>=0; i--)
                            result += (char)s[i];
                    }
                    pcode = ccode;
                }while(true);
            }
            
            
    return result;
    }

    static public String base2string(String data) {
    int remainder = 0, i, a, b, c, d;
    String result; while (data.length() % 4 > 0) {
    data = 'A' + data;
    } if (data.charAt(data.length() - 2) == '=') {
    remainder = 1;
    data = data.substring(0, data.length() - 2) + (char) (0)
    + (char) (0);
    } else if (data.charAt(data.length() - 1) == '=') {
    remainder = 2;
    data = data.substring(0, data.length() - 1) + (char) (0);
    } result = "";
    for (i = 0; i < data.length() / 4; i++) {
    a = Tool.indexOfBase(data.charAt(i * 4));
    b = Tool.indexOfBase(data.charAt(i * 4 + 1));
    c = Tool.indexOfBase(data.charAt(i * 4 + 2));
    d = Tool.indexOfBase(data.charAt(i * 4 + 3)); result = result + (char) ((a << 2 & 0xfc) | (b >> 4 & 0x03));
    result = result + (char) ((b << 4 & 0xf0) | (c >> 2 & 0x0f));
    result = result + (char) ((c << 6 & 0xc0) | (d & 0x3f));
    } if (remainder == 1) {
    result = result.substring(0, result.length() - 2);
    } else if (remainder == 2) {
    result = result.substring(0, result.length() - 1);
    } return result;
    }

    static public BigInteger genSeed(int length) {

    char[] charset = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    int l = (length + 3) / 4;
    BigInteger base = new BigInteger("2").pow(length);

    String result = "";
    for (int i = 0; i < l; i++) {
    int index = (int)(Math.random() * 16); 
    result = result + charset[index];
    }

    return new BigInteger(result, 16).mod(base);
    }

    static public BigInteger genLess(BigInteger max) {
    BigInteger result = genSeed(max.bitLength());

    for (int i = max.bitLength(); i >= 0; i--)
    if (Math.random() * 2 >= 1) {
    result.clearBit(i);
    break;
    }

    return result;
    }

    static public BigInteger sha(BigInteger message) {
    MessageDigest md;
    try {
    byte[] mb = message.toByteArray();
    byte[] data = new byte[mb.length - 1];
    for (int i = 1; i < mb.length; i++) 
    data[i - 1] = mb[i]; md = MessageDigest.getInstance("SHA-1");
    md.update(data);
    byte[] digest = md.digest();

    String result = "";
    for (int i = 0; i < digest.length; i++) 
    result = result + dec2hex(digest[i]); return new BigInteger(result, 16);
    } catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
    return null;
    }
        } static public String saperateString(String data, int step) {
    String result = "";
    for (int t = 0, i = data.length() - 1; i >= 0; i--, t++) {
    if (t == step) {
    result = " " + result;
    t = 0;
    }
    result = data.charAt(i) + result;
    }
    return result;
    }}