encode static method
Takes in a list of bytes
converts it to a Uint8List so that one can run
bit operations on it, then outputs a base32 String representation.
Implementation
static String encode(Uint8List bytes) {
int i = 0, index = 0, digit = 0;
int currByte, nextByte;
String base32 = '';
while (i < bytes.length) {
currByte = bytes[i];
if (index > 3) {
if ((i + 1) < bytes.length) {
nextByte = bytes[i + 1];
} else {
nextByte = 0;
}
digit = currByte & (0xFF >> index);
index = (index + 5) % 8;
digit <<= index;
digit |= nextByte >> (8 - index);
i++;
} else {
digit = (currByte >> (8 - (index + 5)) & 0x1F);
index = (index + 5) % 8;
if (index == 0) {
i++;
}
}
base32 = base32 + _base32Chars[digit];
}
return base32;
}