local expect = require "cc.expect".expect local bxor = bit32.bxor local rol = bit32.lrotate local mod = {} function mod.crypt(key, nonce, message, rounds, offset) expect(1, key, "string") assert(#key == 32, "key length must be 32") expect(2, nonce, "string") assert(#nonce == 12, "nonce length must be 12") expect(3, message, "string") expect(4, rounds, "number", "nil") rounds = rounds or 20 assert(rounds % 2 == 0, "round number must be even") assert(rounds >= 8 and rounds <= 20, "round number must be in 8..20") expect(5, offset, "number", "nil") offset = offset or 1 assert(offset % 1 == 0 and offset >= 0, "offset must be an integer >= 0") assert(#message + 64 * offset < 2 ^ 37, "offset too large") -- Build the state block. local i0, i1, i2, i3 = 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 local k0, k1, k2, k3, k4, k5, k6, k7 = ("