最新の18ビット認証
1760 ワード
package test;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Test t = new Test();
String certNo="130925198512055555";
boolean tt= t.convertCert(certNo);
if(tt){
System.out.println(" ");
}else{
System.out.println(" ");
}
}
public static boolean convertCert(String certNo){
try{
if(certNo.trim().length()!=18){
return false;
}
String tempStr = certNo.substring(0,17);//certNo.substring(0,6)+"19"+certNo.substring(6);
System.out.println(tempStr);
String checkCode = "";
int[] a = new int[17];
int i = 0;
while(i<17){
a[i] = Integer.parseInt(tempStr.substring(i,i+1));
i++;
}
int mod = (a[0]*7+a[1]*9+a[2]*10+a[3]*5+a[4]*8+a[5]*4+a[6]*2+a[7]*1+a[8]*6+a[9]*3+a[10]*7
+a[11]*9+a[12]*10+a[13]*5+a[14]*8+a[15]*4+a[16]*2)%11;
switch (mod){
case 10: checkCode = "2"; break;
case 9: checkCode = "3"; break;
case 8: checkCode = "4"; break;
case 7: checkCode = "5"; break;
case 6: checkCode = "6"; break;
case 5: checkCode = "7"; break;
case 4: checkCode = "8"; break;
case 3: checkCode = "9"; break;
case 2: checkCode = "x"; break;
case 1: checkCode = "0"; break;
case 0: checkCode = "1"; break;
}
String sourceCheckCode = certNo.substring(17,18);
if(sourceCheckCode.equalsIgnoreCase(checkCode)){
return true;
}else{
return false;
}
}catch(Exception e){
e.printStackTrace();
return false;
}
}
}
注意:String certNo="130925198512055555";身分証明書番号は正しいものでなければなりません.