36 posts
Location
USA, east coast
Posted 12 June 2014 - 11:13 PM
I'm currently developing an encryption system over rednet, but I've hit a snag on disks. The code all works fine for the program, but it has to transmit the encryption key first, and even though I've gotten it to 6 digits without crashes on my weak laptop that I use, anyone with brains could see what I was doing and decrypt it. so here's what I need help with, how do I save a string to a disk? it should be simple but I can't figure out how without labeling the floppy disk my key, but if that's the way then that's the way. The program will probably get sent to the programs page when it's done, but that's a bit away.
Edited on 12 June 2014 - 09:15 PM
7083 posts
Location
Tasmania (AU)
Posted 13 June 2014 - 12:00 AM
Quite frankly, labeling the floppy according to your key probably IS the most efficient way to code it…
But let's say you wanted to write the key into a file on the disk. You'd use
fs.open() to get a file handle, then write to that:
local myFile = fs.open("disk/keyFile","w")
myFile.writeLine(myKey)
myFile.close()
And then to read it back later:
local myFile = fs.open("disk/keyFile","r")
local myKey = myFile.readLine()
myFile.close()
40 posts
Posted 13 June 2014 - 12:04 AM
I have hard to decrypt your request! - But i go for this part:
..
how do I save a string to a disk? This code makes a file called. "SavedFile" containing the text: "The string to save"local filename="SavedFile"
local text="The string to save"
local f=fs.open(filename,"w")
f.write()
f.close()
Maybe you want to read about FS here: http://www.computerc...fo/wiki/Fs_(API)Hope this helps/sEiEDIT: Arghhhh i got Ninja'ed ;)/>
Edited on 12 June 2014 - 10:05 PM
36 posts
Location
USA, east coast
Posted 13 June 2014 - 12:53 AM
sorry for the late response, but l appreciate the answers. Sadly sEi, maybe your "ninja'ed" edit may show this, but I'll have to try the bloke who commented first, and then maybe if that isn't what I'm looking for then your solution will be used.
36 posts
Location
USA, east coast
Posted 13 June 2014 - 01:19 AM
only problem: second line when reading the file, I get an attempt to call nil, which usually means that I got a parameter wrong, but it should be fine since even gion to that path I find a file called keyFile, and in it I find the test key of hey. however, I can't pull "hey" to a variable in the lua console. Even the wiki says it should work
Edit: Even sEi's doesn't work when it gets to f.write(), and I tried f.write("hello")
Edited on 12 June 2014 - 11:22 PM
7083 posts
Location
Tasmania (AU)
Posted 13 June 2014 - 02:39 AM
It means it can't create the file handle. If the file exists, then that probably means the file is already open - perhaps you forgot to close it when you wrote to it? Rebooting the computer will likely resolve that.
36 posts
Location
USA, east coast
Posted 13 June 2014 - 02:45 AM
I'll try it. btw, found out the max encryption length ended up as 127 digits, so fun times making a max length!
well that didn't work. now even writing doesn't work. I'll just stick with the label as the key even though the max is 25 characters
Edited on 13 June 2014 - 12:47 AM