From cec7feb2f889c5b23bc242ee0adb9a7880e5e5c3 Mon Sep 17 00:00:00 2001 From: sa Date: Fri, 30 Dec 2022 02:05:56 -0500 Subject: [PATCH] moved fileio stuff to new file --- src/encrypt.lua | 50 ------------------------------------------- src/fileIOtesting.lua | 48 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 50 deletions(-) create mode 100644 src/fileIOtesting.lua diff --git a/src/encrypt.lua b/src/encrypt.lua index 41f48b6..050fd7c 100644 --- a/src/encrypt.lua +++ b/src/encrypt.lua @@ -34,56 +34,6 @@ L = K local P = 0xb7e151628aed2a6b local Q = 0x9e3779b97f4a7c15 ---[[ -main loop -read in file in 1 block bytes -this will work for files under 1MB for larger files -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 - -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 = input:read(block) - if byte == nil then - break - else - --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 -input:close() -output:close() -]] - - local S = {} S[0] = P --initialize the S array for i = 1, t do diff --git a/src/fileIOtesting.lua b/src/fileIOtesting.lua new file mode 100644 index 0000000..435c9c8 --- /dev/null +++ b/src/fileIOtesting.lua @@ -0,0 +1,48 @@ +--[[ +main loop +read in file in 1 block bytes +this will work for files under 1MB for larger files +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 + +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 = input:read(block) + if byte == nil then + break + else + --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 +input:close() +output:close() +]]