This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Spongy141's profile picture

[Lua][Question]I don't know if my program will work

Started by Spongy141, 04 March 2013 - 01:06 PM
Spongy141 #1
Posted 04 March 2013 - 02:06 PM
Since I cant test my program myself, and I have a good feeling it wont work right, can one of you "pros" tell me whats wrong with it? I would test it myself and make it better myself, but I cant seem to get ComputerCraft installed right..
anyways, it basically is a encryption and decryption code….


os.pullEvent == os.pullEventRaw
function top()
  rednet.open("top")
  term.clear()
  term.setCursorPos(1,1)
  term.setTextColor(colors.lightBlue)
  print("SimpleOS")
  term.setTextColor(colors.gray)
  print("========")
  term.setTextColor(colors.white)
  sleep(1)
  term.setTextColor(colors.green)
  print("Password: ")
  local pass = read()
  if pass == ("a22h013S[123]") then
	end top()
  else
  os.reboot()
  end
end

function encrypte()  --This encryptes the msg you want to send.
  msg ==
	"a" == "01"
"b" == "001"
"c" == "0001"
"d" == "0010"
"e" == "0100"
"f" == "1000"
"g" == "1001"
"h" == "1010"
"i" == "1100"
"j" == "1110"
"k" == "1101"
"l" == "0110"
"m" == "1011"
"n" == "0011"
"o" == "0111"
"p" == "0010"
"q" == "1111"
"r" == "10"
"s" == "110"
"t" == "010"
"u" == "100"
"v" == "111"
"w" == "101"
"x" == "000"
"y" == "011"
"z" == "0000"
= Nmsg
end

function send()
  rednet.broadcast(Nmsg)
end

function decrypte() --This decryptes the message your receiveing
  RDmsg ==
	"01"   == "a"
"001"  == "b"
"0001" == "c"
"0010" == "d"
"0100" == "e"
"1000" == "f"
"1001" == "j"
"1010" == "h"
"1100" == "i"
"1110" == "j"
"1101" == "k"
"0110" == "l"
"1011" == "m"
"0011" == "n"
"0111" == "o"
"0010" == "p"
"1111" == "q"
"10"   == "r"
"110"  == "s"
"010"  == "t"
"100"  == "u"
"111"  == "v"
"101"  == "w"
"000"  == "x"
"011"  == "y"
"0000" == "z"
= RNmsg
end

function receive()
  id,DRmsg == rednet.receive
end
top()
while true do
  term.setTextColor(colors.lime)
  print("Message: ")
  term.setTextColor(colors.white)
  local msg = read()
  encrypte(msg)
  send(Nmsg)
  receive(DRmsg)
  decrypte(DRmsg)
  term.setTextColor(colors.purple)
  print(id..":Message: ")
  write(RNmsg)
end
KaoS #2
Posted 04 March 2013 - 02:30 PM
you should generally start by telling us what is "right", what it should do etc
Spongy141 #3
Posted 04 March 2013 - 02:47 PM
you should generally start by telling us what is "right", what it should do etc
lol sorry about that, I thought it would be easy to tell with the comments inside the code itself, but it basically a encrypter and a decrypter.
AnDwHaT5 #4
Posted 04 March 2013 - 04:16 PM
CC is weird for installation. First go to the http://computercraft.info page and go to download. First get minecraft forge. Go to the siteand in the little box above it will say releases. Hit that and download the latest one. make sure it is universal Go back to the list and get computercraft. Open up your .minecraft/bin/minecraft.jar and delete meta.inf. After drag your contents of the minecraft forge into the folder. Then go to your .minecraft and make a folder called mods. After put your computercraft.zip in there and try to launch it. If done right it should work or try deleting meta.inf that comes with the forge. after you can make a new wrold and then go to your .minecraft/saves/computers and create a file called 1. drag the file of your code into it and then go to the game and put down a computer make sure it is the first one. rename the file to what you want because it normally goes myfile.txt. make sure when you put the file in the name has no spaces for it will screw it up. If you have any questions ask me or refer to youtube.
Pharap #5
Posted 04 March 2013 - 04:28 PM
Right off the bat I know this won't work.
The == operator is different from = in that it takes the values on both of it's sides, tests them with a predefined equality testing method and returns true or false based on the result. i.e. (5==5) equates to true, but (5==4) is false.
Also the variables referred to in your functions will either not exist or will clutter up the global table.
SuicidalSTDz #6
Posted 04 March 2013 - 05:03 PM
When in doubt, use CC Emulator!
oeed #7
Posted 04 March 2013 - 05:07 PM
Since I cant test my program myself, and I have a good feeling it wont work right, can one of you "pros" tell me whats wrong with it? I would test it myself and make it better myself, but I cant seem to get ComputerCraft installed right..
anyways, it basically is a encryption and decryption code….


os.pullEvent == os.pullEventRaw
function top()
  rednet.open("top")
  term.clear()
  term.setCursorPos(1,1)
  term.setTextColor(colors.lightBlue)
  print("SimpleOS")
  term.setTextColor(colors.gray)
  print("========")
  term.setTextColor(colors.white)
  sleep(1)
  term.setTextColor(colors.green)
  print("Password: ")
  local pass = read()
  if pass == ("a22h013S[123]") then
	end top()
  else
  os.reboot()
  end
end

function encrypte()  --This encryptes the msg you want to send.
  msg ==
	"a" == "01"
"b" == "001"
"c" == "0001"
"d" == "0010"
"e" == "0100"
"f" == "1000"
"g" == "1001"
"h" == "1010"
"i" == "1100"
"j" == "1110"
"k" == "1101"
"l" == "0110"
"m" == "1011"
"n" == "0011"
"o" == "0111"
"p" == "0010"
"q" == "1111"
"r" == "10"
"s" == "110"
"t" == "010"
"u" == "100"
"v" == "111"
"w" == "101"
"x" == "000"
"y" == "011"
"z" == "0000"
= Nmsg
end

function send()
  rednet.broadcast(Nmsg)
end

function decrypte() --This decryptes the message your receiveing
  RDmsg ==
	"01"   == "a"
"001"  == "b"
"0001" == "c"
"0010" == "d"
"0100" == "e"
"1000" == "f"
"1001" == "j"
"1010" == "h"
"1100" == "i"
"1110" == "j"
"1101" == "k"
"0110" == "l"
"1011" == "m"
"0011" == "n"
"0111" == "o"
"0010" == "p"
"1111" == "q"
"10"   == "r"
"110"  == "s"
"010"  == "t"
"100"  == "u"
"111"  == "v"
"101"  == "w"
"000"  == "x"
"011"  == "y"
"0000" == "z"
= RNmsg
end

function receive()
  id,DRmsg == rednet.receive
end
top()
while true do
  term.setTextColor(colors.lime)
  print("Message: ")
  term.setTextColor(colors.white)
  local msg = read()
  encrypte(msg)
  send(Nmsg)
  receive(DRmsg)
  decrypte(DRmsg)
  term.setTextColor(colors.purple)
  print(id..":Message: ")
  write(RNmsg)
end

i had all this stuff on how to fix it then I closed Chrome by accident :angry:/>

Anyway, so much of this makes no sense. Delete the first line. It's 'encrypt' not 'encrypte', and that functino makes no sense. I'd recode it, really theres nothing in there that really works :P/>
Moody #8
Posted 04 March 2013 - 05:51 PM
Just some quick note:
When you do an encryption program, why not bother doing it a bit more complicated: Just use a proper encryption that is not based on static value mapping but dynamic encryption that comes with a key you must have to read the message.
It shouldnt be too hard to do and would increase the safety of your encryption vastly - here everybody that has the program can just read the message.
oeed #9
Posted 04 March 2013 - 07:01 PM
Just some quick note:
When you do an encryption program, why not bother doing it a bit more complicated: Just use a proper encryption that is not based on static value mapping but dynamic encryption that comes with a key you must have to read the message.
It shouldnt be too hard to do and would increase the safety of your encryption vastly - here everybody that has the program can just read the message.

Yea, I don't know whether you could class this as encryption at all really. It does work as a file size doubler.
KaoS #10
Posted 04 March 2013 - 11:15 PM
you should generally start by telling us what is "right", what it should do etc
lol sorry about that, I thought it would be easy to tell with the comments inside the code itself, but it basically a encrypter and a decrypter.

Ah well many people post code that does nothing like what they want :)/> I was 90% asleep when I posted that lol. didn't want to read the code
Spongy141 #11
Posted 06 March 2013 - 12:11 PM
-snip-

i had all this stuff on how to fix it then I closed Chrome by accident :angry:/>

Anyway, so much of this makes no sense. Delete the first line. It's 'encrypt' not 'encrypte', and that functino makes no sense. I'd recode it, really theres nothing in there that really works :P/>
Well I know that the encrypting and decrypting part does nothing, I was mainly asking how would I make it work so it could change what a string says. Lol I wish your Chrome did close by accident, it probably would have been very helpful.
Pharap #12
Posted 06 March 2013 - 03:39 PM
Replacing strings in strings is easy, sadly it rarely makes a good encryption system since it's usually easily undo-able, and there's a slim chance two strings put in can give the same output depending on the replace system.
For example on your system:
z='0000', a='01', x='000', b='001',
Therefore using string swap 'za' is the same as 'xb'
This means the idea of decrypting it is flawed as it won't always give back the right result.

Also, by doing this you would more than triple the size of the data you're sending, since each letter is around 1-2 bytes (8-16 bits) in length (depending on encoding). For example, for every x (1 char = 1 byte) you are getting 000 (3 chars = 3 bytes).

If you want to do encryption, I suggest you learn about ascii and bytes, so you know how characters are actually stored and read like binary numbers. Once you know that, you can play around with the bits in the bytes that represent the characters until you find a system that you think works as a good reversible encryption system.

Edit -
Couldn't find a decent tutorial on binary (didn't look very hard, just looked up 'binary'), so instead I wrote one:
http://www.computercraft.info/forums2/index.php?/topic/10894-bytes-and-binary-the-basics/
Enjoy, (then complain because my 4am brain isn't good at writing.)
Spongy141 #13
Posted 07 March 2013 - 03:44 AM
Replacing strings in strings is easy, sadly it rarely makes a good encryption system since it's usually easily undo-able, and there's a slim chance two strings put in can give the same output depending on the replace system.
For example on your system:
z='0000', a='01', x='000', b='001',
Therefore using string swap 'za' is the same as 'xb'
This means the idea of decrypting it is flawed as it won't always give back the right result.

Also, by doing this you would more than triple the size of the data you're sending, since each letter is around 1-2 bytes (8-16 bits) in length (depending on encoding). For example, for every x (1 char = 1 byte) you are getting 000 (3 chars = 3 bytes).

If you want to do encryption, I suggest you learn about ascii and bytes, so you know how characters are actually stored and read like binary numbers. Once you know that, you can play around with the bits in the bytes that represent the characters until you find a system that you think works as a good reversible encryption system.

Edit -
Couldn't find a decent tutorial on binary (didn't look very hard, just looked up 'binary'), so instead I wrote one:
http://www.computerc...ary-the-basics/
Enjoy, (then complain because my 4am brain isn't good at writing.)
Well I honestly don't see how memory could cause an issue, since the most I have ever used was probably 20 KBs for a CC program, and plus(not trying to prove anything, just making a reply, hope I don't cause you offence) I never recall CC having a memory system for how much you can store. But anyways, I'll look into using ascii binary code for the encryting and decryting, I have used them in the past, mainly for non related games. Well thanks for the tip.
ikke009 #14
Posted 07 March 2013 - 06:00 AM
When in doubt, use CC Emulator!
Couln't have said it better myself :)/>
BrolofTheViking #15
Posted 07 March 2013 - 06:16 AM
There are a lot of nonsensical things in that code.
Anyway, last year I wrote a very good encryption/decryption algorithm that I can try to fish up again. It's written in python, but it should be easy enough to translate into Lua. The encryption is nearly unbreakable without knowing how it works and having the alphabet it uses.
It's so effective because any one character in it can be turned into hundreds or thousands of different combinations of a configurable amount of other characters. The default I used with it was to turn 1 character into three characters, but it would be just as effective if it turned each character into 2 characters. I'll try to find it.

EDIT: I found the code pretty quickly.
http://pastebin.com/bmQnQ0Wk
Python is a whitespace-based language, which can make it odd to read at times, especially when given a width constraint like pastebin does.
Pharap #16
Posted 07 March 2013 - 06:31 AM
Well I honestly don't see how memory could cause an issue, since the most I have ever used was probably 20 KBs for a CC program, and plus(not trying to prove anything, just making a reply, hope I don't cause you offence) I never recall CC having a memory system for how much you can store. But anyways, I'll look into using ascii binary code for the encryting and decryting, I have used them in the past, mainly for non related games. Well thanks for the tip.

Thing is, using your current 'encryption' system, that 20kb would become a good 60 or 80 kb.
Those files do get stored on the computer hosting the game (ie your computer or the computer holding the server).
Also, adding unneeded data is generally considered a bad thing in an encryption system. a bit of extra data is fine, but 3-4 times the amount is a really bad idea.
I suggest looking at how other people handle encryption or some encryptions systems like SHA. Shifting Ciphers are also good to use since they don't require much extra memory and are completely reversible providing you know how they work. Enigma is a good example of a shifting cipher.
Spongy141 #17
Posted 07 March 2013 - 06:26 PM
Thing is, using your current 'encryption' system, that 20kb would become a good 60 or 80 kb.
Those files do get stored on the computer hosting the game (ie your computer or the computer holding the server).
Also, adding unneeded data is generally considered a bad thing in an encryption system. a bit of extra data is fine, but 3-4 times the amount is a really bad idea.
I suggest looking at how other people handle encryption or some encryptions systems like SHA. Shifting Ciphers are also good to use since they don't require much extra memory and are completely reversible providing you know how they work. Enigma is a good example of a shifting cipher.
Well other than making the encryption itself, I still don't know how to replace a var inside a string, I tried looking it up, but mainly found random crap about other stuff.
Spongy141 #18
Posted 07 March 2013 - 06:31 PM
There are a lot of nonsensical things in that code.
Anyway, last year I wrote a very good encryption/decryption algorithm that I can try to fish up again. It's written in python, but it should be easy enough to translate into Lua. The encryption is nearly unbreakable without knowing how it works and having the alphabet it uses.
It's so effective because any one character in it can be turned into hundreds or thousands of different combinations of a configurable amount of other characters. The default I used with it was to turn 1 character into three characters, but it would be just as effective if it turned each character into 2 characters. I'll try to find it.

EDIT: I found the code pretty quickly.
http://pastebin.com/bmQnQ0Wk
Python is a whitespace-based language, which can make it odd to read at times, especially when given a width constraint like pastebin does.
Lol the thing I like doing the least, converting code, lol thanks anyways, but I don't know python at all, and honestly really never heard of it. But thanks anyways, and I might try to convert it (If I'm feeling up to it).
Pharap #19
Posted 08 March 2013 - 01:55 AM
Thing is, using your current 'encryption' system, that 20kb would become a good 60 or 80 kb.
Those files do get stored on the computer hosting the game (ie your computer or the computer holding the server).
Also, adding unneeded data is generally considered a bad thing in an encryption system. a bit of extra data is fine, but 3-4 times the amount is a really bad idea.
I suggest looking at how other people handle encryption or some encryptions systems like SHA. Shifting Ciphers are also good to use since they don't require much extra memory and are completely reversible providing you know how they work. Enigma is a good example of a shifting cipher.
Well other than making the encryption itself, I still don't know how to replace a var inside a string, I tried looking it up, but mainly found random crap about other stuff.

The function you are looking for is string.gsub: http://pgl.yoyo.org/luai/i/string.gsub note that you can replace any of the fancy % patterns with the string you want replacing. If you want to learn about patterns though, you can look here: http://pgl.yoyo.org/luai/i/5.4+String+Manipulation or have a nose around in the tutorials here on the forums to see if you can find a better tutorial.
Spongy141 #20
Posted 08 March 2013 - 03:59 AM
Thing is, using your current 'encryption' system, that 20kb would become a good 60 or 80 kb.
Those files do get stored on the computer hosting the game (ie your computer or the computer holding the server).
Also, adding unneeded data is generally considered a bad thing in an encryption system. a bit of extra data is fine, but 3-4 times the amount is a really bad idea.
I suggest looking at how other people handle encryption or some encryptions systems like SHA. Shifting Ciphers are also good to use since they don't require much extra memory and are completely reversible providing you know how they work. Enigma is a good example of a shifting cipher.
Well other than making the encryption itself, I still don't know how to replace a var inside a string, I tried looking it up, but mainly found random crap about other stuff.

The function you are looking for is string.gsub: http://pgl.yoyo.org/luai/i/string.gsub note that you can replace any of the fancy % patterns with the string you want replacing. If you want to learn about patterns though, you can look here: http://pgl.yoyo.org/...ng+Manipulation or have a nose around in the tutorials here on the forums to see if you can find a better tutorial.
Thanks, P.S. if your ever looking to see if this program gets release… it wont, well not separate that is. since its going to be part of my new OS, but anyways thanks guys for helping.
robhol #21
Posted 08 March 2013 - 05:08 AM
There are a lot of nonsensical things in that code.
Anyway, last year I wrote a very good encryption/decryption algorithm that I can try to fish up again. It's written in python, but it should be easy enough to translate into Lua. The encryption is nearly unbreakable without knowing how it works and having the alphabet it uses.
It's so effective because any one character in it can be turned into hundreds or thousands of different combinations of a configurable amount of other characters. The default I used with it was to turn 1 character into three characters, but it would be just as effective if it turned each character into 2 characters. I'll try to find it.

EDIT: I found the code pretty quickly.
http://pastebin.com/bmQnQ0Wk
Python is a whitespace-based language, which can make it odd to read at times, especially when given a width constraint like pastebin does.

If it's a homebrew encryption algorithm and you're not a professional cryptographer, it's breakable. :P/>
Pharap #22
Posted 08 March 2013 - 05:43 AM
The function you are looking for is string.gsub: http://pgl.yoyo.org/luai/i/string.gsub note that you can replace any of the fancy % patterns with the string you want replacing. If you want to learn about patterns though, you can look here: http://pgl.yoyo.org/...ng+Manipulation or have a nose around in the tutorials here on the forums to see if you can find a better tutorial.
Thanks, P.S. if your ever looking to see if this program gets release… it wont, well not separate that is. since its going to be part of my new OS, but anyways thanks guys for helping.

I can relate, I'm currently developing my own OS but I'm unlikely to release it unless I can get it backwards compatible with CraftOS programs (I'm essentially ripping the system to shreds and rebuilding it to my liking)