Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.zjh.blwy.opendoorqcode;
- import android.text.TextUtils;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- public class XXTEACAI {
- private int[] a;
- private final String[] b;
- private a c;
- public enum OpenType {
- NO_MATCH,
- HOUSE_NUM,
- MAC
- }
- public enum TimeLimitType {
- NO,
- YES
- }
- public static class a {
- private String a;
- private String b;
- private TimeLimitType c = TimeLimitType.YES;
- private int d = 1;
- private int e = 60;
- private Integer f = null;
- private Integer g = null;
- private OpenType h = OpenType.NO_MATCH;
- private Integer i = null;
- private String[] j;
- private Date k = null;
- private Date l = null;
- public void a(String str) {
- this.a = str;
- }
- public void a(TimeLimitType timeLimitType) {
- this.c = timeLimitType;
- }
- public void a(byte b) {
- this.d = b;
- }
- public void a(int i) {
- this.e = i;
- }
- public void b(int i) {
- this.f = Integer.valueOf(i);
- }
- public void c(int i) {
- this.g = Integer.valueOf(i);
- }
- public void a(String... strArr) {
- int length = strArr.length;
- int i = 0;
- while (i < length) {
- String str = strArr[i];
- if (str.length() != 6) {
- throw new RuntimeException("please input macaddress last six number!");
- }
- try {
- Integer.valueOf(str, 16);
- i++;
- } catch (Exception e) {
- throw new RuntimeException("please input invalid mac address!");
- }
- }
- this.h = OpenType.MAC;
- this.j = strArr;
- }
- public void a(int i, int i2) {
- if (i2 <= 0) {
- throw new RuntimeException("expriyDate must be >0");
- }
- Calendar instance = Calendar.getInstance();
- instance.add(13, -i);
- this.k = instance.getTime();
- instance.add(13, i2);
- this.l = instance.getTime();
- }
- public XXTEACAI a() {
- if (TextUtils.isEmpty(this.a) || this.a.contains("|")) {
- throw new RuntimeException("please call setUnique and unique not contain '|'");
- } else if (this.f == null || this.g == null) {
- throw new RuntimeException("plase call setUserSecertKey and setDeviceSecertKey");
- } else {
- switch (this.h) {
- case HOUSE_NUM:
- if (this.i == null || this.j == null || this.j.length <= 0) {
- throw new RuntimeException("please call buildOpenType,number must not null,serials must not null");
- } else if (this.j.length > 255) {
- throw new RuntimeException("serials max length is 255");
- }
- break;
- case MAC:
- if (this.j == null || this.j.length <= 0) {
- this.j = new String[0];
- break;
- } else if (this.j.length > 255) {
- throw new RuntimeException("serials max length is 255");
- }
- break;
- }
- if (TextUtils.isEmpty(this.b)) {
- this.b = String.format("%08x", new Object[]{Integer.valueOf((int) ((System.currentTimeMillis() / 1000) & -1))});
- }
- return new XXTEACAI();
- }
- }
- }
- private XXTEACAI(a aVar) {
- this.b = new String[8];
- this.c = aVar;
- this.b[7] = "8";
- b();
- c();
- d();
- e();
- f();
- g();
- h();
- }
- private void b() {
- this.a = new int[4];
- int[] iArr = this.a;
- int[] iArr2 = this.a;
- int intValue = this.c.g.intValue();
- iArr2[3] = intValue;
- iArr[1] = intValue;
- iArr = this.a;
- iArr2 = this.a;
- intValue = this.c.f.intValue();
- iArr2[0] = intValue;
- iArr[2] = intValue;
- }
- private void c() {
- this.b[0] = this.c.a + "|";
- }
- private void d() {
- this.b[1] = this.c.b;
- }
- private void e() {
- this.b[3] = String.format("%08x", new Object[]{this.c.f});
- }
- private void f() {
- int ordinal = this.c.c.ordinal();
- int ordinal2 = this.c.h.ordinal();
- this.b[4] = String.format("%1$02x%2$02x%3$02x%4$04x000000", new Object[]{Integer.valueOf(ordinal), Integer.valueOf(this.c.d), Integer.valueOf(ordinal2), Integer.valueOf(this.c.e)});
- }
- private void g() {
- if (this.c.k == null) {
- Calendar instance = Calendar.getInstance();
- this.c.k = instance.getTime();
- instance.add(5, 3);
- this.c.l = instance.getTime();
- }
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyMMddHHmmss");
- this.b[5] = simpleDateFormat.format(this.c.k) + simpleDateFormat.format(this.c.l);
- }
- private void h() {
- int i = 0;
- StringBuilder stringBuilder;
- String[] k;
- int length;
- switch (this.c.h) {
- case HOUSE_NUM:
- stringBuilder = new StringBuilder();
- stringBuilder.append(String.format("%02x", new Object[]{Integer.valueOf(this.c.j.length)}));
- stringBuilder.append(String.format("%08x", new Object[]{this.c.i}));
- k = this.c.j;
- length = k.length;
- while (i < length) {
- stringBuilder.append(k[i]);
- i++;
- }
- this.b[6] = stringBuilder.toString();
- return;
- case MAC:
- stringBuilder = new StringBuilder();
- stringBuilder.append(String.format("%02x", new Object[]{Integer.valueOf(this.c.j.length)}));
- k = this.c.j;
- length = k.length;
- while (i < length) {
- stringBuilder.append(k[i]);
- i++;
- }
- this.b[6] = stringBuilder.toString();
- return;
- default:
- this.b[6] = "";
- return;
- }
- }
- private String i() {
- String str = this.b[4] + this.b[5] + this.b[6];
- int length = str.length();
- int i = (byte) (length / 8);
- int i2 = (byte) (length % 8);
- if (i2 != 0) {
- i = (byte) (i + 1);
- } else {
- i2 = 8;
- }
- String toHexString = Integer.toHexString(i & 255);
- if (toHexString.length() < 2) {
- toHexString = "0" + toHexString;
- }
- String toHexString2 = Integer.toHexString(((byte) ((length % 8) / 2)) & 255);
- if (toHexString2.length() < 2) {
- toHexString2 = "0" + toHexString2;
- }
- this.b[2] = toHexString + toHexString2;
- int i3 = i <= 20 ? 20 : i;
- int[] iArr = new int[i3];
- for (length = 0; length < i - 1; length++) {
- iArr[length] = (int) Long.valueOf(str.substring(length * 8, (length + 1) * 8), 16).longValue();
- }
- iArr[i - 1] = (int) Long.valueOf(str.substring((i - 1) * 8, ((i - 1) * 8) + i2), 16).longValue();
- int[] iArr2 = new int[i3];
- iArr = a.a(iArr, this.a, i);
- toHexString2 = "";
- for (i3 = 0; i3 < i; i3++) {
- toHexString2 = toHexString2 + a(Integer.toHexString(iArr[i3]).toUpperCase(), 8, true);
- }
- System.out.println("加密前字符串" + str);
- System.out.println("加密后的字符串" + toHexString2);
- a(iArr, i, i2);
- return this.b[0] + this.b[1] + this.b[2] + this.b[3] + toHexString2;
- }
- public String a(int[] iArr, int i, int i2) {
- int[] iArr2 = new int[20];
- int[] b = a.b(iArr, this.a, i);
- String str = "";
- String str2 = "";
- for (int i3 = 0; i3 < i - 1; i3++) {
- str = str + a(Integer.toHexString(b[i3]).toUpperCase(), 8, true);
- }
- if (i2 == 1) {
- str2 = str + a(Integer.toHexString(b[i - 1]).toUpperCase(), 2, true);
- } else if (i2 == 2) {
- str2 = str + a(Integer.toHexString(b[i - 1]).toUpperCase(), 4, true);
- } else if (i2 == 3) {
- str2 = str + a(Integer.toHexString(b[i - 1]).toUpperCase(), 6, true);
- } else {
- str2 = str + a(Integer.toHexString(b[i - 1]).toUpperCase(), 8, true);
- }
- System.out.println("解密后字符串" + str2);
- return str2;
- }
- public final String a() {
- return i();
- }
- private String a(String str, int i, boolean z) {
- if (str == null) {
- str = "";
- }
- int length = i - str.length();
- StringBuffer stringBuffer = new StringBuffer();
- for (int i2 = 0; i2 < length; i2++) {
- stringBuffer.append("0");
- }
- if (z) {
- stringBuffer.append(str);
- } else {
- stringBuffer.insert(0, str);
- }
- return stringBuffer.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement