 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
WankaUSR
Joined: 14 Aug 2007 Posts: 33
|
Posted: Tue Jul 22, 2008 12:59 pm Post subject: help with a keygenerator from php to ahk |
|
|
So what i want to do is use this php code to create a key for my program. The ideea is that a web page generates a code and the program will check for if it is correct.
| Code: | $name=wankausr;
$random=str_makerand (strlen($name), strlen($name), true, false, true);
$uniqkey=str_makerand (5, 5, true, $usespecial, false)."-".str_makerand (5, 5, true, $usespecial, false)."-".str_makerand (5, 5, true, $usespecial, false)."-".str_makerand (5, 5, true, $usespecial, false)."-".str_makerand (5, 5, true, $usespecial, false);
echo $uniqkey."<br>random=".$random;
function str_makerand ($minlength, $maxlength, $useupper, $usespecial, $usenumbers)
{
$charset="key".$name."apo".$random;
if ($useupper) $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if ($usenumbers) $charset .= "0123456789";
if ($usespecial) $charset .= "~@#$%^*()_+-={}|][";
if ($minlength > $maxlength) $length = mt_rand ($maxlength, $minlength);
else $length = mt_rand ($minlength, $maxlength);
$nba=strlen($charset)/7;
$nb=intval($nba);
for ($i=0; $i<$length; $i++) {
$key .= $charset[(mt_rand(0,(strlen($charset)-$nb)))];
$nb=intval(($nb*7-$nb)/5);
}
return $key;
} |
I got the code from the internet and modified it and i don't know how to make this code
| Code: | | $charset[(mt_rand(0,(strlen($charset)-$nb)))]; | in ahk language. If this is a lot to ask can at least someone tell me how to get in php the first, the fifth etc letter from a string because it would be a lot simpler to use it in ahk, or simply guide me to another way to do this |
|
| Back to top |
|
 |
BoBo² Guest
|
Posted: Tue Jul 22, 2008 2:09 pm Post subject: |
|
|
| Code: | $name := "wankausr"
$random := str_makerand (strlen($name), strlen($name), true, false, true)
$uniqkey := str_makerand (5, 5, true, $usespecial, false)."-".str_makerand (5, 5, true, $usespecial, false)."-".str_makerand (5, 5, true, $usespecial, false)."-".str_makerand (5, 5, true, $usespecial, false)."-".str_makerand (5, 5, true, $usespecial, false)
MsgBox % $uniqkey."<br>random=".$random
function str_makerand ($minlength, $maxlength, $useupper, $usespecial, $usenumbers)
{
$charset="key".$name."apo".$random;
if ($useupper="true")
$charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if ($usenumbers="true")
$charset = "0123456789"
if ($usespecial="true")
$charset = "~@#$%^*()_+-={}|]["
if ($minlength > $maxlength)
Random, $length, $maxlength, $minlength
else
Random, $length, $minlength, $maxlength
$nba := strlen($charset)/7
$nb := intval($nba)
Loop %$length%
{
$key .= $charset[(mt_rand(0,(strlen($charset)-$nb)))];
$nb := intval(($nb*7-$nb)/5);
}
Return ($key)
} | I guess that'll be the rough structure. You've to tweak it the whole against the AHK Syntax (and check out for the red marked lines for equivalent AHK commands). Not tested. Good luck.  |
|
| Back to top |
|
 |
WankaUSR
Joined: 14 Aug 2007 Posts: 33
|
Posted: Tue Jul 22, 2008 5:49 pm Post subject: |
|
|
| that's a a lot better then my translation to ahk but i see you have the same problem as me at that line of code. |
|
| Back to top |
|
 |
BoBo² Guest
|
Posted: Tue Jul 22, 2008 8:31 pm Post subject: |
|
|
| Code: | name := "wankausr"
random := str_makerand(strlen(name), strlen(name), "true", "false", "true")
Loop, 5
uniqkey .= str_makerand(5, 5, "true", usespecial, "false") . "-"
StringTrimRight, uniqkey, uniqkey, 1
MsgBox % uniqkey . "<br>random=" . random
str_makerand(minlength, maxlength, useupper, usespecial, usenumbers)
{
charset="key".name."apo".random
if (useupper="true")
charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if (usenumbers="true")
charset = "0123456789"
if (usespecial="true")
charset := "~@#%^*()_+-={}|][$"
if (minlength > maxlength)
Random, length, maxlength, minlength
else
Random, length, minlength, maxlength
nba := strlen(charset)/7
nb := Round(nba)
Loop %length%
{
Random, StartingPos, 0, % strlen(charset)-nb
key .= SubStr(charset, StartingPos, 1)
nb := Round(nb*7-nb)/5
}
Return (key)
} |  |
|
| Back to top |
|
 |
WankaUSR
Joined: 14 Aug 2007 Posts: 33
|
Posted: Wed Jul 23, 2008 7:26 am Post subject: |
|
|
thanks man it works i just had to remove the "" from upper charset because it selected the " to in the code although special chars are set to false. Thanks! I really appreciate your help
| Code: | name := "wankausr"
random := str_makerand(strlen(name), strlen(name), "true", "false", "true")
Loop, 5
uniqkey .= str_makerand(5, 5, "true", usespecial, "false") . "-"
StringTrimRight, uniqkey, uniqkey, 1
MsgBox % uniqkey . " random=" . random
str_makerand(minlength, maxlength, useupper, usespecial, usenumbers)
{
charset=key%name%apo%random%
msgbox %charset%
if (useupper="true")
StringUpper, charset, %charset%
if (usenumbers="true")
charset = 0123456789
if (usespecial="true")
charset := "~@#%^*()_+-={}|][$"
if (minlength > maxlength)
Random, length, maxlength, minlength
else
Random, length, minlength, maxlength
nba := strlen(charset)/7
nb := Round(nba)
Loop %length%
{
Random, StartingPos, 0, % strlen(charset)-nb
key .= SubStr(charset, StartingPos, 1)
nb := Round(nb*7-nb)/5
}
Return (key)
} |
Edit: why doesn't the name and random variables show up in the function?
I've added msgbox %charset% with red in the script and the var don't show up. They are vital to the keygen |
|
| Back to top |
|
 |
WankaUSR
Joined: 14 Aug 2007 Posts: 33
|
Posted: Wed Jul 23, 2008 8:23 am Post subject: |
|
|
FIXED
added name&random to the function parameters
| Code: | name := "wankausr"
random := str_makerand(strlen(name), strlen(name), "false", "false", "false", bcdfghijlmnqrstuv, wxz)
Loop, 5
uniqkey .= str_makerand(5, 5, "true", usespecial, "false", name, random) . "-"
StringTrimRight, uniqkey, uniqkey, 1
MsgBox % uniqkey . "`nrandom=" . random
str_makerand(minlength, maxlength, useupper, usespecial, usenumbers, name, random)
{
charset=key%name%apo%random%
;msgbox %charset%
if (useupper="true")
StringUpper, charset, charset
if (usenumbers="true")
charset = 0123456789
if (usespecial="true")
charset := "~@#%^*()_+-={}|][$"
if (minlength > maxlength)
Random, length, maxlength, minlength
else
Random, length, minlength, maxlength
nba := strlen(charset)/7
nb := Round(nba)
Loop %length%
{
Random, StartingPos, 0, % strlen(charset)-nb
key .= SubStr(charset, StartingPos, 1)
nb := Round(nb*7-nb*2)/5
}
Return (key)
} |
|
|
| Back to top |
|
 |
BoBo² Guest
|
Posted: Wed Jul 23, 2008 8:47 am Post subject: |
|
|
Interesting challenge, because I never dealt with any php code before.
Would you mind to provide your final/working script at [Scripts & Functions]? |
|
| Back to top |
|
 |
WankaUSR
Joined: 14 Aug 2007 Posts: 33
|
Posted: Wed Jul 23, 2008 10:09 am Post subject: |
|
|
so here is the php keygenerator name and random key( wich will be generated by hardware fingerprint) dependent and splied into 5 chars@5 codes.
i'm working to fully translate into ahk and then post it into scripts and functions.
here is the address where you can see the php at work name=wankausr http://mixfm.raknetsoft.ro/sorin/ahk.php
| Code: | <?
$name=wankausr;
$random=str_makerand (17, 17, true, false, true,masterkey,sysloader);
$uniqkey=str_key (25, 25, true, $usespecial, false,$name,$random);
$serial=split_uniq ($uniqkey);
echo $uniqkey."<br>random=".$random."<br>".strlen($uniqkey);
echo "<br>Serial: ".$serial;
function split_uniq ($uniq)
{
for($nb=0;$nb<21;$nb=$nb+5)
{
if ($nb<20) $l="-";
$key .=substr($uniq, $nb, 5).$l;
}
$key =substr($key, 0, 29);
return $key;
}
function str_key ($minlength, $maxlength, $useupper, $usespecial, $usenumbers,$name,$random)
{
$charset="key".$name."apotv".$random;
if ($useupper) $charset=strtoupper($charset);
if ($usenumbers) $charset .= $charset."0123456789";
if ($usespecial) $charset .= $charset."~@#$%^*()_+-={}|][";
$nb=intval(strlen($charset)/2);
for ($i=0; $i<$maxlength; $i++) {
$key .=substr($charset, $nb, 1);
$nb=$nb-2;
}
return $key;
}
function str_makerand ($minlength, $maxlength, $useupper, $usespecial, $usenumbers,$name,$random)
{
$charset="key".$name."apotv".$random;
if ($useupper) $charset=strtoupper($charset);
if ($usenumbers) $charset .= $charset."0123456789";
if ($usespecial) $charset .= $charset."~@#$%^*()_+-={}|][";
for ($i=0; $i<$maxlength; $i++) {
$key .=substr($charset, $nb, 1);
$nb=$nb-3;
}
return $key;
}
?> |
EDIT: here is the ahk code but i am having trouble with the red lines because php can substract letters with "-" position that is letters from the end of the word and ahk shows an error invalid char "-"
| Code: | name = wankausr
random := str_makerand(strlen(name), strlen(name), "false", "false", "false","masterkey", "sysloader")
Loop, 5
uniqkey .= str_key(5, 5, "true", usespecial, "false", name, random) . "-"
StringTrimRight, uniqkey, uniqkey, 1
MsgBox % uniqkey . "`nrandom=" . random
str_makerand(minlength, maxlength, useupper, usespecial, usenumbers, name, random)
{
charset=key%name%apo%random%
msgbox %random%
if (useupper="true")
StringUpper, charset, %charset%
if (usenumbers="true")
charset := %charset%."0123456789"
if (usespecial="true")
charset := "~@#%^*()_+-={}|][$"
nb:=0
Loop %maxlength%
{
key .= SubStr(charset, nb, 1)
nb := %nb%-3
}
msgbox %key%
Return (key)
}
str_key(minlength, maxlength, useupper, usespecial, usenumbers, name, random)
{
charset=key%name%apo%random%
msgbox %charset%
if (useupper="true")
StringUpper, charset, %charset%
if (usenumbers="true")
charset := %charset%."0123456789"
if (usespecial="true")
charset := "~@#%^*()_+-={}|][$"
StringLen ,nba ,charset
nbx:=%nba%/2
nb := Round(nbx)
Loop %maxlength%
{
key .= SubStr(charset, nb, 1)
nb := %nb%-2
}
Return (key)
} |
|
|
| Back to top |
|
 |
BoBo² Guest
|
Posted: Wed Jul 23, 2008 10:43 am Post subject: |
|
|
| Code: | | nb := nb-3 ; expressionstyle |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|