You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Common/ConvertBase32.cs

35 lines
903 B

namespace NzbDrone.Common
{
public static class ConvertBase32
{
private static string ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
public static byte[] FromBase32String(string str)
{
var numBytes = str.Length * 5 / 8;
var bytes = new byte[numBytes];
// all UPPERCASE chars
str = str.ToUpper();
var bitBuffer = 0;
var bitBufferCount = 0;
var index = 0;
for (var i = 0; i < str.Length; i++)
{
bitBuffer = (bitBuffer << 5) | ValidChars.IndexOf(str[i]);
bitBufferCount += 5;
if (bitBufferCount >= 8)
{
bitBufferCount -= 8;
bytes[index++] = (byte)(bitBuffer >> bitBufferCount);
}
}
return bytes;
}
}
}