👨💻 about me home CV/Resume 🖊️ Contact Github LinkedIn I’m a Haskeller 📝 Blog Freedom, privacy, tutorials… 🏆 Best of Fizzbuzz LuaX Calculadoira panda upp Haskell todo pwd TPG Nextcloud Git

🆕
**since August 2022**: LuaX is a Lua
eXtended interpretor/cross compiler providing a bunch of useful modules
(statically linked, no dependency). Nice integration with upp (new functions and modules available to extend upp
macros) and also with a soon released but yet confidential project about
actor oriented programming!

💣
*Kick GAFAMs out*
(✔️ ~~ǝlƃooפ~~, ✔️ ~~ʞooqǝɔɐℲ~~, ✔️ ~~uozɐɯ∀~~): Stop giving
our soul and money to evils, be free and respectful!

🆕
**since December 2020**: Playing with the actor model in an
embedded multicore context. C imperative components become C stream pure
functions with no side effect ➡️ C low level programming with high
level pure functional programming properties 🏆

📰 **Saturday 30. January
2021**: Playing with Pandoc Lua filters in
Lua. panda is a lightweight
alternative to abp providing a
consistent set of Pandoc filters (text substitution, file inclusion,
diagrams, scripts, …).

🆕
**Sunday 24. May 2020**: Working at EasyMile for more than 5 years. Critical
real-time software in C, simulation and monitoring in Haskell ➡️ perfect combo! It’s
efficient and funny ;-)

`local crypt = require "crypt"`

`crypt`

provides cryptography functions.

The LuaX pseudorandom number generator is a linear congruential generator. This generator is not a cryptographically secure pseudorandom number generator. It can be used as a repeatable generator (e.g. for repeatable tests).

LuaX has a global generator (with a global seed) and can instantiate independant generators with their own seeds.

`local rng = crypt.prng(seed)`

returns a random number generator starting from the optional seed
`seed`

. This object has four methods:
`srand(seed)`

, `rand([m, [n]])`

,
`rands([bytes])`

and `randf([a, [b]])`

.

`:srand([seed]) rng`

sets the seed of the PRNG. The default seed is a number based on the current time and the process id.

`:rand() rng`

returns a random integral number between `0`

and
`crypt.RAND_MAX`

.

`:rand(m) rng`

returns a random integral number between `1`

and
`m`

.

`:rand(m, n) rng`

returns a random integral number between `m`

and
`n`

.

`:randf() rng`

returns a random floating point number between `0.0`

and
`1.0`

.

`:randf(a) rng`

returns a random floating point number between `0.0`

and
`a`

.

`:randf(a, b) rng`

returns a random floating point number between `a`

and
`b`

.

`:rands(bytes) rng`

returns a string with `bytes`

random bytes.

`.srand([seed]) crypt`

sets the seed of the global PRNG. The default seed is a number based on the current time and the process id.

`.rand() crypt`

returns a random integral number between `0`

and
`crypt.RAND_MAX`

.

`.rand(m) crypt`

returns a random integral number between `1`

and
`m`

.

`.rand(m, n) crypt`

returns a random integral number between `m`

and
`n`

.

`.randf() crypt`

returns a random floating point number between `0.0`

and
`1.0`

.

`.randf(a) crypt`

returns a random floating point number between `0.0`

and
`a`

.

`.randf(a, b) crypt`

returns a random floating point number between `a`

and
`b`

.

`.rands(bytes) crypt`

returns a string with `bytes`

random bytes.

The hexadecimal encoder transforms a string into a string where bytes are coded with hexadecimal digits.

`.hex(data) crypt`

encodes `data`

in hexa.

`.unhex(data) crypt`

decodes the hexa `data`

.

The base64 encoder transforms a string with non printable characters into a printable string (see https://en.wikipedia.org/wiki/Base64)

`.base64(data) crypt`

encodes `data`

in base64.

`.unbase64(data) crypt`

decodes the base64 `data`

.

`.base64url(data) crypt`

encodes `data`

in base64url.

`.unbase64url(data) crypt`

decodes the base64url `data`

.

The CRC-32 algorithm has been generated by pycrc with the `crc-32`

algorithm.

`.crc32(data) crypt`

computes the CRC32 of `data`

.

The CRC-64 algorithm has been generated by pycrc with the `crc-64-xz`

algorithm.

`.crc64(data) crypt`

computes the CRC64 of `data`

.

RC4 is a stream cipher (see https://en.wikipedia.org/wiki/RC4). It is design to be fast and simple.

```
.rc4(data, key, [drop])
crypt.unrc4(data, key, [drop]) -- note that unrc4 == rc4 crypt
```

encrypts/decrypts `data`

using the RC4Drop algorithm and
the encryption key `key`

(drops the first `drop`

encryption steps, the default value of `drop`

is 768).

The `crypt`

contains functions from TinyCrypt.

`.sha256(data) crypt`

returns the SHA256 digest of `data`

.

`.hmac(data, key) crypt`

returns the HMAC-SHA256 digest of `data`

using
`key`

as a key.

`.hmac_prng(personalization) crypt`

returns a HMAC PRNG initialized with `personalization`

(32
bytes or more) and some OS dependant entropy. This object has three
methods: `srand(seed)`

, `rand([bytes])`

and
`frand()`

.

`.ctr_prng(personalization) crypt`

returns a CTR PRNG initialized with `personalization`

(32
bytes of more) and some OS dependant entropy. This object has three
methods: `srand(seed)`

, `rand([bytes])`

and
`frand()`

.

`.aes(data, key) crypt`

encrypts `data`

using the AES-128-CBC algorithm and the
encryption key `key`

.

`.unaes(data, key) crypt`

decrypts `data`

using the AES-128-CBC algorithm and the
encryption key `key`

.

Some functions of the `crypt`

package are added to the
string module:

```
:hex() == crypt.hex(s)
s:unhex() == crypt.unhex(s)
s:base64() == crypt.base64(s)
s:unbase64() == crypt.unbase64(s)
s:base64url() == crypt.base64url(s)
s:unbase64url() == crypt.unbase64url(s)
s:crc32() == crypt.crc32(s)
s:crc64() == crypt.crc64(s)
s:rc4(key, drop) == crypt.rc4(s, key, drop)
s:unrc4(key, drop) == crypt.unrc4(s, key, drop)
s:sha256() == crypt.sha256(s)
s:hmac(key) == crypt.hmac(s, key)
s:aes(key) == crypt.aes(s, key)
s:unaes(key) == crypt.unaes(s, key) s
```