mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-07-31 12:00:10 -07:00
@iceman1001 's updated lualibs
This commit is contained in:
parent
ab7fdfcbed
commit
9ccfb3a8bc
8 changed files with 627 additions and 30 deletions
|
@ -135,10 +135,11 @@ local _commands = {
|
||||||
CMD_MIFARE_SNIFFER = 0x0630,
|
CMD_MIFARE_SNIFFER = 0x0630,
|
||||||
|
|
||||||
--//ultralightC
|
--//ultralightC
|
||||||
CMD_MIFAREUC_AUTH1 = 0x0724,
|
CMD_MIFAREUC_AUTH1 = 0x0724,
|
||||||
CMD_MIFAREUC_AUTH2 = 0x0725,
|
CMD_MIFAREUC_AUTH2 = 0x0725,
|
||||||
CMD_MIFAREUC_READCARD = 0x0726,
|
CMD_MIFAREUC_READCARD = 0x0726,
|
||||||
CMD_MIFAREUC_SETPWD = 0x0727,
|
CMD_MIFAREUC_SETPWD = 0x0727,
|
||||||
|
CMD_MIFAREU_SETUID = 0x0728,
|
||||||
|
|
||||||
--// mifare desfire
|
--// mifare desfire
|
||||||
CMD_MIFARE_DESFIRE_READBL = 0x0728,
|
CMD_MIFARE_DESFIRE_READBL = 0x0728,
|
||||||
|
@ -154,10 +155,10 @@ local _commands = {
|
||||||
|
|
||||||
|
|
||||||
local _reverse_lookup,k,v = {}
|
local _reverse_lookup,k,v = {}
|
||||||
for k, v in pairs(_commands) do
|
for k, v in pairs(_commands) do
|
||||||
_reverse_lookup[v] = k
|
_reverse_lookup[v] = k
|
||||||
end
|
end
|
||||||
_commands.tostring = function(command)
|
_commands.tostring = function(command)
|
||||||
if(type(command) == 'number') then
|
if(type(command) == 'number') then
|
||||||
return ("%s (%d)"):format(_reverse_lookup[command]or "ERROR UNDEFINED!", command)
|
return ("%s (%d)"):format(_reverse_lookup[command]or "ERROR UNDEFINED!", command)
|
||||||
end
|
end
|
||||||
|
@ -218,7 +219,6 @@ function Command:getBytes()
|
||||||
local data = self.data
|
local data = self.data
|
||||||
local cmd = self.cmd
|
local cmd = self.cmd
|
||||||
local arg1, arg2, arg3 = self.arg1, self.arg2, self.arg3
|
local arg1, arg2, arg3 = self.arg1, self.arg2, self.arg3
|
||||||
|
return bin.pack("LLLLH",cmd, arg1, arg2, arg3, data);
|
||||||
return bin.pack("LLLLH",cmd, arg1, arg2, arg3,data);
|
|
||||||
end
|
end
|
||||||
return _commands
|
return _commands
|
||||||
|
|
|
@ -24,6 +24,7 @@ local _names = {
|
||||||
{"13", "0d00", "0030", "water", "regular", "Wham Shell"},
|
{"13", "0d00", "0030", "water", "regular", "Wham Shell"},
|
||||||
{"14", "0e00", "0030", "water", "regular", "Gill Grunt"},
|
{"14", "0e00", "0030", "water", "regular", "Gill Grunt"},
|
||||||
--{"14", "0e00", "0030", "water", "regular", "Elite Gill Grunt"},
|
--{"14", "0e00", "0030", "water", "regular", "Elite Gill Grunt"},
|
||||||
|
--{"14", "0e00", "0030", "water", "regular", "Tidal Wave Gill Grunt"},
|
||||||
{"15", "0f00", "0030", "water", "regular", "Slam Bam"},
|
{"15", "0f00", "0030", "water", "regular", "Slam Bam"},
|
||||||
--{"15", "0f00", "0030", "water", "regular", "Surfer Slam Bam"},
|
--{"15", "0f00", "0030", "water", "regular", "Surfer Slam Bam"},
|
||||||
{"16", "1000", "0030", "magic", "regular", "Spyro"},
|
{"16", "1000", "0030", "magic", "regular", "Spyro"},
|
||||||
|
@ -43,7 +44,8 @@ local _names = {
|
||||||
{"25", "1900", "0030", "life", "regular", "Zook"},
|
{"25", "1900", "0030", "life", "regular", "Zook"},
|
||||||
{"26", "1a00", "0030", "life", "regular", "Stealth Elf"},
|
{"26", "1a00", "0030", "life", "regular", "Stealth Elf"},
|
||||||
--{"26", "1a00", "0030", "life", "regular", "Elite Stealth Elf"},
|
--{"26", "1a00", "0030", "life", "regular", "Elite Stealth Elf"},
|
||||||
--{"26", "1a00", "0030", "life", "regular", "Dark Stealth Elf"},
|
--{"26", "1a00", "0528", "life", "regular", "Dark Stealth Elf"},
|
||||||
|
{"26", "1a00", "0528", "life", "swapforce", "Ninja Stealth Elf"},
|
||||||
{"27", "1b00", "0030", "life", "regular", "Stump Smash"},
|
{"27", "1b00", "0030", "life", "regular", "Stump Smash"},
|
||||||
{"27", "1b00", "0118", "life", "regular", "Stump Smash"},
|
{"27", "1b00", "0118", "life", "regular", "Stump Smash"},
|
||||||
--{"27", "1b00", "0030", "life", "regular", "Autumn Stump Smash"},
|
--{"27", "1b00", "0030", "life", "regular", "Autumn Stump Smash"},
|
||||||
|
@ -59,6 +61,7 @@ local _names = {
|
||||||
--{"32", "2000", "0030", "undead", "regular", "Skeletal Cynder"},
|
--{"32", "2000", "0030", "undead", "regular", "Skeletal Cynder"},
|
||||||
|
|
||||||
{"100", "6400", "0030", "air", "giant", "Jet Vac"},
|
{"100", "6400", "0030", "air", "giant", "Jet Vac"},
|
||||||
|
--{"100", "6400", "0030", "air", "giant", "Full blast Jet Vac"},
|
||||||
{"101", "6500", "0030", "air", "giant", "Swarm"},
|
{"101", "6500", "0030", "air", "giant", "Swarm"},
|
||||||
{"102", "6600", "0030", "earth", "giant", "Crusher"},
|
{"102", "6600", "0030", "earth", "giant", "Crusher"},
|
||||||
{"103", "6700", "0030", "earth", "giant", "Flashwing"},
|
{"103", "6700", "0030", "earth", "giant", "Flashwing"},
|
||||||
|
@ -73,12 +76,14 @@ local _names = {
|
||||||
--{"108", "6c00", "0030", "magic", "giant", "Hoppity Pop Fizz"},
|
--{"108", "6c00", "0030", "magic", "giant", "Hoppity Pop Fizz"},
|
||||||
{"108", "6c00", "023c", "magic", "giant", "Love Potion Pop Fizz"},
|
{"108", "6c00", "023c", "magic", "giant", "Love Potion Pop Fizz"},
|
||||||
--{"108", "6c00", "0030", "magic", "giant", "Punch Pop Fizz"},
|
--{"108", "6c00", "0030", "magic", "giant", "Punch Pop Fizz"},
|
||||||
|
--{"108", "6c00", "0030", "magic", "giant", "Fizzy Frenzy Pop Fizz"},
|
||||||
{"109", "6d00", "0030", "magic", "giant", "Nin Jini"},
|
{"109", "6d00", "0030", "magic", "giant", "Nin Jini"},
|
||||||
{"110", "6e00", "0030", "tech", "giant", "Bouncer"},
|
{"110", "6e00", "0030", "tech", "giant", "Bouncer"},
|
||||||
{"111", "6f00", "0030", "tech", "giant", "Sprocket"},
|
{"111", "6f00", "0030", "tech", "giant", "Sprocket"},
|
||||||
{"112", "7000", "0030", "life", "giant", "Tree Rex"},
|
{"112", "7000", "0030", "life", "giant", "Tree Rex"},
|
||||||
--{"112", "7000", "0030", "life", "giant", "Gnarly Tree Rex"},
|
--{"112", "7000", "0030", "life", "giant", "Gnarly Tree Rex"},
|
||||||
{"113", "7100", "0030", "life", "giant", "Shroomboom"}, --lightcore
|
{"113", "7100", "0030", "life", "giant", "Shroomboom"},
|
||||||
|
--{"113", "7100", "0030", "life", "giant", "Sure shot Shroomboom"},
|
||||||
{"114", "7200", "0030", "undead", "giant", "Eye Broawl"},
|
{"114", "7200", "0030", "undead", "giant", "Eye Broawl"},
|
||||||
{"115", "7300", "0030", "undead", "giant", "Fright Rider"},
|
{"115", "7300", "0030", "undead", "giant", "Fright Rider"},
|
||||||
|
|
||||||
|
@ -268,27 +273,35 @@ local _names = {
|
||||||
{"485", "e501", "0030", "dark", "regular", "Blackout"},
|
{"485", "e501", "0030", "dark", "regular", "Blackout"},
|
||||||
--{"485", "e501", "0234", "dark", "regular", "Special Blackout"},
|
--{"485", "e501", "0234", "dark", "regular", "Special Blackout"},
|
||||||
|
|
||||||
|
-- MINI's
|
||||||
{"502", "f601", "0030", "earth", "mini", "Bop"},
|
{"502", "f601", "0030", "earth", "mini", "Bop"},
|
||||||
{"503", "f701", "0030", "magic", "mini", "Spry"},
|
|
||||||
{"504", "f801", "0030", "undead", "mini", "Hijinx"},
|
|
||||||
{"505", "f901", "0030", "earth", "mini", "Terrabite"},
|
{"505", "f901", "0030", "earth", "mini", "Terrabite"},
|
||||||
|
|
||||||
{"506", "fa01", "0030", "air", "mini", "Breeze"},
|
{"506", "fa01", "0030", "air", "mini", "Breeze"},
|
||||||
{"507", "fb01", "0030", "fire", "mini", "Weeruptor"},
|
|
||||||
--{"507", "fb01", "0030", "fire", "mini", "Eggsellent Weeruptor"},
|
|
||||||
{"508", "fc01", "0030", "air", "mini", "Pet Vac"},
|
{"508", "fc01", "0030", "air", "mini", "Pet Vac"},
|
||||||
--{"508", "fc01", "0030", "air", "mini", "Power Punch Pet Vac"},
|
--{"508", "fc01", "0030", "air", "mini", "Power Punch Pet Vac"},
|
||||||
|
|
||||||
|
{"507", "fb01", "0030", "fire", "mini", "Weeruptor"},
|
||||||
|
--{"507", "fb01", "0030", "fire", "mini", "Eggsellent Weeruptor"},
|
||||||
{"509", "fd01", "0030", "fire", "mini", "Small Fry"},
|
{"509", "fd01", "0030", "fire", "mini", "Small Fry"},
|
||||||
|
|
||||||
{"510", "fe01", "0030", "tech", "mini", "Drobit"},
|
{"510", "fe01", "0030", "tech", "mini", "Drobit"},
|
||||||
{"514", "0202", "0030", "water", "mini", "Gill Runt"},
|
|
||||||
{"519", "0702", "0030", "tech", "mini", "Trigger Snappy"},
|
{"519", "0702", "0030", "tech", "mini", "Trigger Snappy"},
|
||||||
|
|
||||||
{"526", "0e02", "0030", "life", "mini", "Whisper Elf"},
|
{"526", "0e02", "0030", "life", "mini", "Whisper Elf"},
|
||||||
{"540", "1c02", "0030", "life", "mini", "Barkley"},
|
{"540", "1c02", "0030", "life", "mini", "Barkley"},
|
||||||
--{"540", "1c02", "0030", "life", "mini", "Gnarly Barkley"},
|
--{"540", "1c02", "0030", "life", "mini", "Gnarly Barkley"},
|
||||||
|
|
||||||
{"541", "1d02", "0030", "water", "mini", "Thumpling"},
|
{"541", "1d02", "0030", "water", "mini", "Thumpling"},
|
||||||
|
{"514", "0202", "0030", "water", "mini", "Gill Runt"},
|
||||||
|
|
||||||
{"542", "1e02", "0030", "magic", "mini", "mini Jini"},
|
{"542", "1e02", "0030", "magic", "mini", "mini Jini"},
|
||||||
|
{"503", "f701", "0030", "magic", "mini", "Spry"},
|
||||||
|
|
||||||
|
{"504", "f801", "0030", "undead", "mini", "Hijinx"},
|
||||||
{"543", "1f02", "0030", "undead", "mini", "Eye Small"},
|
{"543", "1f02", "0030", "undead", "mini", "Eye Small"},
|
||||||
|
|
||||||
{"3000", "b80b", "0030", "air", "SWAPFORCE", "Scratch"},
|
{"3000", "b80b", "0030", "air", "mini", "Scratch", "SWAPFORCE"},
|
||||||
{"3001", "b90b", "0030", "air", "SWAPFORCE", "Pop Thorn"},
|
{"3001", "b90b", "0030", "air", "SWAPFORCE", "Pop Thorn"},
|
||||||
--{"3001", "b90b", "0030", "air", "SWAPFORCE", "Buttered Pop Thorn"},
|
--{"3001", "b90b", "0030", "air", "SWAPFORCE", "Buttered Pop Thorn"},
|
||||||
{"3002", "ba0b", "0030", "earth", "SWAPFORCE", "Slobber Tooth"},
|
{"3002", "ba0b", "0030", "earth", "SWAPFORCE", "Slobber Tooth"},
|
||||||
|
@ -315,6 +328,29 @@ local _names = {
|
||||||
{"3013", "c50b", "0030", "undead", "SWAPFORCE", "Grim Creeper"},
|
{"3013", "c50b", "0030", "undead", "SWAPFORCE", "Grim Creeper"},
|
||||||
{"3014", "c60b", "0030", "water", "SWAPFORCE", "Rip Tide"},
|
{"3014", "c60b", "0030", "water", "SWAPFORCE", "Rip Tide"},
|
||||||
{"3015", "c70b", "0030", "water", "SWAPFORCE", "Punk Shock"},
|
{"3015", "c70b", "0030", "water", "SWAPFORCE", "Punk Shock"},
|
||||||
|
|
||||||
|
--{"", "", "0030", "water", "SWAPFORCE", "Hoot Loop"},
|
||||||
|
--{"", "", "0030", "water", "SWAPFORCE", "Trap Shadow"},
|
||||||
|
--{"", "", "0030", "water", "SWAPFORCE", "Wash Buckler"},
|
||||||
|
--{"", "", "0030", "water", "SWAPFORCE", "Freeze Blade"},
|
||||||
|
--{"", "", "0030", "fire", "SWAPFORCE", "Magna Charge"},
|
||||||
|
--{"", "", "0030", "fire", "SWAPFORCE", "Spy Rise"},
|
||||||
|
|
||||||
|
--{"", "", "0030", "fire", "SWAPFORCE", "Doom Stone"},
|
||||||
|
--{"", "", "0030", "fire", "SWAPFORCE", "Rubble Rouser"},
|
||||||
|
|
||||||
|
--{"", "", "0030", "fire", "SWAPFORCE", "Blast Zone"}
|
||||||
|
--{"", "", "0030", "fire", "SWAPFORCE", "Fire Kraken"},
|
||||||
|
|
||||||
|
--{"", "", "0030", "fire", "SWAPFORCE", "Rattle Shake"},
|
||||||
|
--{"", "", "0030", "fire", "SWAPFORCE", "Night Shift"},
|
||||||
|
|
||||||
|
--{"", "", "0030", "life", "SWAPFORCE", "Stink Bomb"},
|
||||||
|
--{"", "", "0030", "life", "SWAPFORCE", "Grilla Drilla"},
|
||||||
|
|
||||||
|
--{"", "", "0030", "air", "SWAPFORCE", "Free Ranger"},
|
||||||
|
--{"", "", "0030", "air", "SWAPFORCE", "Boom Jet"},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local function find( main, sub)
|
local function find( main, sub)
|
||||||
|
@ -327,7 +363,15 @@ local function find( main, sub)
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
local function list()
|
||||||
|
print ("Type\tSub\tElement\tGame Name")
|
||||||
|
print (string.rep('=', 54))
|
||||||
|
for k, v in pairs(_names) do
|
||||||
|
print(("%s\t%s\t%s\t%-9s\t%s"):format(v[2],v[3],v[4], v[5], v[6] ))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Find = find,
|
Find = find,
|
||||||
|
List = list,
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ end
|
||||||
return {
|
return {
|
||||||
convert_bin_to_html = convert_bin_to_html,
|
convert_bin_to_html = convert_bin_to_html,
|
||||||
convert_eml_to_html = convert_eml_to_html,
|
convert_eml_to_html = convert_eml_to_html,
|
||||||
convert_eml_to_bin = convert_eml_to_bin,
|
convert_eml_to_bin = convert_eml_to_bin,
|
||||||
SaveAsBinary = save_BIN,
|
SaveAsBinary = save_BIN,
|
||||||
SaveAsText = save_TEXT,
|
SaveAsText = save_TEXT,
|
||||||
}
|
}
|
||||||
|
|
384
client/lualibs/md5.lua
Normal file
384
client/lualibs/md5.lua
Normal file
|
@ -0,0 +1,384 @@
|
||||||
|
local md5 = {
|
||||||
|
_VERSION = "md5.lua 0.5.0",
|
||||||
|
_DESCRIPTION = "MD5 computation in Lua (5.1)",
|
||||||
|
_URL = "https://github.com/kikito/md5.lua",
|
||||||
|
_LICENSE = [[
|
||||||
|
MIT LICENSE
|
||||||
|
|
||||||
|
Copyright (c) 2013 Enrique García Cota + Adam Baldwin + hanzao + Equi 4 Software
|
||||||
|
|
||||||
|
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.
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
|
||||||
|
-- bit lib implementions
|
||||||
|
|
||||||
|
local floor, abs, max = math.floor, math.abs, math.max
|
||||||
|
local char, byte, format, rep, sub =
|
||||||
|
string.char, string.byte, string.format, string.rep, string.sub
|
||||||
|
|
||||||
|
local function check_int(n)
|
||||||
|
-- checking not float
|
||||||
|
if(n - floor(n) > 0) then
|
||||||
|
error("trying to use bitwise operation on non-integer!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function tbl2number(tbl)
|
||||||
|
local n = #tbl
|
||||||
|
|
||||||
|
local rslt = 0
|
||||||
|
local power = 1
|
||||||
|
for i = 1, n do
|
||||||
|
rslt = rslt + tbl[i]*power
|
||||||
|
power = power*2
|
||||||
|
end
|
||||||
|
|
||||||
|
return rslt
|
||||||
|
end
|
||||||
|
|
||||||
|
local function expand(tbl_m, tbl_n)
|
||||||
|
local big = {}
|
||||||
|
local small = {}
|
||||||
|
if(#tbl_m > #tbl_n) then
|
||||||
|
big = tbl_m
|
||||||
|
small = tbl_n
|
||||||
|
else
|
||||||
|
big = tbl_n
|
||||||
|
small = tbl_m
|
||||||
|
end
|
||||||
|
-- expand small
|
||||||
|
for i = #small + 1, #big do
|
||||||
|
small[i] = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local to_bits -- needs to be declared before bit_not
|
||||||
|
|
||||||
|
local function bit_not(n)
|
||||||
|
local tbl = to_bits(n)
|
||||||
|
local size = max(#tbl, 32)
|
||||||
|
for i = 1, size do
|
||||||
|
if(tbl[i] == 1) then
|
||||||
|
tbl[i] = 0
|
||||||
|
else
|
||||||
|
tbl[i] = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tbl2number(tbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- defined as local above
|
||||||
|
to_bits = function (n)
|
||||||
|
check_int(n)
|
||||||
|
if(n < 0) then
|
||||||
|
-- negative
|
||||||
|
return to_bits(bit_not(abs(n)) + 1)
|
||||||
|
end
|
||||||
|
-- to bits table
|
||||||
|
local tbl = {}
|
||||||
|
local cnt = 1
|
||||||
|
while (n > 0) do
|
||||||
|
local last = math.fmod(n,2)
|
||||||
|
if(last == 1) then
|
||||||
|
tbl[cnt] = 1
|
||||||
|
else
|
||||||
|
tbl[cnt] = 0
|
||||||
|
end
|
||||||
|
n = (n-last)/2
|
||||||
|
cnt = cnt + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
|
local function bit_or(m, n)
|
||||||
|
local tbl_m = to_bits(m)
|
||||||
|
local tbl_n = to_bits(n)
|
||||||
|
expand(tbl_m, tbl_n)
|
||||||
|
|
||||||
|
local tbl = {}
|
||||||
|
local rslt = max(#tbl_m, #tbl_n)
|
||||||
|
for i = 1, rslt do
|
||||||
|
if(tbl_m[i]== 0 and tbl_n[i] == 0) then
|
||||||
|
tbl[i] = 0
|
||||||
|
else
|
||||||
|
tbl[i] = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return tbl2number(tbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function bit_and(m, n)
|
||||||
|
local tbl_m = to_bits(m)
|
||||||
|
local tbl_n = to_bits(n)
|
||||||
|
expand(tbl_m, tbl_n)
|
||||||
|
|
||||||
|
local tbl = {}
|
||||||
|
local rslt = max(#tbl_m, #tbl_n)
|
||||||
|
for i = 1, rslt do
|
||||||
|
if(tbl_m[i]== 0 or tbl_n[i] == 0) then
|
||||||
|
tbl[i] = 0
|
||||||
|
else
|
||||||
|
tbl[i] = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return tbl2number(tbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function bit_xor(m, n)
|
||||||
|
local tbl_m = to_bits(m)
|
||||||
|
local tbl_n = to_bits(n)
|
||||||
|
expand(tbl_m, tbl_n)
|
||||||
|
|
||||||
|
local tbl = {}
|
||||||
|
local rslt = max(#tbl_m, #tbl_n)
|
||||||
|
for i = 1, rslt do
|
||||||
|
if(tbl_m[i] ~= tbl_n[i]) then
|
||||||
|
tbl[i] = 1
|
||||||
|
else
|
||||||
|
tbl[i] = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return tbl2number(tbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function bit_rshift(n, bits)
|
||||||
|
check_int(n)
|
||||||
|
|
||||||
|
local high_bit = 0
|
||||||
|
if(n < 0) then
|
||||||
|
-- negative
|
||||||
|
n = bit_not(abs(n)) + 1
|
||||||
|
high_bit = 2147483648 -- 0x80000000
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=1, bits do
|
||||||
|
n = n/2
|
||||||
|
n = bit_or(floor(n), high_bit)
|
||||||
|
end
|
||||||
|
return floor(n)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function bit_lshift(n, bits)
|
||||||
|
check_int(n)
|
||||||
|
|
||||||
|
if(n < 0) then
|
||||||
|
-- negative
|
||||||
|
n = bit_not(abs(n)) + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=1, bits do
|
||||||
|
n = n*2
|
||||||
|
end
|
||||||
|
return bit_and(n, 4294967295) -- 0xFFFFFFFF
|
||||||
|
end
|
||||||
|
|
||||||
|
-- convert little-endian 32-bit int to a 4-char string
|
||||||
|
local function lei2str(i)
|
||||||
|
local f=function (s) return char( bit_and( bit_rshift(i, s), 255)) end
|
||||||
|
return f(0)..f(8)..f(16)..f(24)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- convert raw string to big-endian int
|
||||||
|
local function str2bei(s)
|
||||||
|
local v=0
|
||||||
|
for i=1, #s do
|
||||||
|
v = v * 256 + byte(s, i)
|
||||||
|
end
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
-- convert raw string to little-endian int
|
||||||
|
local function str2lei(s)
|
||||||
|
local v=0
|
||||||
|
for i = #s,1,-1 do
|
||||||
|
v = v*256 + byte(s, i)
|
||||||
|
end
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
-- cut up a string in little-endian ints of given size
|
||||||
|
local function cut_le_str(s,...)
|
||||||
|
local o, r = 1, {}
|
||||||
|
local args = {...}
|
||||||
|
for i=1, #args do
|
||||||
|
table.insert(r, str2lei(sub(s, o, o + args[i] - 1)))
|
||||||
|
o = o + args[i]
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
|
local swap = function (w) return str2bei(lei2str(w)) end
|
||||||
|
|
||||||
|
local function hex2binaryaux(hexval)
|
||||||
|
return char(tonumber(hexval, 16))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function hex2binary(hex)
|
||||||
|
local result, _ = hex:gsub('..', hex2binaryaux)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
-- An MD5 mplementation in Lua, requires bitlib (hacked to use LuaBit from above, ugh)
|
||||||
|
-- 10/02/2001 jcw@equi4.com
|
||||||
|
|
||||||
|
local FF = 0xffffffff
|
||||||
|
local CONSTS = {
|
||||||
|
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
||||||
|
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
||||||
|
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
||||||
|
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
||||||
|
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
||||||
|
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
||||||
|
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
||||||
|
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
||||||
|
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
||||||
|
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
||||||
|
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
||||||
|
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
||||||
|
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
||||||
|
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
||||||
|
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
||||||
|
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
|
||||||
|
0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476
|
||||||
|
}
|
||||||
|
|
||||||
|
local f=function (x,y,z) return bit_or(bit_and(x,y),bit_and(-x-1,z)) end
|
||||||
|
local g=function (x,y,z) return bit_or(bit_and(x,z),bit_and(y,-z-1)) end
|
||||||
|
local h=function (x,y,z) return bit_xor(x,bit_xor(y,z)) end
|
||||||
|
local i=function (x,y,z) return bit_xor(y,bit_or(x,-z-1)) end
|
||||||
|
local z=function (f,a,b,c,d,x,s,ac)
|
||||||
|
a=bit_and(a+f(b,c,d)+x+ac,FF)
|
||||||
|
-- be *very* careful that left shift does not cause rounding!
|
||||||
|
return bit_or(bit_lshift(bit_and(a,bit_rshift(FF,s)),s),bit_rshift(a,32-s))+b
|
||||||
|
end
|
||||||
|
|
||||||
|
local function transform(A,B,C,D,X)
|
||||||
|
local a,b,c,d=A,B,C,D
|
||||||
|
local t=CONSTS
|
||||||
|
|
||||||
|
a=z(f,a,b,c,d,X[ 0], 7,t[ 1])
|
||||||
|
d=z(f,d,a,b,c,X[ 1],12,t[ 2])
|
||||||
|
c=z(f,c,d,a,b,X[ 2],17,t[ 3])
|
||||||
|
b=z(f,b,c,d,a,X[ 3],22,t[ 4])
|
||||||
|
a=z(f,a,b,c,d,X[ 4], 7,t[ 5])
|
||||||
|
d=z(f,d,a,b,c,X[ 5],12,t[ 6])
|
||||||
|
c=z(f,c,d,a,b,X[ 6],17,t[ 7])
|
||||||
|
b=z(f,b,c,d,a,X[ 7],22,t[ 8])
|
||||||
|
a=z(f,a,b,c,d,X[ 8], 7,t[ 9])
|
||||||
|
d=z(f,d,a,b,c,X[ 9],12,t[10])
|
||||||
|
c=z(f,c,d,a,b,X[10],17,t[11])
|
||||||
|
b=z(f,b,c,d,a,X[11],22,t[12])
|
||||||
|
a=z(f,a,b,c,d,X[12], 7,t[13])
|
||||||
|
d=z(f,d,a,b,c,X[13],12,t[14])
|
||||||
|
c=z(f,c,d,a,b,X[14],17,t[15])
|
||||||
|
b=z(f,b,c,d,a,X[15],22,t[16])
|
||||||
|
|
||||||
|
a=z(g,a,b,c,d,X[ 1], 5,t[17])
|
||||||
|
d=z(g,d,a,b,c,X[ 6], 9,t[18])
|
||||||
|
c=z(g,c,d,a,b,X[11],14,t[19])
|
||||||
|
b=z(g,b,c,d,a,X[ 0],20,t[20])
|
||||||
|
a=z(g,a,b,c,d,X[ 5], 5,t[21])
|
||||||
|
d=z(g,d,a,b,c,X[10], 9,t[22])
|
||||||
|
c=z(g,c,d,a,b,X[15],14,t[23])
|
||||||
|
b=z(g,b,c,d,a,X[ 4],20,t[24])
|
||||||
|
a=z(g,a,b,c,d,X[ 9], 5,t[25])
|
||||||
|
d=z(g,d,a,b,c,X[14], 9,t[26])
|
||||||
|
c=z(g,c,d,a,b,X[ 3],14,t[27])
|
||||||
|
b=z(g,b,c,d,a,X[ 8],20,t[28])
|
||||||
|
a=z(g,a,b,c,d,X[13], 5,t[29])
|
||||||
|
d=z(g,d,a,b,c,X[ 2], 9,t[30])
|
||||||
|
c=z(g,c,d,a,b,X[ 7],14,t[31])
|
||||||
|
b=z(g,b,c,d,a,X[12],20,t[32])
|
||||||
|
|
||||||
|
a=z(h,a,b,c,d,X[ 5], 4,t[33])
|
||||||
|
d=z(h,d,a,b,c,X[ 8],11,t[34])
|
||||||
|
c=z(h,c,d,a,b,X[11],16,t[35])
|
||||||
|
b=z(h,b,c,d,a,X[14],23,t[36])
|
||||||
|
a=z(h,a,b,c,d,X[ 1], 4,t[37])
|
||||||
|
d=z(h,d,a,b,c,X[ 4],11,t[38])
|
||||||
|
c=z(h,c,d,a,b,X[ 7],16,t[39])
|
||||||
|
b=z(h,b,c,d,a,X[10],23,t[40])
|
||||||
|
a=z(h,a,b,c,d,X[13], 4,t[41])
|
||||||
|
d=z(h,d,a,b,c,X[ 0],11,t[42])
|
||||||
|
c=z(h,c,d,a,b,X[ 3],16,t[43])
|
||||||
|
b=z(h,b,c,d,a,X[ 6],23,t[44])
|
||||||
|
a=z(h,a,b,c,d,X[ 9], 4,t[45])
|
||||||
|
d=z(h,d,a,b,c,X[12],11,t[46])
|
||||||
|
c=z(h,c,d,a,b,X[15],16,t[47])
|
||||||
|
b=z(h,b,c,d,a,X[ 2],23,t[48])
|
||||||
|
|
||||||
|
a=z(i,a,b,c,d,X[ 0], 6,t[49])
|
||||||
|
d=z(i,d,a,b,c,X[ 7],10,t[50])
|
||||||
|
c=z(i,c,d,a,b,X[14],15,t[51])
|
||||||
|
b=z(i,b,c,d,a,X[ 5],21,t[52])
|
||||||
|
a=z(i,a,b,c,d,X[12], 6,t[53])
|
||||||
|
d=z(i,d,a,b,c,X[ 3],10,t[54])
|
||||||
|
c=z(i,c,d,a,b,X[10],15,t[55])
|
||||||
|
b=z(i,b,c,d,a,X[ 1],21,t[56])
|
||||||
|
a=z(i,a,b,c,d,X[ 8], 6,t[57])
|
||||||
|
d=z(i,d,a,b,c,X[15],10,t[58])
|
||||||
|
c=z(i,c,d,a,b,X[ 6],15,t[59])
|
||||||
|
b=z(i,b,c,d,a,X[13],21,t[60])
|
||||||
|
a=z(i,a,b,c,d,X[ 4], 6,t[61])
|
||||||
|
d=z(i,d,a,b,c,X[11],10,t[62])
|
||||||
|
c=z(i,c,d,a,b,X[ 2],15,t[63])
|
||||||
|
b=z(i,b,c,d,a,X[ 9],21,t[64])
|
||||||
|
|
||||||
|
return A+a,B+b,C+c,D+d
|
||||||
|
end
|
||||||
|
|
||||||
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
function md5.sumhexa(s)
|
||||||
|
local msgLen = #s
|
||||||
|
local padLen = 56 - msgLen % 64
|
||||||
|
|
||||||
|
if msgLen % 64 > 56 then padLen = padLen + 64 end
|
||||||
|
|
||||||
|
if padLen == 0 then padLen = 64 end
|
||||||
|
|
||||||
|
s = s .. char(128) .. rep(char(0),padLen-1) .. lei2str(8*msgLen) .. lei2str(0)
|
||||||
|
|
||||||
|
assert(#s % 64 == 0)
|
||||||
|
|
||||||
|
local t = CONSTS
|
||||||
|
local a,b,c,d = t[65],t[66],t[67],t[68]
|
||||||
|
|
||||||
|
for i=1,#s,64 do
|
||||||
|
local X = cut_le_str(sub(s,i,i+63),4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4)
|
||||||
|
assert(#X == 16)
|
||||||
|
X[0] = table.remove(X,1) -- zero based!
|
||||||
|
a,b,c,d = transform(a,b,c,d,X)
|
||||||
|
end
|
||||||
|
|
||||||
|
return format("%08x%08x%08x%08x",swap(a),swap(b),swap(c),swap(d))
|
||||||
|
end
|
||||||
|
|
||||||
|
function md5.sum(s)
|
||||||
|
return hex2binary(md5.sumhexa(s))
|
||||||
|
end
|
||||||
|
|
||||||
|
return md5
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
local _keys = {
|
local _keys = {
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
|
||||||
These keys are from the pm3 c-codebase.
|
These keys are from the pm3 c-codebase.
|
||||||
|
@ -157,9 +158,30 @@ local _keys = {
|
||||||
'9de89e070277',
|
'9de89e070277',
|
||||||
'eff603e1efe9',
|
'eff603e1efe9',
|
||||||
'644672bd4afe',
|
'644672bd4afe',
|
||||||
|
|
||||||
'b5ff67cba951',
|
'b5ff67cba951',
|
||||||
}
|
|
||||||
|
--[[
|
||||||
|
hotel system cards,
|
||||||
|
http://www.proxmark.org/forum/viewtopic.php?id=2430
|
||||||
|
--]]
|
||||||
|
'44ab09010845',
|
||||||
|
'85fed980ea5a',
|
||||||
|
|
||||||
|
--[[
|
||||||
|
VIGIK1
|
||||||
|
--]]
|
||||||
|
'314B49474956',
|
||||||
|
'564c505f4d41',
|
||||||
|
|
||||||
|
--[[
|
||||||
|
BCARD keyB
|
||||||
|
--]]
|
||||||
|
'f4a9ef2afc6d',
|
||||||
|
|
||||||
|
--[[
|
||||||
|
--]]
|
||||||
|
'a9f953def0a3',
|
||||||
|
}
|
||||||
|
|
||||||
---
|
---
|
||||||
-- The keys above have just been pasted in, for completeness sake. They contain duplicates.
|
-- The keys above have just been pasted in, for completeness sake. They contain duplicates.
|
||||||
|
|
94
client/lualibs/precalc.lua
Normal file
94
client/lualibs/precalc.lua
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
--[[
|
||||||
|
This is an experimental lib.
|
||||||
|
--]]
|
||||||
|
local utils = require('utils')
|
||||||
|
|
||||||
|
-- LOOKUP Tables
|
||||||
|
local perm = {}
|
||||||
|
perm [1]= { 0x0, 0x1, 0x3, 0x2, 0x7, 0x6, 0x4, 0x5, 0xF, 0xE, 0xC, 0xD, 0x8, 0x9, 0xB, 0xA }
|
||||||
|
perm [2]= { 0x1, 0x0, 0x2, 0x3, 0x6, 0x7, 0x5, 0x4, 0xE, 0xF, 0xD, 0xC, 0x9, 0x8, 0xA, 0xB }
|
||||||
|
perm [3]= { 0x2, 0x3, 0x1, 0x0, 0x5, 0x4, 0x6, 0x7, 0xD, 0xC, 0xE, 0xF, 0xA, 0xB, 0x9, 0x8 }
|
||||||
|
perm [4]= { 0x3, 0x2, 0x0, 0x1, 0x4, 0x5, 0x7, 0x6, 0xC, 0xD, 0xF, 0xE, 0xB, 0xA, 0x8, 0x9 }
|
||||||
|
perm [5]= { 0x4, 0x5, 0x7, 0x6, 0x3, 0x2, 0x0, 0x1, 0xB, 0xA, 0x8, 0x9, 0xC, 0xD, 0xF, 0xE }
|
||||||
|
perm [6]= { 0x5, 0x4, 0x6, 0x7, 0x2, 0x3, 0x1, 0x0, 0xA, 0xB, 0x9, 0x8, 0xD, 0xC, 0xE, 0xF }
|
||||||
|
perm [7]= { 0x6, 0x7, 0x5, 0x4, 0x1, 0x0, 0x2, 0x3, 0x9, 0x8, 0xA, 0xB, 0xE, 0xF, 0xD, 0xC }
|
||||||
|
perm [8]= { 0x7, 0x6, 0x4, 0x5, 0x0, 0x1, 0x3, 0x2, 0x8, 0x9, 0xB, 0xA, 0xF, 0xE, 0xC, 0xD }
|
||||||
|
perm [9]= { 0x8, 0x9, 0xB, 0xA, 0xF, 0xE, 0xC, 0xD, 0x7, 0x6, 0x4, 0x5, 0x0, 0x1, 0x3, 0x2 }
|
||||||
|
perm [10]= { 0x9, 0x8, 0xA, 0xB, 0xE, 0xF, 0xD, 0xC, 0x6, 0x7, 0x5, 0x4, 0x1, 0x0, 0x2, 0x3 }
|
||||||
|
perm [11]= { 0xA, 0xB, 0x9, 0x8, 0xD, 0xC, 0xE, 0xF, 0x5, 0x4, 0x6, 0x7, 0x2, 0x3, 0x1, 0x0 }
|
||||||
|
perm [12]= { 0xB, 0xA, 0x8, 0x9, 0xC, 0xD, 0xF, 0xE, 0x4, 0x5, 0x7, 0x6, 0x3, 0x2, 0x0, 0x1 }
|
||||||
|
perm [13]= { 0xC, 0xD, 0xF, 0xE, 0xB, 0xA, 0x8, 0x9, 0x3, 0x2, 0x0, 0x1, 0x4, 0x5, 0x7, 0x6 }
|
||||||
|
perm [14]= { 0xD, 0xC, 0xE, 0xF, 0xA, 0xB, 0x9, 0x8, 0x2, 0x3, 0x1, 0x0, 0x5, 0x4, 0x6, 0x7 }
|
||||||
|
perm [15]= { 0xE, 0xF, 0xD, 0xC, 0x9, 0x8, 0xA, 0xB, 0x1, 0x0, 0x2, 0x3, 0x6, 0x7, 0x5, 0x4 }
|
||||||
|
perm [16]= { 0xF, 0xE, 0xC, 0xD, 0x8, 0x9, 0xB, 0xA, 0x0, 0x1, 0x3, 0x2, 0x7, 0x6, 0x4, 0x5 }
|
||||||
|
|
||||||
|
local shifts = {}
|
||||||
|
shifts[1]= { 0x4, 0x5, 0x7, 0x6, 0x3, 0x2, 0x0, 0x1, 0xB, 0xA, 0x8, 0x9, 0xC, 0xD, 0xF, 0xE }
|
||||||
|
shifts[2]= { 0x4, 0xB, 0xB, 0x4, 0xB, 0x4, 0x4, 0xB, 0xA, 0x5, 0x5, 0xA, 0x5, 0xA, 0xA, 0x5 }
|
||||||
|
shifts[3]= { 0xB, 0x6, 0x0, 0xD, 0xD, 0x0, 0x6, 0xB, 0x6, 0xB, 0xD, 0x0, 0x0, 0xD, 0xB, 0x6 }
|
||||||
|
shifts[4]= { 0xE, 0x5, 0x9, 0x2, 0x0, 0xB, 0x7, 0xC, 0x3, 0x8, 0x4, 0xF, 0xD, 0x6, 0xA, 0x1 }
|
||||||
|
shifts[5]= { 0x4, 0xE, 0x1, 0xB, 0xF, 0x5, 0xA, 0x0, 0x3, 0x9, 0x6, 0xC, 0x8, 0x2, 0xD, 0x7 }
|
||||||
|
shifts[6]= { 0xA, 0x4, 0x7, 0x9, 0x0, 0xE, 0xD, 0x3, 0xE, 0x0, 0x3, 0xD, 0x4, 0xA, 0x9, 0x7 }
|
||||||
|
shifts[7]= { 0xE, 0x6, 0xE, 0x6, 0xF, 0x7, 0xF, 0x7, 0xD, 0x5, 0xD, 0x5, 0xC, 0x4, 0xC, 0x4 }
|
||||||
|
shifts[8]= { 0x7, 0x1, 0xB, 0xD, 0xE, 0x8, 0x2, 0x4, 0x4, 0x2, 0x8, 0xE, 0xD, 0xB, 0x1, 0x7 }
|
||||||
|
shifts[9]= { 0xD, 0xB, 0x0, 0x6, 0x6, 0x0, 0xB, 0xD, 0xA, 0xC, 0x7, 0x1, 0x1, 0x7, 0xC, 0xA }
|
||||||
|
shifts[10]= { 0xe, 0x1, 0x1, 0xe, 0x1, 0xe, 0xe, 0x1, 0x1, 0xe, 0xe, 0x1, 0xe, 0x1, 0x1, 0xe }
|
||||||
|
|
||||||
|
local function ApplyPermutationAndShifts( pos, value, nibble)
|
||||||
|
local shiftbytes = shifts[pos]
|
||||||
|
local shiftElem = shiftbytes[nibble+1] --one indexed
|
||||||
|
local shiftOne = shiftbytes[1]
|
||||||
|
local rs = bit32.bxor(value, bit32.bxor(shiftOne, shiftElem))
|
||||||
|
return rs
|
||||||
|
end
|
||||||
|
|
||||||
|
local function GetOne( uid, block )
|
||||||
|
|
||||||
|
if uid == nil then return nil, 'empty uid string' end
|
||||||
|
if #uid == 0 then return nil, 'empty uid string' end
|
||||||
|
if #uid ~= 8 then return nil, 'uid wrong length. Should be 4 hex bytes' end
|
||||||
|
if type(block) ~= 'number' then return nil, 'block is not number' end
|
||||||
|
if block > 16 or block < 0 then return nil, 'block is out-of-range' end
|
||||||
|
|
||||||
|
local s = ('%s%02X'):format(uid,block)
|
||||||
|
local nibble1 = tonumber(s:sub(1,1),16) + 1
|
||||||
|
|
||||||
|
local permuted = ''
|
||||||
|
for i = 1, #s do
|
||||||
|
local el_row = shifts[i]
|
||||||
|
local el_value = el_row[nibble1]
|
||||||
|
j = 1
|
||||||
|
while j <= i do
|
||||||
|
if i-j > 0 then
|
||||||
|
local nibble = tonumber(s:sub(j+1,j+1),16)
|
||||||
|
el_value = ApplyPermutationAndShifts(i-j, el_value, nibble)
|
||||||
|
end
|
||||||
|
j = j+1
|
||||||
|
end
|
||||||
|
permuted =('%s%X'):format(permuted,el_value)
|
||||||
|
end
|
||||||
|
|
||||||
|
permuted = 'C2'..permuted
|
||||||
|
local crc64numStr = utils.Crc64(permuted)
|
||||||
|
local keybytes = utils.ConvertAsciiToBytes(crc64numStr, true)
|
||||||
|
local key = utils.ConvertBytesToHex(keybytes)
|
||||||
|
return key:sub(1,12)
|
||||||
|
end
|
||||||
|
|
||||||
|
local PreCalc =
|
||||||
|
{
|
||||||
|
GetAll = function(id)
|
||||||
|
if id == nil then return nil, 'empty string' end
|
||||||
|
if #id == 0 then return nil, 'empty string' end
|
||||||
|
if #id ~= 8 then return nil, 'wrong length. Should be 4 hex bytes' end
|
||||||
|
|
||||||
|
local list = '4b0b20107ccb'
|
||||||
|
for i = 1,15 do
|
||||||
|
local key, err = GetOne(id,i)
|
||||||
|
if not key then return oops(err) end
|
||||||
|
list = list..key
|
||||||
|
end
|
||||||
|
return list
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
return PreCalc
|
|
@ -20,7 +20,9 @@ local ISO14A_COMMAND = {
|
||||||
ISO14A_RAW = 8,
|
ISO14A_RAW = 8,
|
||||||
ISO14A_REQUEST_TRIGGER = 0x10,
|
ISO14A_REQUEST_TRIGGER = 0x10,
|
||||||
ISO14A_APPEND_CRC = 0x20,
|
ISO14A_APPEND_CRC = 0x20,
|
||||||
ISO14A_SET_TIMEOUT = 0x40
|
ISO14A_SET_TIMEOUT = 0x40,
|
||||||
|
ISO14A_NO_SELECT = 0x80,
|
||||||
|
ISO14A_TOPAZMODE = 0x100
|
||||||
}
|
}
|
||||||
|
|
||||||
local ISO14443a_TYPES = {}
|
local ISO14443a_TYPES = {}
|
||||||
|
|
|
@ -71,8 +71,8 @@ local Utils =
|
||||||
return outResults
|
return outResults
|
||||||
end,
|
end,
|
||||||
|
|
||||||
------------ CRC-16 ccitt checksums
|
|
||||||
|
|
||||||
|
------------ CRC-16 ccitt checksums
|
||||||
-- Takes a hex string and calculates a crc16
|
-- Takes a hex string and calculates a crc16
|
||||||
Crc16 = function(s)
|
Crc16 = function(s)
|
||||||
if s == nil then return nil end
|
if s == nil then return nil end
|
||||||
|
@ -85,7 +85,22 @@ local Utils =
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
------------ CRC-64 ecma checksums
|
||||||
|
-- Takes a hex string and calculates a crc64 ecma
|
||||||
|
Crc64 = function(s)
|
||||||
|
if s == nil then return nil end
|
||||||
|
if #s == 0 then return nil end
|
||||||
|
if type(s) == 'string' then
|
||||||
|
local utils = require('utils')
|
||||||
|
local asc = utils.ConvertHexToAscii(s)
|
||||||
|
local hash = core.crc64(asc)
|
||||||
|
return hash
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end,
|
||||||
|
|
||||||
|
|
||||||
-- input parameter is a string
|
-- input parameter is a string
|
||||||
-- Swaps the endianess and returns a number,
|
-- Swaps the endianess and returns a number,
|
||||||
-- IE: 'cd7a' -> '7acd' -> 0x7acd
|
-- IE: 'cd7a' -> '7acd' -> 0x7acd
|
||||||
|
@ -135,7 +150,7 @@ local Utils =
|
||||||
while IN>0 do
|
while IN>0 do
|
||||||
I=I+1
|
I=I+1
|
||||||
IN , D = math.floor(IN/B), math.modf(IN,B)+1
|
IN , D = math.floor(IN/B), math.modf(IN,B)+1
|
||||||
OUT=string.sub(K,D,D)..OUT
|
OUT = string.sub(K,D,D)..OUT
|
||||||
end
|
end
|
||||||
return OUT
|
return OUT
|
||||||
end,
|
end,
|
||||||
|
@ -147,7 +162,7 @@ local Utils =
|
||||||
end
|
end
|
||||||
local s={}
|
local s={}
|
||||||
for i = 1, #(bytes) do
|
for i = 1, #(bytes) do
|
||||||
s[i] = string.format("%02X",bytes[i])
|
s[i] = string.format("%02X",bytes[i])
|
||||||
end
|
end
|
||||||
return table.concat(s)
|
return table.concat(s)
|
||||||
end,
|
end,
|
||||||
|
@ -171,16 +186,28 @@ local Utils =
|
||||||
end
|
end
|
||||||
return t
|
return t
|
||||||
end,
|
end,
|
||||||
ConvertAsciiToBytes = function(s)
|
ConvertAsciiToBytes = function(s, reverse)
|
||||||
local t={}
|
local t = {}
|
||||||
if s == nil then return t end
|
if s == nil then return t end
|
||||||
if #s == 0 then return t end
|
if #s == 0 then return t end
|
||||||
|
|
||||||
for k in s:gmatch"(.)" do
|
for k in s:gmatch"(.)" do
|
||||||
table.insert(t, string.byte(k))
|
table.insert(t, string.byte(k))
|
||||||
end
|
end
|
||||||
return t
|
|
||||||
|
if not reverse then
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local rev = {}
|
||||||
|
if reverse then
|
||||||
|
for i = #t, 1,-1 do
|
||||||
|
table.insert(rev, t[i] )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return rev
|
||||||
end,
|
end,
|
||||||
|
|
||||||
ConvertHexToAscii = function(s)
|
ConvertHexToAscii = function(s)
|
||||||
local t={}
|
local t={}
|
||||||
if s == nil then return t end
|
if s == nil then return t end
|
||||||
|
@ -191,6 +218,30 @@ local Utils =
|
||||||
return table.concat(t)
|
return table.concat(t)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
Chars2num = function(s)
|
||||||
|
return (s:byte(1)*16777216)+(s:byte(2)*65536)+(s:byte(3)*256)+(s:byte(4))
|
||||||
|
end,
|
||||||
|
|
||||||
|
-- use length of string to determine 8,16,32,64 bits
|
||||||
|
bytes_to_int = function(str,endian,signed)
|
||||||
|
local t={str:byte(1,-1)}
|
||||||
|
if endian=="big" then --reverse bytes
|
||||||
|
local tt={}
|
||||||
|
for k=1,#t do
|
||||||
|
tt[#t-k+1]=t[k]
|
||||||
|
end
|
||||||
|
t=tt
|
||||||
|
end
|
||||||
|
local n=0
|
||||||
|
for k=1,#t do
|
||||||
|
n=n+t[k]*2^((k-1)*8)
|
||||||
|
end
|
||||||
|
if signed then
|
||||||
|
n = (n > 2^(#t*8-1) -1) and (n - 2^(#t*8)) or n -- if last bit set, negative.
|
||||||
|
end
|
||||||
|
return n
|
||||||
|
end,
|
||||||
|
|
||||||
-- function convertStringToBytes(str)
|
-- function convertStringToBytes(str)
|
||||||
-- local bytes = {}
|
-- local bytes = {}
|
||||||
-- local strLength = string.len(str)
|
-- local strLength = string.len(str)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue