⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adler32.cpp

📁 非常好用的五子棋游戏源码
💻 CPP
字号:
// Created:10-22-98
// By Jeff Connelly

// Adler32 calculation, similar to CRC

// I DO NOT CLAIM I WROTE THE ORIGINAL SOFTWARE
// THIS IS A MODIFIED VERSION OF ADLER32.C FROM ZLIB
// THIS IS NOT THE ORIGINAL SOFTWARE

#include "stdafx.h"
#define EXPORTING
#include "comprlib.h"

// Largest prime under 65536 (0xFFFF)
#define BASE   65521L

// Largest n that 255n(n + 1) / 2 + (n + 1)(BASE - 1) <= 2 ^ 32 - 1
#define NMAX   5552

#define DO1(buf, i) {s1 += buf[i]; s2 += s1;}
#define DO2(buf, i) DO1(buf, i); DO1(buf, i + 1);
#define DO4(buf, i) DO2(buf, i); DO2(buf, i + 2);
#define DO8(buf, i) DO4(buf, i); DO4(buf, i + 4);
#define DO16(buf)   DO8(buf, 0); DO8(buf, 8);

// Updates the Adler32 'adler' using 'buf' that is 'len' bytes long.  The
// reason why it takes a string instead of a single character is for speed.
// Calling this n times will be slower than calling is 1 time with 'buf'
// containing n bytes.
unsigned long EXPORT adler32(unsigned long adler, char* buf, unsigned int len)
{
    unsigned long s1 = adler & 0xFFFF;
    unsigned long s2 = (adler >> 0x10) & 0xFFFF;
    int k;

    if (!buf)
        return 1L;

    while (len > 0)
    {
        k = len < NMAX ? len : NMAX;
        len -= k;
        while (k >= 0x10)
        {
            DO16(buf);
            buf += 0x10;
            k -= 0x10;
        }
        if (!k)
        {
            do
            {
                s1 += *buf++;
                s2 += s1;
            } while (--k);
            s1 %= BASE;
            s2 %= BASE;
        }
    }
    return (s2 << 0x10) | s1;
}

// Generates a Adler32 for the whole input file, output file not messed with
unsigned long EXPORT adler32()
{
    register unsigned long adler = 0;
    char c;

    while (!end_of_data())
    {
        c = read_byte();
        adler32(adler, &c, 1);
    }
	return adler;
}
        


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -