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

Keygen

Started by xWoody25, 19 August 2012 - 11:17 AM
xWoody25 #1
Posted 19 August 2012 - 01:17 PM
Hi, im wondering is there a way to make a keygen in ComputerCraft, im fairly new to CC so if someone does know can you add notes so i can see what the code is doing, thanks in advance
immibis #2
Posted 19 August 2012 - 01:26 PM
What is a keygen in this context?
xWoody25 #3
Posted 19 August 2012 - 03:11 PM
What is a keygen in this context?
Like if someone made a password door with the

os.pullEvent = os.pullEventRaw

and instead of doing the floppy disk drive thing, i want to challenge myself to make a keygen for pass word doors
Kolpa #4
Posted 19 August 2012 - 03:36 PM
you cant really because you cant run 2 programs simultaneously
ardera #5
Posted 19 August 2012 - 03:54 PM
Code:

function genKey(len)
  s={}
  for n=0, 127 do
	s[n]=string.char(n)
  end
  function t01(len)
	ret={}
	for num=1, len do
   ret[#ret+1]=0
end
return unpack(ret)
  end
  all={}
  states={{t01(len)}}
  sa=300
  for n=1, table.maxn(s)^len do
	if math.floor(n/sa)==n/sa then sleep(0) end
	function set(s)
	  states[n]=states[#states]
   states[n][s]=states[n][1]+1
   if states[n][s]==128 then
	 states[n][s]=0
  if s<len then
		  set(s+1)
  end
   end
end
set(1)
function charAll()
   ret={}
   for num=1, len do
	 ret[num]=string.char(states[n][num])
   end
   return table.concat(ret, "")
end
	all[n]=charAll()
  end
  return all
end

You can use this function (genKey), param 1 has to be the length of the password.
And no worry if its taking long to build the keys… The function is just working (if you want to know how much rounds the main for loop goes, just type in the lua shell math.pow(128, thenumberofthespaces))

How it works:
every space is 1 number. It increases the number each round +1. If the number==128 then it sets the number to 0, and the next number in the states table +1.
xWoody25 #6
Posted 19 August 2012 - 04:17 PM
Code:

function genKey(len)
  s={}
  for n=0, 127 do
	s[n]=string.char(n)
  end
  function t01(len)
	ret={}
	for num=1, len do
   ret[#ret+1]=0
end
return unpack(ret)
  end
  all={}
  states={{t01(len)}}
  sa=300
  for n=1, table.maxn(s)^len do
	if math.floor(n/sa)==n/sa then sleep(0) end
	function set(s)
	  states[n]=states[#states]
   states[n][s]=states[n][1]+1
   if states[n][s]==128 then
	 states[n][s]=0
  if s<len then
		  set(s+1)
  end
   end
end
set(1)
function charAll()
   ret={}
   for num=1, len do
	 ret[num]=string.char(states[n][num])
   end
   return table.concat(ret, "")
end
	all[n]=charAll()
  end
  return all
end

You can use this function (genKey), param 1 has to be the length of the password.
And no worry if its taking long to build the keys… The function is just working (if you want to know how much rounds the main for loop goes, just type in the lua shell math.pow(128, thenumberofthespaces))

How it works:
every space is 1 number. It increases the number each round +1. If the number==128 then it sets the number to 0, and the next number in the states table +1.
is there a way to simplify that explanation xD, but thanks soo much for the code xD
ardera #7
Posted 19 August 2012 - 04:23 PM
Er… It only goes trough all different possibilities…

use of the function: atable=genKey(length)
length has to be the length of the keys.
atable is now an table (if you don't know how to use tables: google: lua table)

WARNING: keys with a smaller length will not be generated!