view src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhCRC.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line source
1 // LzhCRC.cpp
3 #include "StdAfx.h"
5 #include "LzhCRC.h"
7 namespace NArchive {
8 namespace NLzh {
10 static const UInt16 kCRCPoly = 0xA001;
12 UInt16 CCRC::Table[256];
14 void CCRC::InitTable()
15 {
16 for (UInt32 i = 0; i < 256; i++)
17 {
18 UInt32 r = i;
19 for (int j = 0; j < 8; j++)
20 if (r & 1)
21 r = (r >> 1) ^ kCRCPoly;
22 else
23 r >>= 1;
24 CCRC::Table[i] = (UInt16)r;
25 }
26 }
28 class CCRCTableInit
29 {
30 public:
31 CCRCTableInit() { CCRC::InitTable(); }
32 } g_CRCTableInit;
34 void CCRC::Update(const void *data, size_t size)
35 {
36 UInt16 v = _value;
37 const Byte *p = (const Byte *)data;
38 for (; size > 0; size--, p++)
39 v = (UInt16)(Table[((Byte)(v)) ^ *p] ^ (v >> 8));
40 _value = v;
41 }
43 }}