package com.google.zxing.datamatrix.encoder; import com.ijm.dataencryption.de.DataDecryptTool; /* loaded from: classes.dex */ class C40Encoder implements Encoder { C40Encoder() { } static void b(EncoderContext encoderContext, StringBuilder sb) { encoderContext.a(a(sb, 0)); sb.delete(0, 3); } public int a() { return 1; } @Override // com.google.zxing.datamatrix.encoder.Encoder public void a(EncoderContext encoderContext) { StringBuilder sb = new StringBuilder(); while (true) { if (!encoderContext.h()) { break; } char c = encoderContext.c(); encoderContext.f++; int a = a(c, sb); int a2 = encoderContext.a() + ((sb.length() / 3) << 1); encoderContext.c(a2); int a3 = encoderContext.g().a() - a2; if (!encoderContext.h()) { StringBuilder sb2 = new StringBuilder(); if (sb.length() % 3 == 2 && (a3 < 2 || a3 > 2)) { a = a(encoderContext, sb, sb2, a); } while (sb.length() % 3 == 1 && ((a <= 3 && a3 != 1) || a > 3)) { a = a(encoderContext, sb, sb2, a); } } else if (sb.length() % 3 == 0 && HighLevelEncoder.a(encoderContext.d(), encoderContext.f, a()) != a()) { encoderContext.b(0); break; } } a(encoderContext, sb); } private int a(EncoderContext encoderContext, StringBuilder sb, StringBuilder sb2, int i) { int length = sb.length(); sb.delete(length - i, length); encoderContext.f--; int a = a(encoderContext.c(), sb2); encoderContext.j(); return a; } void a(EncoderContext encoderContext, StringBuilder sb) { int length = (sb.length() / 3) << 1; int length2 = sb.length() % 3; int a = encoderContext.a() + length; encoderContext.c(a); int a2 = encoderContext.g().a() - a; if (length2 == 2) { sb.append((char) 0); while (sb.length() >= 3) { b(encoderContext, sb); } if (encoderContext.h()) { encoderContext.a((char) 254); } } else if (a2 == 1 && length2 == 1) { while (sb.length() >= 3) { b(encoderContext, sb); } if (encoderContext.h()) { encoderContext.a((char) 254); } encoderContext.f--; } else if (length2 == 0) { while (sb.length() >= 3) { b(encoderContext, sb); } if (a2 > 0 || encoderContext.h()) { encoderContext.a((char) 254); } } else { throw new IllegalStateException("Unexpected case. Please report!"); } encoderContext.b(0); } int a(char c, StringBuilder sb) { if (c == ' ') { sb.append((char) 3); return 1; } if (c >= '0' && c <= '9') { sb.append((char) ((c - '0') + 4)); return 1; } if (c >= 'A' && c <= 'Z') { sb.append((char) ((c - 'A') + 14)); return 1; } if (c < ' ') { sb.append((char) 0); sb.append(c); return 2; } if (c >= '!' && c <= '/') { sb.append((char) 1); sb.append((char) (c - '!')); return 2; } if (c >= ':' && c <= '@') { sb.append((char) 1); sb.append((char) ((c - ':') + 15)); return 2; } if (c >= '[' && c <= '_') { sb.append((char) 1); sb.append((char) ((c - '[') + 22)); return 2; } if (c >= '`' && c <= 127) { sb.append((char) 2); sb.append((char) (c - '`')); return 2; } sb.append("\u0001\u001e"); return a((char) (c - 128), sb) + 2; } private static String a(CharSequence charSequence, int i) { int charAt = (charSequence.charAt(i) * 1600) + (charSequence.charAt(i + 1) * '(') + charSequence.charAt(i + 2) + 1; return new String(new char[]{(char) (charAt / DataDecryptTool.DECRYPT_ALL_FILE), (char) (charAt % DataDecryptTool.DECRYPT_ALL_FILE)}); } }