public class BarCodeVerifier {
int nAPMCCode = 0;
int nDate = 0;
int nMonth = 0;
int nTime = 0;
int nTrader = 0;
int nLorry = 0;
int nCommodity = 0;
int nQuantity = 0;
int nMinute = 0;
//String dt = DateFormat.getDateInstance().format(new Date()); // DateTime.Now.ToLongDateString();
public BarCodeVerifier() {
}
public int[] GetDecodedData(String strCoded) {
int[] nArr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// strip the last char...
char c = strCoded.toCharArray()[strCoded.length() - 1];
if (strCoded.length() > 17) {
String strMinuteCode = strCoded.substring(15, 17);
int nMunite = (int) (Base36Decode(strMinuteCode));
strCoded = new String(strCoded.substring(0, strCoded.length() - 3));
nArr[8] = nMunite;
} else {
strCoded = strCoded.substring(0, strCoded.length() - 1);
nArr[8] = 0;
}
// char c = strCoded.ToCharArray()[strCoded.Length-1];
// strCoded = strCoded.substring(0,strCoded.length()-1);
int nTime = (int) Base36Decode(String.valueOf(c));
int nTemp = (nTime < 15) ? (15 - nTime) : (15 - (nTime - 15));
strCoded = RotateString(strCoded, nTemp);
nArr[0] = (int) (Base36Decode(strCoded.substring(0, 2)));
nArr[1] = (int) (Base36Decode(strCoded.substring(2, 3)));
nArr[2] = (int) (Base36Decode(strCoded.substring(3, 4)));
nArr[3] = nTime; // Time
nArr[4] = (int) (Base36Decode(strCoded.substring(4, 7)));
nArr[5] = (int) (Base36Decode(strCoded.substring(7, 10)));
nArr[6] = (int) (Base36Decode(strCoded.substring(10, 12)));
// CODE
nArr[7] = (int) (Base36Decode(strCoded.substring(12, 15)));
return nArr;
}
// Converts base36 string to int64 string .. All capitals
public static long Base36Decode(String input) {
/*
* This function converts the input String characters into base36 values
*/
String base36Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char[] arrInput = new char[input.length()];
arrInput=input.toCharArray();
for (int i = input.length() - 1, j = 0; i != -1; i--, j++) {
arrInput[j] = input.charAt(i);
}
long returnValue = 0, rv=0;;
int value=1;
for (int i = 0; i < arrInput.length; i++) {
int valueindex = base36Chars.indexOf(arrInput[i]);
if(i==0)
{
rv=valueindex;
}
else
{
for(int j=0;j<=i;j++)
{
if(j==0)
{
value=1;
}
else
{
value*=36;
}
}
returnValue+= valueindex*value;
}
}
return rv+returnValue;
}
private String RotateString(String strRotate, int nTimes) {
/*
* Function can Rotates the String
*/
char[] cTemp;
char cur, nxt;
int nLen = strRotate.length();
for (int nIndex = 0; nIndex < nTimes; nIndex++) {
cTemp = strRotate.toCharArray();
cur = cTemp[0];
nxt = cur;
for (int nTemp = 0; nTemp < nLen - 1; nTemp++) {
nxt = cTemp[nTemp + 1];
cTemp[nTemp + 1] = cur;
cur = nxt;
}
cTemp[0] = nxt;
strRotate = new String(cTemp);
}
return strRotate;
}
}