worked on file io

This commit is contained in:
sa 2022-04-02 17:49:37 -04:00
parent 8eb8a65d1c
commit 3e8b21fb6d

View File

@ -42,20 +42,48 @@ once the table reaches 512kb, encrypt it, and put it
into tmp files. once all of the data has been encrypted into tmp files. once all of the data has been encrypted
stitch together all the tmp files stitch together all the tmp files
local bytes = {} load the file into two arrays as words into bytesA and bytesB
file = assert(io.open(arg[1], "rb")) where bytesA & B alternate between bytes (odd and even)
block = 1 --blocks of 1 byte
encrypt
merge arrays load into encrypted array
write to output file
local bytesA = {}
local bytesB = {}
input = assert(io.open(arg[1], "rb"))
output = assert(io.open(arg[2], "wb"))
io.output(arg[2])
local block = 1 --blocks of 1 byte
while true do while true do
local byte = file:read(block) local byte = input:read(block)
if byte == nil then if byte == nil then
break break
else else
bytes[#bytes+1] = string.byte(byte) --break word 1 into bytes
--load the bytes into an array
bytesA[#bytesA+1] = string.byte(byte)
end end
while true do
local byte = input:read(block)
if byte == nil then
break
else
--break word 2 into bytes
--load the bytes into an array
--bytesB[#bytesB+1] = string.byte(byte)
end
merge arrays bytesA and bytesB
end end
file:close() input:close()
output:close()
]] ]]
local S = {} local S = {}
S[0] = P --initialize the S array S[0] = P --initialize the S array
for i = 1, t do for i = 1, t do