The question is: why would you even want to do this in Lua? Lua is not designed to do any heavy lifting. You should do this in C or Java instead.
Because, for better or for worse, Lua is what we have. It takes a lot less skill and effort to write something in Lua than it does to write a Minecraft mod to plug into CC (even getting MCP set up is more effort than just pulling up a Lua interpreter in CC). And if you play on a server that you don’t run, or if you do run it but you want to seem fair to everyone else by not just installing all your own stuff, you simply
can’t use anything but Lua.
And if you were to do it in Lua, you can do fh:read(1024) for 1024 bytes. I don't know if this works in CC, though.
This doesn’t work in CC. Whether you’re using a file handle from the “io” API or from the “fs” API, in binary mode, the “read” function takes zero parameters and returns one byte.
On top of that, do you really need this grade of privacy in Minecraft? In my opinion, It'd be more fun to create my own encryption, rather than translate some other encryption into Lua.
Personally, I think encryption is mostly pointless in CC altogether. If you play on a server where people destroy each other’s blocks, they could just go into your base, destroy any maximum-priority floppy drive you might have, and install their own code to sniff your password if they want to recover your encrypted data. If you play on a server where destroying each other’s stuff is forbidden, you don’t need encryption: just keep the data on a computer behind a locked door (if you need access to it at a public place via a password, use access control instead of encryption by having the public computer send the password to the secured one which checks it before returning the data).
That’s beside the point though. There are lots of applications for binary files other than encryption (and for that matter, encryption need not be used only on files). Maybe you want binary because you’re dealing with large volumes of data (unlikely in CC, but you never know). Maybe you want binary because you want to build an image decompresser that can display a PNG file on a monitor in ASCII art, or on a giant grid of Lumar lamps, or something. Maybe you want to implement a cryptographic hash function, like MD5, which you’ll use to verify the integrity of some files during a software auto-update protocol (I think I’m probably going to be doing this at some point), not because you’re worried about security but just because you want to make sure there wasn’t accidental corruption. There’s no reason we shouldn’t hope for a better way of manipulating binary data.