Posted 05 January 2013 - 06:10 AM
Hello guys,
i got a problem: The following code is a sting/file encryption and decryption program
But if I want to encrypt a file, it returns a number like [44, 45, 46].
Please help me, i want to make a safer rednet
Thanks for your help! ;)/>
i got a problem: The following code is a sting/file encryption and decryption program
local tArgs = { ... }
local param1 = tonumber(tArgs[1])
local param2 = tArgs[2]
local param3 = tArgs[3]
local content = tArgs[4]
if not param1 or not param2 or not param3 or not content then
print("")
print("Usage: zipper.lua <code> <-enc, -dec> <-f , -s> <filename , string>");
return;
end
function encrypt_string(code, str)
local chars="1234567890!@#$%^&*()qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM,<.>/?;:'[{]}\|`~"
local newstr = ""
for i=1,999 do
if string.sub(str, i, i) == "" then
break;
else
com=string.sub(str,i,i);
end
for j=1,90 do
cur=string.sub(chars,j,j)
if com == cur then
new=j+code;
while new > 90 do
new = new - 90;
end
newstr = ""..newstr..""..string.sub(chars,new,new).."";
end
end
end
return newstr;
end
function encrypt_file(codec, filename22 )
origfile = io.open(filename, "r")
fCont = origfile:read("*a")
origfile:close()
encfstr = encrypt_string(codec, fCont)
encfilename = ""
print("+---------[File Content]---------+")
print(encfstr)
print("+---------[End of file!]---------+")
encfilename = filename..".zip";
encfile = io.open(encfilename, "w")
encfile:write(encfstr);
encfile:close()
return encfstr, encfilename;
end
function decrypt_string(code, str)
local chars="1234567890!@#$%^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ,<.>/?;:'[{]}\|`~";
local newstr = ""
for i=1,999 do
if string.sub(str,i,i) == "" then
break
else
com=string.sub(str,i,i)
end
for x=1, 90 do
cur=string.sub(chars,x,x)
if com == cur then
new=x-code
while new < 0 do
new = new + 90
end
newstr=""..newstr..""..string.sub(chars,new,new)..""
end
end
end
return newstr
end
function decrypt_file(codec, filename)
origfile = io.open(filename, "r")
fContent = origfile:read("*a")
origfile.close()
decstr = decrypt_string(codec, fContent)
decfilename = ""
print("+---------[File Content]---------+")
print(decstr)
print("+---------[End of file!]---------+")
decfilename = filename..".source";
decfile = io.open(decfilename, "w")
decfile:write(decstr)
decfile:close()
return decstr, decfilename
end
if param2 == "-enc" and param3 == "-f" then
encrypt_file(param1, content)
elseif param2 == "-enc" and param3 == "-s" then
fail = encrypt_string(param1, content)
print("Original: "..content.." | Packed: "..fail)
elseif param2 == "-dec" and param3 == "-f" then
decrypt_file(param1, ""..content.."")
elseif param2 == "-dec" and param3 == "-s" then
fail = decrypt_string(param1, content)
print("Packed: "..content.." | Unpacked: "..fail)
else
print("Unkown parameters: "..param2.." "..param3)
end
But if I want to encrypt a file, it returns a number like [44, 45, 46].
Please help me, i want to make a safer rednet
Thanks for your help! ;)/>