import java.io.*;
import com.she.util.*;
import java.util.Random;
import java.util.*;
public class AuthCode {
public enum DiscuzAuthcodeMode {
Encode, Decode
};
private static MD5 md5 = new MD5();
private static BASE64 base64 = new BASE64();
///
/// 从字符串的指定位置截取指定长度的子字符串
///
/// 原字符串
/// 子字符串的起始位置
/// 子字符串的长度
/// 子字符串
public static String CutString(String str, int startIndex, int length) {
if (startIndex >= 0) {
if (length < 0) {
length = length * -1;
if (startIndex - length < 0) {
length = startIndex;
startIndex = 0;
} else {
startIndex = startIndex - length;
}
}
if (startIndex > str.length()) {
return "";
}
} else {
if (length < 0) {
return "";
} else {
if (length + startIndex > 0) {
length = length + startIndex;
startIndex = 0;
} else {
return "";
}
}
}
if (str.length() - startIndex < length) {
length = str.length() - startIndex;
}
return str.substring(startIndex, startIndex + length);
}
///
/// 从字符串的指定位置开始截取到字符串结尾的了符串
///
/// 原字符串
/// 子字符串的起始位置
/// 子字符串
public static String CutString(String str, int startIndex) {
return CutString(str, startIndex, str.length());
}
///
/// 返回文件是否存在
///
/// 文件名
/// 是否存在
public static boolean FileExists(String filename) {
File f = new File(filename);
return f.exists();
}