Office的CRC算法是用C#实现的吗

发布于 2024-10-09 03:46:25 字数 209 浏览 0 评论 0原文

我正在寻找 Microsoft Office

http://msdn 定义的 crc 算法的实现.microsoft.com/en-us/library/dd922675.aspx

它已经在某处实施了吗?

I am looking for an implementation of the crc algorithm defined by Microsoft Office

http://msdn.microsoft.com/en-us/library/dd922675.aspx

Is it already implemented somewhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深居我梦 2024-10-16 03:46:25

我可能是错的,但我认为如果您细化搜索以查找 Microsoft Office CRC SALT< /a> 你会有更好的运气。

简而言之,CRC 算法应该与其他算法相同,但有时程序有自己的 SALT 来“调味”哈希算法。

I could be mistaken, but i think if you refine your search to look for Microsoft Office CRC SALT you will have better luck.

In short the CRC algorithme should be the same as any other, but some times programs have their own SALT to "spice" up the hash algorithme.

回梦 2024-10-16 03:46:25

未经测试,但 15 分钟,办公室文章表明这​​应该可以解决问题。鉴于原始来源允许调用者使用他们想要的任何起始值来播种算法,我不能保证结果将与您正在寻找的任何内容相匹配:MS Office 可以使用 32 位随机数来播种 CRC 计算熵。没有任何内容表明计算应以初始值 0 为种子。

public class MsoCrc32
{
  private const int BUFFER_SIZE =  4096 ;
  private static readonly uint[] cache ;

  public uint Value { get ; private set ; }

  public void Add( byte[] bytes )
  {
    foreach ( byte octet in bytes )
    {
      uint i = ( Value >> 24 ) ^ octet ;

      Value <<= 8        ;
      Value  ^= cache[i] ;

    }

    return ;
  }
  public void Add( Stream s )
  {
    byte[] buffer = new byte[BUFFER_SIZE] ;
    int    bufl   = 0 ;

    while ( (bufl=s.Read(buffer,0,buffer.Length)) > 0 )
    {
      Add( buffer ) ;
    }

    return ;
  }

  public MsoCrc32() : this(0)
  {
  }
  public MsoCrc32( int value )
  {
    this.Value = (uint) value ;
  }
  static MsoCrc32()
  {
    cache = InitCache();
    return ;
  }

  private static uint[] InitCache()
  {
    uint[] cacheInstance = new uint[256] ;

    for ( uint i = 0 ; i < cache.Length ; ++i )
    {
      uint value = i << 24 ;

      for ( uint j = 0 ; j < 8 ; ++j )
      {
        value <<= 1 ;
        if ( 0x80000000 == (value&0x80000000) )
        {
          value  ^= 0xAF000000 ;
        }
      }

      value &= 0xFFFF0000 ;

      cacheInstance[i] = value ;

    }

    return cacheInstance ;
  }

}

Not tested, but 15 minutes and the office article suggests that this should do the trick. Given that the original source allows the caller to seed the algorithm with whatever starting value they want, There's no guarantee that I see, that the results will match whatever you're looking for: MS Office could seed the CRC computation with 32 bits of random entropy. Nothing says that computation is to be seeded with an initial value of 0.

public class MsoCrc32
{
  private const int BUFFER_SIZE =  4096 ;
  private static readonly uint[] cache ;

  public uint Value { get ; private set ; }

  public void Add( byte[] bytes )
  {
    foreach ( byte octet in bytes )
    {
      uint i = ( Value >> 24 ) ^ octet ;

      Value <<= 8        ;
      Value  ^= cache[i] ;

    }

    return ;
  }
  public void Add( Stream s )
  {
    byte[] buffer = new byte[BUFFER_SIZE] ;
    int    bufl   = 0 ;

    while ( (bufl=s.Read(buffer,0,buffer.Length)) > 0 )
    {
      Add( buffer ) ;
    }

    return ;
  }

  public MsoCrc32() : this(0)
  {
  }
  public MsoCrc32( int value )
  {
    this.Value = (uint) value ;
  }
  static MsoCrc32()
  {
    cache = InitCache();
    return ;
  }

  private static uint[] InitCache()
  {
    uint[] cacheInstance = new uint[256] ;

    for ( uint i = 0 ; i < cache.Length ; ++i )
    {
      uint value = i << 24 ;

      for ( uint j = 0 ; j < 8 ; ++j )
      {
        value <<= 1 ;
        if ( 0x80000000 == (value&0x80000000) )
        {
          value  ^= 0xAF000000 ;
        }
      }

      value &= 0xFFFF0000 ;

      cacheInstance[i] = value ;

    }

    return cacheInstance ;
  }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文