initialize method

void initialize()

Implementation

void initialize() {
  const poly = (1 << 8) | (1 << 4) | (1 << 3) | (1 << 1) | (1 << 0);

  int mul(int b, int c) {
    int i = b;
    int j = c;
    int s = 0;
    for (int k = 1; k < 0x100 && j != 0; k <<= 1) {
      if ((j & k) != 0) {
        s ^= i;
        j ^= k;
      }
      i <<= 1;
      if ((i & 0x100) != 0) {
        i ^= poly;
      }
    }
    return s;
  }

  // ignore: no_leading_underscores_for_local_identifiers
  _rot24(int x) => rotl32(x, 24);
  // (x << 24) | (x >> 8);

  for (int i = 0; i < 256; i++) {
    final s = _sbox0[i];
    int w = ((mul(s, 2) << 24) | (s << 16) | (s << 8) | mul(s, 3)) & mask32;
    _te0[i] = w;
    w = _rot24(w);
    _te1[i] = w;
    w = _rot24(w);
    _te2[i] = w;
    w = _rot24(w);
    _te3[i] = w;
    w = _rot24(w);
  }

  for (int i = 0; i < 256; i++) {
    final s = _sbox1[i];
    int w = (mul(s, 0xe) << 24) |
        (mul(s, 0x9) << 16) |
        (mul(s, 0xd) << 8) |
        mul(s, 0xb);
    _td0[i] = w;
    w = _rot24(w);
    _td1[i] = w;
    w = _rot24(w);
    _td2[i] = w;
    w = _rot24(w);
    _td3[i] = w;
    w = _rot24(w);
  }
}