Mercurial > vba-linux
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhCRC.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,43 @@ 1.4 +// LzhCRC.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include "LzhCRC.h" 1.9 + 1.10 +namespace NArchive { 1.11 +namespace NLzh { 1.12 + 1.13 +static const UInt16 kCRCPoly = 0xA001; 1.14 + 1.15 +UInt16 CCRC::Table[256]; 1.16 + 1.17 +void CCRC::InitTable() 1.18 +{ 1.19 + for (UInt32 i = 0; i < 256; i++) 1.20 + { 1.21 + UInt32 r = i; 1.22 + for (int j = 0; j < 8; j++) 1.23 + if (r & 1) 1.24 + r = (r >> 1) ^ kCRCPoly; 1.25 + else 1.26 + r >>= 1; 1.27 + CCRC::Table[i] = (UInt16)r; 1.28 + } 1.29 +} 1.30 + 1.31 +class CCRCTableInit 1.32 +{ 1.33 +public: 1.34 + CCRCTableInit() { CCRC::InitTable(); } 1.35 +} g_CRCTableInit; 1.36 + 1.37 +void CCRC::Update(const void *data, size_t size) 1.38 +{ 1.39 + UInt16 v = _value; 1.40 + const Byte *p = (const Byte *)data; 1.41 + for (; size > 0; size--, p++) 1.42 + v = (UInt16)(Table[((Byte)(v)) ^ *p] ^ (v >> 8)); 1.43 + _value = v; 1.44 +} 1.45 + 1.46 +}}