Subversion-Projekte lars-tiefland.content-management

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
 
2
<?php
3
// Verschlüsselungsalgorithmus
4
function pre($_x)
5
{
6
	print( "<pre>" );
7
	print_r($_x);
8
	print( "</pre>" );
9
}
10
/*
11
$_a = array(
12
 
13
					1 => "4",
14
					2 => "8",
15
					3 => "16",
16
					4 => "32",
17
					5 => "64",
18
					6 => "128",
19
					7 => "256",
20
					8 => "512",
21
					9 => "1024",
22
					10 => "2048",
23
					11 => "4096",
24
					12 => "8192",
25
					13 => "16384"
26
			);
27
 
28
 
29
$a = "01012005120053";
30
 
31
 
32
$a = preg_split('//', $a, -1, PREG_SPLIT_NO_EMPTY);
33
 
34
function _crypt($_o, $_a)
35
{
36
	foreach(array_keys($_o) AS $elem)
37
	{
38
		$_n[]=dechex(ord($_o[$elem])*$_a[$elem]);
39
		echo $_n[$elem].".";
40
	}
41
 
42
	// return($_n);
43
}
44
 
45
function _ncrypt($_n, $_a)
46
{
47
	foreach(array_keys($_n) AS $elem)
48
	{
49
		$_o[]=chr(hexdec($_n[$elem])/($_a[$elem]));
50
	}
51
	return($_o);
52
}
53
 
54
$n = _crypt($a,$_a);
55
 
56
pre($n);
57
 
58
pre(_ncrypt($n,$_a));
59
*/
60
 
61
 
62
// test
63
$a[]="01012005120053";
64
$a[]="100.00";
65
$a[]="markus@niewerth.com";
66
 
67
foreach(array_keys($a) AS $elem)
68
{
69
	$b[$elem] = sprintf("%u",crc32(md5($a[$elem])));
70
	$b[$elem] = wordwrap( $b[$elem] , 2 , "###", 1);
71
	$a_[$elem] = explode("###",$b[$elem]);
72
}
73
 
74
foreach(array_keys($a_) as $elem)
75
{
76
	foreach(array_keys($a_[$elem]) as $key)
77
	{
78
		$x[]=dechex($a_[$elem][$key]);
79
	}
80
}
81
 
82
$key="";
83
 
84
for($i=0;$i<count($x);$i++)
85
{
86
	$key .= strtoupper($x[$i]).( ($i%5==0 && $i!=0) ? "-" : "");
87
}
88
 
89
pre($key);
90
 
91
 
92
?>
93
<form name="form1" method="post" action="">
94
  <input name="code" type="text" id="code">
95
  <input type="submit" name="submit" value="Abschicken">
96
</form>
97
 
98
<?
99
	if($_POST['submit'])
100
	{
101
		// Ncode
102
		$ncode="";
103
		$code = str_replace("-", "", $_POST['code']);
104
		$code = wordwrap( $code , 2 , "###", 1);
105
		$code = explode("###",$code);
106
		foreach(array_keys($code) AS $elem)
107
		{
108
			$ncode.=hexdec($code[$elem]);
109
		}
110
 
111
		$ncode = wordwrap( $ncode , 10 , "-", 1);
112
		$ncode = explode( "-", $ncode );
113
		$ncode = $ncode[0]."-".$ncode[1]."-".$ncode[2];
114
		// Vcode
115
		foreach(array_keys($a) AS $elem)
116
		{
117
			$b[$elem] = sprintf("%u",crc32(md5($a[$elem])));
118
		}
119
		$vcode = $b[0]."-".$b[1]."-".$b[2];
120
		echo "NCode:$ncode<br>";
121
		echo "VCode:$vcode<br>";
122
		if($ncode!=$vcode) { echo "Der code war nicht richtig!"; }else{ echo "Dies war ein gülltiger code"; }
123
	}
124
?>