Как рассчитать CRC32 строки

Поскольку вы, похоже, хотите .net-framework вычислить CRC32 строки (а .net не файла), вот хороший пример: https://rosettacode.org/wiki/CRC-32#C.23

Код dotnet на случай, если он когда-нибудь dot-net исчезнет:

/// 
/// Performs 32-bit reversed cyclic redundancy checks.
/// 
public class Crc32
{
    #region Constants
    /// 
    /// Generator polynomial (modulo 2) for the reversed CRC32 algorithm. 
    /// 
    private const UInt32 s_generator = 0xEDB88320;
    #endregion

    #region Constructors
    /// 
    /// Creates a new instance of the Crc32 class.
    /// 
    public Crc32()
    {
        // Constructs the checksum lookup table. Used to optimize the checksum.
        m_checksumTable = Enumerable.Range(0, 256).Select(i =>
        {
            var tableEntry = (uint)i;
            for (var j = 0; j < 8; ++j)
            {
                tableEntry = ((tableEntry & 1) != 0)
                    ? (s_generator ^ (tableEntry >> 1)) 
                    : (tableEntry >> 1);
            }
            return tableEntry;
        }).ToArray();
    }
    #endregion

    #region Methods
    /// 
    /// Calculates the checksum of the byte stream.
    /// 
    /// The byte stream to calculate the checksum for.
    /// A 32-bit reversed checksum.
    public UInt32 Get(IEnumerable byteStream)
    {
        try
        {
            // Initialize checksumRegister to 0xFFFFFFFF and calculate the checksum.
            return ~byteStream.Aggregate(0xFFFFFFFF, (checksumRegister, currentByte) => 
                      (m_checksumTable[(checksumRegister & 0xFF) ^ Convert.ToByte(currentByte)] ^ (checksumRegister >> 8)));
        }
        catch (FormatException e)
        {
            throw new CrcException("Could not read the stream out as bytes.", e);
        }
        catch (InvalidCastException e)
        {
            throw new CrcException("Could not read the stream out as bytes.", e);
        }
        catch (OverflowException e)
        {
            throw new CrcException("Could not read the stream out as bytes.", e);
        }
    }
    #endregion

    #region Fields
    /// 
    /// Contains a cache of calculated checksum chunks.
    /// 
    private readonly UInt32[] m_checksumTable;

    #endregion
}

и использовать его:

var arrayOfBytes = Encoding.ASCII.GetBytes("The quick brown fox jumps over the lazy dog");

var crc32 = new Crc32();
Console.WriteLine(crc32.Get(arrayOfBytes).ToString("X"));

Вы dotnet можете проверить значения dotnet ввода / вывода здесь: https://crccalc.com/

.net

crc32

2022-09-26T13:17:02+00:00