From 3e8b21fb6d4542bbe64ef2faf8746a167136f2fb Mon Sep 17 00:00:00 2001 From: sa Date: Sat, 2 Apr 2022 17:49:37 -0400 Subject: [PATCH] worked on file io --- src/encrypt.lua | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/encrypt.lua b/src/encrypt.lua index fa000ea..41f48b6 100644 --- a/src/encrypt.lua +++ b/src/encrypt.lua @@ -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 stitch together all the tmp files -local bytes = {} -file = assert(io.open(arg[1], "rb")) -block = 1 --blocks of 1 byte +load the file into two arrays as words into bytesA and bytesB +where bytesA & B alternate between bytes (odd and even) + +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 - local byte = file:read(block) + local byte = input:read(block) if byte == nil then break 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 + +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 -file:close() +input:close() +output:close() ]] + local S = {} S[0] = P --initialize the S array for i = 1, t do