JAVA 批量生成IMEI 源代码

来源:互联网 发布:苹果4s越狱软件 编辑:程序博客网 时间:2024/05/29 14:30


JAVA 有规律的批量生成IMEI

手机IMEI码由15-17位数字组成。

第一部分 TAC,Type Allocation Code,类型分配码,由8位数字组成(早期是6位),是区分手机品牌和型号的编码,该代码由GSMA及其授权机构分配。其中TAC码前两位又是分配机构标识(Reporting Body Identifier),是授权IMEI码分配机构的代码,如01为美国CTIA,35为英国BABT,86为中国TAF。

第二部分 FAC,Final Assembly Code,最终装配地代码,由2位数字构成,仅在早期TAC码为6位的手机中存在,所以TAC和FAC码合计一共8位数字。FAC码用于生产商内部区分生产地代码。

第三部分 SNR,Serial Number,序列号,由第9位开始的6位数字组成,区分每部手机的生产序列号。

第四部分 CD,Check Digit,验证码,由前14位数字通过Luhn算法计算得出。

第五部分 SVN,Software Version Number,软件版本号,区分同型号手机出厂时使用的不同软件版本,仅在部分品牌的部分机型中存在。




package com.test.main;import java.util.ArrayList;import java.util.List;public class IMEIGen {/** * @param args */public static void main(String[] args) {String code = "35254112521400";String newCode = genCode(code);System.out.println("======"+newCode);System.out.println(code+newCode);String endCode = "35254112521500";beachIMEI(code,endCode);}/** * 批量生成IMEI * @param begin  * @param end * @return */static List<String> beachIMEI(String begin,String end){List<String> imeis = new ArrayList<String>();try {long count = Long.parseLong(end) - Long.parseLong(begin);Long currentCode = Long.parseLong(begin);String code ;for (int i = 0; i <= count; i++) {code = currentCode.toString();code =code+ genCode(code);imeis .add(code);System.out.println("code====="+code);currentCode += 1;}} catch (Exception e) {e.printStackTrace();}return imeis;}/** * IMEI 校验码 * @param code * @return */public static String genCode(String code){int total=0,sum1=0,sum2 =0;int temp=0;char [] chs = code.toCharArray();for (int i = 0; i < chs.length; i++) {int num = chs[i] - '0'; // ascii to num//System.out.println(num);/*(1)将奇数位数字相加(从1开始计数)*/if (i%2==0) {sum1 = sum1 + num;}else{/*(2)将偶数位数字分别乘以2,分别计算个位数和十位数之和(从1开始计数)*/temp=num * 2 ;if (temp < 10) {sum2=sum2+temp;}else{sum2 = sum2 + temp + 1 -10;}}}total = sum1+sum2;/*如果得出的数个位是0则校验位为0,否则为10减去个位数 */if (total % 10 ==0) {return "0";}else{return (10 - (total %10))+"";}}}


1 0
原创粉丝点击