moved fileio stuff to new file
This commit is contained in:
parent
3e8b21fb6d
commit
cec7feb2f8
@ -34,56 +34,6 @@ L = K
|
|||||||
local P = 0xb7e151628aed2a6b
|
local P = 0xb7e151628aed2a6b
|
||||||
local Q = 0x9e3779b97f4a7c15
|
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 = {}
|
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
|
||||||
|
48
src/fileIOtesting.lua
Normal file
48
src/fileIOtesting.lua
Normal file
@ -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()
|
||||||
|
]]
|
Loading…
x
Reference in New Issue
Block a user