md5 static method

Uint8List md5(
  1. List<int> message
)

Implementation

static Uint8List md5(List<int> message) {
  const List<int> shifts = <int>[
    7,
    12,
    17,
    22,
    7,
    12,
    17,
    22,
    7,
    12,
    17,
    22,
    7,
    12,
    17,
    22,
    5,
    9,
    14,
    20,
    5,
    9,
    14,
    20,
    5,
    9,
    14,
    20,
    5,
    9,
    14,
    20,
    4,
    11,
    16,
    23,
    4,
    11,
    16,
    23,
    4,
    11,
    16,
    23,
    4,
    11,
    16,
    23,
    6,
    10,
    15,
    21,
    6,
    10,
    15,
    21,
    6,
    10,
    15,
    21,
    6,
    10,
    15,
    21,
  ];
  final List<int> table = List<int>.generate(64, (int i) => ((sin(i + 1).abs()) * 4294967296).floor() & 0xFFFFFFFF);
  final List<int> padded = _padLittleEndian(message);
  int a0 = 0x67452301;
  int b0 = 0xefcdab89;
  int c0 = 0x98badcfe;
  int d0 = 0x10325476;
  for (int chunk = 0; chunk < padded.length; chunk += 64) {
    final List<int> words = List<int>.generate(16, (int i) => padded[chunk + i * 4] | (padded[chunk + i * 4 + 1] << 8) | (padded[chunk + i * 4 + 2] << 16) | (padded[chunk + i * 4 + 3] << 24));
    int a = a0;
    int b = b0;
    int c = c0;
    int d = d0;
    for (int i = 0; i < 64; i++) {
      int f;
      int g;
      if (i < 16) {
        f = (b & c) | (~b & d);
        g = i;
      } else if (i < 32) {
        f = (d & b) | (~d & c);
        g = (5 * i + 1) % 16;
      } else if (i < 48) {
        f = b ^ c ^ d;
        g = (3 * i + 5) % 16;
      } else {
        f = c ^ (b | (~d & 0xFFFFFFFF));
        g = (7 * i) % 16;
      }
      f = (f + a + table[i] + words[g]) & 0xFFFFFFFF;
      a = d;
      d = c;
      c = b;
      b = (b + _rotateLeft32(f, shifts[i])) & 0xFFFFFFFF;
    }
    a0 = (a0 + a) & 0xFFFFFFFF;
    b0 = (b0 + b) & 0xFFFFFFFF;
    c0 = (c0 + c) & 0xFFFFFFFF;
    d0 = (d0 + d) & 0xFFFFFFFF;
  }
  final Uint8List out = Uint8List(16);
  _writeLittleEndian(out, 0, a0);
  _writeLittleEndian(out, 4, b0);
  _writeLittleEndian(out, 8, c0);
  _writeLittleEndian(out, 12, d0);
  return out;
}