]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/lualibs/utils.lua
FIX: maybe I should actually send the uid bytes with the command request....
[proxmark3-svn] / client / lualibs / utils.lua
1 --[[
2 This may be moved to a separate library at some point (Holiman)
3 --]]
4 local Utils =
5 {
6 -- Asks the user for Yes or No
7 confirm = function(message, ...)
8 local answer
9 message = message .. " [y/n] ?"
10 repeat
11 io.write(message)
12 io.flush()
13 answer=io.read()
14 if answer == 'Y' or answer == "y" then
15 return true
16 elseif answer == 'N' or answer == 'n' then
17 return false
18 end
19 until false
20 end,
21 ---
22 -- Asks the user for input
23 input = function (message , default)
24 local answer
25 if default ~= nil then
26 message = message .. " (default: ".. default.. " )"
27 end
28 message = message .." \n > "
29 io.write(message)
30 io.flush()
31 answer=io.read()
32 if answer == '' then answer = default end
33
34 return answer
35 end,
36 --
37 -- Converts DECIMAL to HEX
38 ConvertDec2Hex = function(IN)
39 local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
40 while IN>0 do
41 I=I+1
42 IN,D=math.floor(IN/B),math.mod(IN,B)+1
43 OUT=string.sub(K,D,D)..OUT
44 end
45 return OUT
46 end,
47 ---
48 -- Convert Byte array to string of hex
49 ConvertBytes2String = function(bytes)
50 s = {}
51 for i = 1, #(bytes) do
52 s[i] = string.format("%02X",bytes[i])
53 end
54 return table.concat(s)
55 end,
56 }
57 return Utils
Impressum, Datenschutz