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

Keygen

Started by JustTom, 16 June 2014 - 10:09 AM
JustTom #1
Posted 16 June 2014 - 12:09 PM
Hey all
I'm made a program, which generates a code, and send it to the player (all of the players), then ask for the code.
That's great but when I type the code in it writes: no… so please someone fix it

x = math.random(1,1000)
rednet.broadcast((x))
sleep(0.1)
a, b = rednet.receive()
sleep(0.1)
write"code: "
input = read()
if input == b then
print"ok"
else
print"no"
end
theoriginalbit #2
Posted 16 June 2014 - 12:20 PM
I'm not completely sure I understand the purpose of your code. how do you know that you are entering the same code? you're not printing the value of x, so how do you know what the random number is to enter it in? and more to the point why are you transmitting the number out and then waiting for the same number to be sent back? or do you do something with said number at the other end?

are we able to see the script that sends a response?
JustTom #3
Posted 16 June 2014 - 12:21 PM
I'm not completely sure I understand the purpose of your code. how do you know that you are entering the same code? you're not printing the value of x, so how do you know what the random number is to enter it in? and more to the point why are you transmitting the number out and then waiting for the same number to be sent back? or do you do something with said number at the other end?

are we able to see the script that sends a response?
i made a little prog for a pocket comp

a, b = rednet.receive()
print("message: "..B)/>/>

oh sorry i sent the bad version

x = math.random(1,1000)
rednet.broadcast((x))
sleep(0.1)
write"code: "
input = read()
if input == (B)/>/> then
print"ok"
else
print("no, "..x)
end
this is it
Edited on 16 June 2014 - 10:26 AM
theoriginalbit #4
Posted 16 June 2014 - 12:28 PM
ah I see. so your pocket computer program never actually responds to your main program then?
JustTom #5
Posted 16 June 2014 - 12:34 PM
ah I see. so your pocket computer program never actually responds to your main program then?
nah it just writes the code for me to type to the main comp
but when i type in, it says no.. I think it's because the b

if input == (B)/>
but I don't Know how to fix it
theoriginalbit #6
Posted 16 June 2014 - 03:30 PM
oh I see, your 'better' version omits the rednet.receive. the problem is definitely the b, it is not defined, you should be instead checking that the user input is equal to tostring( x )
JustTom #7
Posted 16 June 2014 - 04:08 PM
oh I see, your 'better' version omits the rednet.receive. the problem is definitely the b, it is not defined, you should be instead checking that the user input is equal to tostring( x )
Thanks man
JustTom #8
Posted 16 June 2014 - 04:50 PM
ahh I'm sorry I can't pls write here the code
Lyqyd #9
Posted 16 June 2014 - 05:04 PM
Show us what you tried when attempting to implement theoriginalbit's advice and we will point out where you went wrong.
JustTom #10
Posted 16 June 2014 - 05:09 PM
Show us what you tried when attempting to implement theoriginalbit's advice and we will point out where you went wrong.
it's already works but there is:

x = math.random(1,1000)
rednet.broadcast((x))
input = read()
if input == tostring(x) then
print"ok"
else
print("no, "..x)
end
Lyqyd #11
Posted 16 June 2014 - 05:12 PM
So what is the problem you're currently having? I'm not sure what code you would have been asking for if you already have that working.
JustTom #12
Posted 16 June 2014 - 05:20 PM
So what is the problem you're currently having? I'm not sure what code you would have been asking for if you already have that working.
I made a remote controlled gate in the same map which sends rednet messages just like this prog and i always get the code from the gate instead of the keygen… yep that's all
Cavious #13
Posted 18 June 2014 - 09:32 PM
So what is the problem you're currently having? I'm not sure what code you would have been asking for if you already have that working.
I made a remote controlled gate in the same map which sends rednet messages just like this prog and i always get the code from the gate instead of the keygen… yep that's all

Could you clarify just a little more.

From the sounds of it the pocket computer transmits the random number(aka your keygen), and the gate is suppose to open?

I think you might be misunderstanding the point of a "KeyGen". If you are wanting it to respond to a password, then i'd suggest you store the password on the pocket computer using a file. The file should be renamed with a hidden prefix ".", that way if you drop it no one can find it nor will they be the wiser.

I'd suggest that you do the same thing with the gate, but use the random number to create new "keys" and store those keys into a hidden file again, and have the gate check the file against the transmitted password. You can do this using the Fs API.

I would also never suggest using "broadcast" for sending secure information back and forth. Use the protocols and send it to a specific computer id. If you want some examples jump on my pastebin I use these type of methods all the times for my secure doors and entrances.

http://pastebin.com/u/Cavious

Good Luck,

Donald R. Valverde (Cavious)