<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.mechsploit.me/index.php?action=history&amp;feed=atom&amp;title=Module%3ACrc32lua</id>
	<title>Module:Crc32lua - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.mechsploit.me/index.php?action=history&amp;feed=atom&amp;title=Module%3ACrc32lua"/>
	<link rel="alternate" type="text/html" href="https://wiki.mechsploit.me/index.php?title=Module:Crc32lua&amp;action=history"/>
	<updated>2026-04-08T15:49:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.mechsploit.me/index.php?title=Module:Crc32lua&amp;diff=306&amp;oldid=prev</id>
		<title>MechsploWikiSysop: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.mechsploit.me/index.php?title=Module:Crc32lua&amp;diff=306&amp;oldid=prev"/>
		<updated>2025-09-02T02:50:20Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:50, 1 September 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>MechsploWikiSysop</name></author>
	</entry>
	<entry>
		<id>https://wiki.mechsploit.me/index.php?title=Module:Crc32lua&amp;diff=305&amp;oldid=prev</id>
		<title>118.166.129.169: Created page with &quot;--[[  LUA MODULE    digest.crc32 - CRC-32 checksum implemented entirely in Lua.  SYNOPSIS    local CRC = require &#039;digest.crc32lua&#039;   print(CRC.crc32 &#039;test&#039;) --&gt; 0xD87F7E0C or...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.mechsploit.me/index.php?title=Module:Crc32lua&amp;diff=305&amp;oldid=prev"/>
		<updated>2019-07-13T14:25:35Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;--[[  LUA MODULE    digest.crc32 - CRC-32 checksum implemented entirely in Lua.  SYNOPSIS    local CRC = require &amp;#039;digest.crc32lua&amp;#039;   print(CRC.crc32 &amp;#039;test&amp;#039;) --&amp;gt; 0xD87F7E0C or...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[&lt;br /&gt;
&lt;br /&gt;
LUA MODULE&lt;br /&gt;
&lt;br /&gt;
  digest.crc32 - CRC-32 checksum implemented entirely in Lua.&lt;br /&gt;
&lt;br /&gt;
SYNOPSIS&lt;br /&gt;
&lt;br /&gt;
  local CRC = require &amp;#039;digest.crc32lua&amp;#039;&lt;br /&gt;
  print(CRC.crc32 &amp;#039;test&amp;#039;) --&amp;gt; 0xD87F7E0C or -662733300&lt;br /&gt;
  &lt;br /&gt;
  assert(CRC.crc32(&amp;#039;st&amp;#039;, CRC.crc32(&amp;#039;te&amp;#039;)) == CRC.crc32 &amp;#039;test&amp;#039;)&lt;br /&gt;
  &lt;br /&gt;
DESCRIPTION&lt;br /&gt;
&lt;br /&gt;
  This can be used to compute CRC-32 checksums on strings.&lt;br /&gt;
  This is similar to [1-2].&lt;br /&gt;
&lt;br /&gt;
API&lt;br /&gt;
&lt;br /&gt;
  Note: in the functions below, checksums are 32-bit integers stored in&lt;br /&gt;
  numbers.  The number format currently depends on the bit&lt;br /&gt;
  implementation--see DESIGN NOTES below.&lt;br /&gt;
&lt;br /&gt;
  CRC.crc32_byte(byte [, crc]) --&amp;gt; rcrc&lt;br /&gt;
  &lt;br /&gt;
    Returns CRC-32 checksum `rcrc` of byte `byte` (number 0..255) appended to&lt;br /&gt;
    a string with CRC-32 checksum `crc`.  `crc` defaults to 0 (empty string)&lt;br /&gt;
    if omitted.&lt;br /&gt;
&lt;br /&gt;
  CRC.crc32_string(s, crc) --&amp;gt; bcrc&lt;br /&gt;
&lt;br /&gt;
    Returns CRC-32 checksum `rcrc` of string `s` appended to&lt;br /&gt;
    a string with CRC-32 checksum `crc`.  `crc` defaults to 0 (empty string)&lt;br /&gt;
    if omitted.&lt;br /&gt;
  &lt;br /&gt;
  CRC.crc32(o, crc) --&amp;gt; bcrc&lt;br /&gt;
&lt;br /&gt;
    This invokes `crc32_byte` if `o` is a byte or `crc32_string` if `o`&lt;br /&gt;
    is a string.&lt;br /&gt;
  &lt;br /&gt;
  CRC.bit&lt;br /&gt;
&lt;br /&gt;
    This contains the underlying bit library used by the module.  It&lt;br /&gt;
    should be considered a read-only copy.&lt;br /&gt;
&lt;br /&gt;
DESIGN NOTES&lt;br /&gt;
&lt;br /&gt;
  Currently, this module exposes the underlying bit array implementation in CRC&lt;br /&gt;
  checksums returned.  In BitOp, bit arrays are 32-bit signed integer numbers&lt;br /&gt;
  (may be negative).  In Lua 5.2 &amp;#039;bit32&amp;#039; and &amp;#039;bit.numberlua&amp;#039;, bit arrays are&lt;br /&gt;
  32-bit unsigned integer numbers (non-negative).  This is subject to change&lt;br /&gt;
  in the future but is currently done due to (unconfirmed) performance&lt;br /&gt;
  implications.&lt;br /&gt;
  &lt;br /&gt;
  On platforms with 64-bit numbers, one way to normalize CRC&lt;br /&gt;
  checksums to be unsigned is to do `crcvalue % 2^32`,&lt;br /&gt;
  &lt;br /&gt;
  The name of this module is inspired by Perl `Digest::CRC*`.&lt;br /&gt;
&lt;br /&gt;
DEPENDENCIES&lt;br /&gt;
 &lt;br /&gt;
  Requires one of the following bit libraries:&lt;br /&gt;
&lt;br /&gt;
    BitOp &amp;quot;bit&amp;quot; -- bitop.luajit.org -- This is included in LuaJIT and also available&lt;br /&gt;
      for Lua 5.1/5.2.  This provides the fastest performance in LuaJIT.&lt;br /&gt;
    Lua 5.2 &amp;quot;bit32&amp;quot; -- www.lua.org/manual/5.2 -- This is provided in Lua 5.2&lt;br /&gt;
      and is preferred in 5.2 (unless &amp;quot;bit&amp;quot; also happens to be installed).&lt;br /&gt;
    &amp;quot;bit.numberlua&amp;quot; (&amp;gt;=000.003) -- https://github.com/davidm/lua-bit-numberlua&lt;br /&gt;
      This is slowest and used as a last resort.&lt;br /&gt;
      It is only a few times slower than &amp;quot;bit32&amp;quot; though.&lt;br /&gt;
&lt;br /&gt;
DOWNLOAD/INSTALLATION&lt;br /&gt;
&lt;br /&gt;
  If using LuaRocks:&lt;br /&gt;
    luarocks install lua-digest-crc32lua&lt;br /&gt;
&lt;br /&gt;
  Otherwise, download &amp;lt;https://github.com/davidm/lua-digest-crc32lua/zipball/master&amp;gt;.&lt;br /&gt;
  Alternately, if using git:&lt;br /&gt;
    git clone git://github.com/davidm/lua-digest-crc32lua.git&lt;br /&gt;
    cd lua-digest-crc32lua&lt;br /&gt;
  Optionally unpack:&lt;br /&gt;
    ./util.mk&lt;br /&gt;
  or unpack and install in LuaRocks:&lt;br /&gt;
    ./util.mk install &lt;br /&gt;
  &lt;br /&gt;
REFERENCES&lt;br /&gt;
&lt;br /&gt;
  [1] http://www.axlradius.com/freestuff/CRC32.java&lt;br /&gt;
  [2] http://www.gamedev.net/reference/articles/article1941.asp&lt;br /&gt;
  [3] http://java.sun.com/j2se/1.5.0/docs/api/java/util/zip/CRC32.html&lt;br /&gt;
  [4] http://www.dsource.org/projects/tango/docs/current/tango.io.digest.Crc32.html&lt;br /&gt;
  [5] http://pydoc.org/1.5.2/zlib.html#-crc32&lt;br /&gt;
  [6] http://www.python.org/doc/2.5.2/lib/module-binascii.html&lt;br /&gt;
 &lt;br /&gt;
LICENSE&lt;br /&gt;
&lt;br /&gt;
  (c) 2008-2011 David Manura.  Licensed under the same terms as Lua (MIT).&lt;br /&gt;
&lt;br /&gt;
  Permission is hereby granted, free of charge, to any person obtaining a copy&lt;br /&gt;
  of this software and associated documentation files (the &amp;quot;Software&amp;quot;), to deal&lt;br /&gt;
  in the Software without restriction, including without limitation the rights&lt;br /&gt;
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell&lt;br /&gt;
  copies of the Software, and to permit persons to whom the Software is&lt;br /&gt;
  furnished to do so, subject to the following conditions:&lt;br /&gt;
&lt;br /&gt;
  The above copyright notice and this permission notice shall be included in&lt;br /&gt;
  all copies or substantial portions of the Software.&lt;br /&gt;
&lt;br /&gt;
  THE SOFTWARE IS PROVIDED &amp;quot;AS IS&amp;quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR&lt;br /&gt;
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,&lt;br /&gt;
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE&lt;br /&gt;
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER&lt;br /&gt;
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,&lt;br /&gt;
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN&lt;br /&gt;
  THE SOFTWARE.&lt;br /&gt;
  (end license)&lt;br /&gt;
 &lt;br /&gt;
--]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local M = {_TYPE=&amp;#039;module&amp;#039;, _NAME=&amp;#039;digest.crc32&amp;#039;, _VERSION=&amp;#039;0.3.20111128&amp;#039;}&lt;br /&gt;
&lt;br /&gt;
local type = type&lt;br /&gt;
local require = require&lt;br /&gt;
local setmetatable = setmetatable&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
 Requires the first module listed that exists, else raises like `require`.&lt;br /&gt;
 If a non-string is encountered, it is returned.&lt;br /&gt;
 Second return value is module name loaded (or &amp;#039;&amp;#039;).&lt;br /&gt;
 --]]&lt;br /&gt;
local function requireany(...)&lt;br /&gt;
  local errs = {}&lt;br /&gt;
  for _,name in ipairs{...} do&lt;br /&gt;
    if type(name) ~= &amp;#039;string&amp;#039; then return name, &amp;#039;&amp;#039; end&lt;br /&gt;
    local ok, mod = pcall(require, name)&lt;br /&gt;
    if ok then return mod, name end&lt;br /&gt;
    errs[#errs+1] = mod&lt;br /&gt;
  end&lt;br /&gt;
  error(table.concat(errs, &amp;#039;\n&amp;#039;), 2)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local bit, name_ = requireany(&amp;#039;bit32&amp;#039;, &amp;#039;bit&amp;#039;, &amp;#039;bit.numberlua&amp;#039;)&lt;br /&gt;
local bxor = bit.bxor&lt;br /&gt;
local bnot = bit.bnot&lt;br /&gt;
local band = bit.band&lt;br /&gt;
local rshift = bit.rshift&lt;br /&gt;
&lt;br /&gt;
-- CRC-32-IEEE 802.3 (V.42)&lt;br /&gt;
local POLY = 0xEDB88320&lt;br /&gt;
&lt;br /&gt;
-- Memoize function pattern (like http://lua-users.org/wiki/FuncTables ).&lt;br /&gt;
local function memoize(f)&lt;br /&gt;
  local mt = {}&lt;br /&gt;
  local t = setmetatable({}, mt)&lt;br /&gt;
  function mt:__index(k)&lt;br /&gt;
    local v = f(k); t[k] = v&lt;br /&gt;
    return v&lt;br /&gt;
  end&lt;br /&gt;
  return t&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- CRC table.&lt;br /&gt;
local crc_table = memoize(function(i)&lt;br /&gt;
  local crc = i&lt;br /&gt;
  for _=1,8 do&lt;br /&gt;
    local b = band(crc, 1)&lt;br /&gt;
    crc = rshift(crc, 1)&lt;br /&gt;
    if b == 1 then crc = bxor(crc, POLY) end&lt;br /&gt;
  end&lt;br /&gt;
  return crc&lt;br /&gt;
end)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function M.crc32_byte(byte, crc)&lt;br /&gt;
  crc = bnot(crc or 0)&lt;br /&gt;
  local v1 = rshift(crc, 8)&lt;br /&gt;
  local v2 = crc_table[bxor(crc % 256, byte)]&lt;br /&gt;
  return bnot(bxor(v1, v2))&lt;br /&gt;
end&lt;br /&gt;
local M_crc32_byte = M.crc32_byte&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function M.crc32_string(s, crc)&lt;br /&gt;
  crc = crc or 0&lt;br /&gt;
  for i=1,#s do&lt;br /&gt;
    crc = M_crc32_byte(s:byte(i), crc)&lt;br /&gt;
  end&lt;br /&gt;
  return crc&lt;br /&gt;
end&lt;br /&gt;
local M_crc32_string = M.crc32_string&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function M.crc32(s, crc)&lt;br /&gt;
  if type(s) == &amp;#039;string&amp;#039; then&lt;br /&gt;
    return M_crc32_string(s, crc)&lt;br /&gt;
  else&lt;br /&gt;
    return M_crc32_byte(s, crc)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
M.bit = bit  -- bit library used&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
return M&lt;/div&gt;</summary>
		<author><name>118.166.129.169</name></author>
	</entry>
</feed>