Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- if #tArgs < 2 then
- print("Usage: "..shell.getRunningProgram().." [infile] <outfile> [key]")
- return
- end
- local infile, outfile, key
- if #tArgs == 2 then
- infile, key = unpack(tArgs)
- outfile = infile
- else
- infile, outfile, key = unpack(tArgs)
- end
- function convert(str, key)
- local res = ""
- for i = 1,#str do
- local keyIndex = (i - 1) % key:len() + 1
- res = res .. string.char( bit.bxor( str:sub(i,i):byte(), key:sub(keyIndex,keyIndex):byte() ) )
- end
- return res
- end
- local h = fs.open(infile, 'rb')
- if h == nil then
- error("No such file!")
- end
- local str = ""
- for c in h.read do
- str = str .. string.char(c)
- end
- h.close()
- local converted = convert(str, key)
- h = fs.open(outfile, 'wb')
- for c in converted:gmatch('.') do
- h.write(c:byte())
- end
- h.close()
Advertisement
Add Comment
Please, Sign In to add comment