msg
=
"cr"
.. cry.encrypt(key, msg,
16
,
1
)
function encrypt(n, s, h, r, d)
assert
(n ~
=
nil,
"Empty password."
)
assert
(n ~
=
nil,
"Empty data."
)
local r
=
r
or
CBCMODE
local h
=
h
or
AES128
local l
=
{
string.byte(n,
1
,
}
local u
=
util.padByteString(s)
if
r
=
=
ECBMODE then
return
ciphermode.encryptString(l, u, ciphermode.encryptECB, d)
elseif r
=
=
CBCMODE then
return
ciphermode.encryptString(l, u, ciphermode.encryptCBC, d)
elseif r
=
=
OFBMODE then
return
ciphermode.encryptString(l, u, ciphermode.encryptOFB, d)
elseif r
=
=
CFBMODE then
return
ciphermode.encryptString(l, u, ciphermode.encryptCFB, d)
elseif r
=
=
CTRMODE then
return
ciphermode.encryptString(l, u, ciphermode.encryptCTR, d)
else
error(
"Unknown mode"
,
2
)
end
end
AES128
=
16
AES192
=
24
AES256
=
32
ECBMODE
=
1
CBCMODE
=
2
OFBMODE
=
3
CFBMODE
=
4
CTRMODE
=
4
aes
=
e(function (n, ...)
local s
=
util.putByte
local h
=
util.getByte
local r
=
"rounds"
local d
=
"type"
...