Wed, 16 Feb 2011 20:29:33 +0000
There are no secrets better kept than the secrets that everybody guesses.
0
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | local bit = require("bit"); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | local public = {}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | local private = {}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | local aeslua = require("aeslua"); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | aeslua.util = public; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | -- calculate the parity of one byte |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | function public.byteParity(byte) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | byte = bit.bxor(byte, bit.rshift(byte, 4)); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | byte = bit.bxor(byte, bit.rshift(byte, 2)); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | byte = bit.bxor(byte, bit.rshift(byte, 1)); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | return bit.band(byte, 1); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | -- get byte at position index |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | function public.getByte(number, index) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | if (index == 0) then |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | return bit.band(number,0xff); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | else |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | return bit.band(bit.rshift(number, index*8),0xff); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | -- put number into int at position index |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | function public.putByte(number, index) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | if (index == 0) then |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | return bit.band(number,0xff); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | else |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | return bit.lshift(bit.band(number,0xff),index*8); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | -- convert byte array to int array |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | function public.bytesToInts(bytes, start, n) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | local ints = {}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 | for i = 0, n - 1 do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 | ints[i] = public.putByte(bytes[start + (i*4) ], 3) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 | + public.putByte(bytes[start + (i*4) + 1], 2) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 | + public.putByte(bytes[start + (i*4) + 2], 1) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 | + public.putByte(bytes[start + (i*4) + 3], 0); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 | return ints; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 | -- convert int array to byte array |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 | function public.intsToBytes(ints, output, outputOffset, n) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 | n = n or #ints; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 | for i = 0, n do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 | for j = 0,3 do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 | output[outputOffset + i*4 + (3 - j)] = public.getByte(ints[i], j); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 | return output; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 | -- convert bytes to hexString |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 | function private.bytesToHex(bytes) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 | local hexBytes = ""; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 | for i,byte in ipairs(bytes) do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 | hexBytes = hexBytes .. string.format("%02x ", byte); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 | return hexBytes; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 | -- convert data to hex string |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 | function public.toHexString(data) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 | local type = type(data); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 | if (type == "number") then |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 | return string.format("%08x",data); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 | elseif (type == "table") then |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 | return private.bytesToHex(data); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 | elseif (type == "string") then |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 | local bytes = {string.byte(data, 1, #data)}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 | return private.bytesToHex(bytes); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 | else |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 | return data; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 | function public.padByteString(data) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 | local dataLength = #data; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 | local random1 = math.random(0,255); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 | local random2 = math.random(0,255); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 | local prefix = string.char(random1, |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 | random2, |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 | random1, |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 | random2, |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 | public.getByte(dataLength, 3), |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 | public.getByte(dataLength, 2), |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 | public.getByte(dataLength, 1), |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 | public.getByte(dataLength, 0)); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 | data = prefix .. data; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 | local paddingLength = math.ceil(#data/16)*16 - #data; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 | local padding = ""; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 | for i=1,paddingLength do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 | padding = padding .. string.char(math.random(0,255)); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 | return data .. padding; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 | function private.properlyDecrypted(data) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 | local random = {string.byte(data,1,4)}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 | if (random[1] == random[3] and random[2] == random[4]) then |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 | return true; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 | return false; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 | function public.unpadByteString(data) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 | if (not private.properlyDecrypted(data)) then |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 | return nil; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 | local dataLength = public.putByte(string.byte(data,5), 3) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 | + public.putByte(string.byte(data,6), 2) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 | + public.putByte(string.byte(data,7), 1) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 | + public.putByte(string.byte(data,8), 0); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 | return string.sub(data,9,8+dataLength); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 | function public.xorIV(data, iv) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 | for i = 1,16 do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 | data[i] = bit.bxor(data[i], iv[i]); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 | return public; |