Skip to content

Commit

Permalink
Moved CRC16-CCITT code to library. (#37)
Browse files Browse the repository at this point in the history
Added Base32Hex library to allow eight flags in a single ASCII digit. (#36)
  • Loading branch information
mrogaski committed Oct 24, 2014
1 parent 0ca8685 commit b4200cf
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 142 deletions.
19 changes: 13 additions & 6 deletions Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ SOFTWARE.
--
-- Debugging levels
--
GW_D_NONE = 0
GW_D_ERROR = 1
GW_D_WARNING = 2
GW_D_NOTICE = 3
GW_D_INFO = 4
GW_D_DEBUG = 5
GW_LOG_NONE = 0
GW_LOG_ERROR = 1
GW_LOG_WARNING = 2
GW_LOG_NOTICE = 3
GW_LOG_INFO = 4
GW_LOG_DEBUG = 5


--
-- Message Flags
--
GW_MSG_END = 0x01
GW_MSG_CRYPT = 0x02

209 changes: 109 additions & 100 deletions GreenWall.lua

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions GreenWall.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
## Title: GreenWall
## Notes: Common communication channel as a replacement for guild chat in guild confederations.
## Author: Mark Rogaski <[email protected]>
## Version: 2.0.0-alpha
## Version: 1.6.0-alpha
## URL: https://github.com/AIE-Guild/GreenWall/releases
## URL: http://wow.curse.com/downloads/wow-addons/details/greenwall.aspx
## DefaultState: enabled
## SavedVariablesPerCharacter: GreenWall,GreenWallLog
## X-Category: Guild
## X-Date: 10/15/2014
## X-Date: 10/23/2014

Lib\Load.xml
Constants.lua
Expand Down
76 changes: 76 additions & 0 deletions Lib/Base32Hex.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
--[[--------------------------------------------------------------------------
The MIT License (MIT)
Copyright (c) 2014 Mark Rogaski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]--------------------------------------------------------------------------

----------------------------------------------------------------------------
-- Package Definition
----------------------------------------------------------------------------

local VERSION_MAJOR = "Encoding:Base32Hex-1.0"
local VERSION_MINOR = 1
local Base32Hex = LibStub:NewLibrary(VERSION_MAJOR, VERSION_MINOR)
if not Base32Hex then
return
end

--- Encode
-- @param i Integer to convert.
-- @return The base32hex string.
function Base32Hex.Encode(i)
local digit = nil
local string = ''
while i > 0 do
local k = i % 32
if k < 10 then
digit = string.char(k + 48)
else
digit = string.char(k + 55)
end
string = string .. digit
end
return string
end


--- Decode
-- @param s String to convert.
-- @return The integer value.
function Base32Hex.Decode(s)
local sum = 0
for c in string.gmatch(s, '.') do
local i = string.byte(c)
if i >= 48 and i < 58 then
sum = sum * 32 + (i - 48)
elseif i >= 65 and i < 87 then
sum = sum * 32 + (i - 65)
elseif i >= 97 and i < 119 then
sum = sum * 32 + (i - 97)
else
return
end
end
return sum
end

2 changes: 1 addition & 1 deletion Lib/Base64.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ all copies or substantial portions of the Software.
-- Package Definition
----------------------------------------------------------------------------

local VERSION_MAJOR = "Encoding:Hash:Base64-1.0"
local VERSION_MAJOR = "Encoding:Base64-1.0"
local VERSION_MINOR = 1
local Base64 = LibStub:NewLibrary(VERSION_MAJOR, VERSION_MINOR)
if not Base64 then
Expand Down
80 changes: 80 additions & 0 deletions Lib/CRC16-CCITT.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--[[--------------------------------------------------------------------------
The MIT License (MIT)
Copyright (c) 2014 Mark Rogaski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]--------------------------------------------------------------------------

----------------------------------------------------------------------------
-- Package Definition
----------------------------------------------------------------------------

local VERSION_MAJOR = "Hash:CRC:16ccitt-1.0"
local VERSION_MINOR = 1
local CRC = LibStub:NewLibrary(VERSION_MAJOR, VERSION_MINOR)
if not CRC then
return
end

----------------------------------------------------------------------------
-- Imports
----------------------------------------------------------------------------

local bxor, band, rshift = bit.bxor, bit.band, bit.rshift


----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------

--- CRC16-CCITT
-- @param str The string to hash.
-- @return The CRC hash.
function CRC.Hash(str)

if str == nil then
str = ''
end

local crc = 0xffff

for i = 1, #str do

c = str:byte(i)
crc = bxor(crc, c)

for j = 1, 8 do

local k = band(crc, 1)
crc = rshift(crc, 1)

if k ~= 0 then
crc = bxor(crc, 0x8408)
end

end

end

return crc
end

2 changes: 2 additions & 0 deletions Lib/Load.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
<Script file="LibStub.lua"/>
<Script file="CRC16-CCITT.lua"/>
<Script file="Base32Hex.lua"/>
<Script file="Base64.lua"/>
<Script file="SHA256.lua"/>
<Script file="Salsa20.lua"/>
Expand Down
33 changes: 0 additions & 33 deletions Utility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,39 +72,6 @@ function gw.Debug(level, msg)
end


--- CRC-16-CCITT
-- @param str The string to hash.
-- @return The CRC hash.
function gw.StringHash(str)

if str == nil then
str = ''
end

local crc = 0xffff

for i = 1, #str do

c = str:byte(i)
crc = bit.bxor(crc, c)

for j = 1, 8 do

local k = bit.band(crc, 1)
crc = bit.rshift(crc, 1)

if k ~= 0 then
crc = bit.bxor(crc, 0x8408)
end

end

end

return crc
end


--[[-----------------------------------------------------------------------
END
Expand Down

0 comments on commit b4200cf

Please sign in to comment.