- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
class Key{
private $chars = array('1'=>'a','2'=>'b','3'=>'c','4'=>'d','5'=>'e','6'=>'f','7'=>'g','8'=>'h','9'=>'i');
private $invChars = array('9'=>'a','8'=>'b','7'=>'c','6'=>'d','5'=>'e','4'=>'f','3'=>'g','2'=>'h','1'=>'i');
private $key = "";
private $numbers = array();
public function createKey(){
for($a=0;$a<4;$a++){
$this->numbers[0] = rand(1, 9);
$this->numbers[1] = rand(1, 9);
$this->key .= $this->numbers[0].$this->invChars[$this->numbers[1]].$this->numbers[1].$this->chars[$this->numbers[0]]."-";
}
return substr_replace($this->key, '', 19, 1);
}
public function checkKey($key){
if(preg_match("/^([1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I])$/", $key)){
$key = str_replace('-', '', $key);
if($this->chars[$key[0]] == $key[3] && $this->invChars[$key[2]] == $key[1]){
if($this->chars[$key[4]] == $key[7] && $this->invChars[$key[6]] == $key[5]){
if($this->chars[$key[8]] == $key[11] && $this->invChars[$key[10]] == $key[9]){
if($this->chars[$key[12]] == $key[15] && $this->invChars[$key[14]] == $key[13]){
return true;
}
else{
return false;
}
}
else{
return false;
}
}
else{
return false;
}
}
else{
return false;
}
}
else{
return false;
}
}
}
minusator41 14.03.2014 17:06 # −7
guest 14.03.2014 17:21 # −1