Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tArgs = { ... }
- function printUsage()
- print("Usage: " ..shell.getRunningProgram().. " <encrypt/decrypt> [filename] [password]")
- end
- if #tArgs < 1 then
- printUsage()
- return
- end
- function encrypt( str, password )
- local mainString = ""
- local passwordLocation = 1
- for i=1,#str do
- local str1 = string.byte( string.sub(str, i, i) ) + string.byte( string.sub(password, passwordLocation, passwordLocation) )
- if passwordLocation == #password then
- passwordLocation = 1
- else
- passwordLocation = passwordLocation +1
- end
- if i == 1 then
- mainString = str1
- else
- mainString = mainString .. "/" ..str1
- end
- end
- return mainString
- end
- function decrypt( str, password )
- tWords = {}
- for match in string.gmatch(str, "[^/\t]+") do
- table.insert( tWords, match )
- end
- local dahString = ""
- local passwordLocation = 1
- for i=1,#tWords do
- local anodahwunbitezdahdust = tonumber(tWords[i]) - string.byte( string.sub(password, passwordLocation, passwordLocation) )
- dahString = dahString .. string.char( anodahwunbitezdahdust )
- passwordLocation = passwordLocation +1
- if passwordLocation == #password then
- passwordLocation = 1
- end
- end
- return dahString
- end
- if string.lower(tArgs[1]) == "encrypt" and fs.exists(tArgs[2]) and tArgs[3] then
- file = fs.open(tArgs[2], "r")
- local endResult = {}
- local characters = 0
- line = file.readLine()
- while line do
- characters = characters + #line
- table.insert(endResult, encrypt(line, tArgs[3]))
- line = file.readLine()
- end
- local resultName = characters + math.random(1,10)
- results = fs.open("result_" ..resultName, "w")
- for i=1,#endResult do
- results.write(endResult[i])
- end
- results.close()
- print("Encrypted " ..characters.. " characters. ")
- print("Password: " ..tArgs[3])
- print("Result file: result_" ..resultName)
- elseif string.lower(tArgs[1]) == "decrypt" and fs.exists(tArgs[2]) and tArgs[3] then
- local resultNum = math.random(1,999)
- file = fs.open("result_" ..resultNum, "w")
- fileRead = fs.open( tArgs[2], "r")
- line = fileRead.readLine()
- local endResult = decrypt( line, tArgs[3] );
- file.write(endResult)
- fileRead.close()
- file.close()
- print("Decrypted. Saved as: ")
- print("result_" ..resultNum)
- else
- printUsage()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement