1
2
3
4
5
6
7
8
9
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
| <?php function index(){
Configure::write('debug', 2);
// set key
$key = '#istrip';
// UTF-8 to SJIS
$key = mb_convert_encoding($key, "SJIS", "UTF-8"); // to, from
// exec
$ret = $this->_makeTrip($key);
// debug
debug($ret);
}
/*-----------------------------------------------------
* make 2ch TRIP ( = DES ) by CASEY.JP 2010 GPL
*-----------------------------------------------------
* VERSION:
* 2010.08.17 0.01 alpha
* NOTE:
* digit 8: -2002.10.03
* digit 10: 2002.10.03-
* digit 12: 2009.06.19-
* test data for digit 10:
* $key = "#テスト"; // ◆SQ2Wyjdi7M
* $key = '#Wikipedia'; // ◆Ig9vRBfuyA
* $key = '#istrip'; // ◆/WG5qp963c
* test data for digit 12:
* $key = '#TESTTESTTESTTEST'; // ◆TDxLX5/h3FIK
* $key = '#テストテストテスト'; // ◆Iwo2kAiiMPp6
* SJIS CODE in SCRIPT
*/
function _makeTrip($key){
// check
preg_match('|^#(.*)$|', $key, $keys);
if(empty($keys[1])) return false;
$key = $keys[1];
// start
if(strlen($key) >= 12){
// digit 12
$mark = substr($key, 0, 1);
if($mark == '#' || $mark == '$'){
if(preg_match('|^#([[:xdigit:]]{16})([./0-9A-Za-z]{0,2})$|', $key, $str)){
$trip = substr(crypt(pack('H*', $str[1]), "$str[2].."), -10);
}else{
// ext
$trip = '???';
}
}else{
$trip = substr(base64_encode(sha1($key, TRUE)), 0, 12);
$trip = str_replace('+', '.', $trip);
}
}else{
// digit 10
$tripkey = htmlspecialchars($key, ENT_QUOTES);
$salt = htmlspecialchars($key, ENT_QUOTES);
$salt = substr($tripkey . 'H.', 1, 2);
$pattern = '/[\x00-\x20\x7B-\xFF]/';
$salt = preg_replace($pattern, ".", $salt);
$patterns = ":;<=>?@[\\]^_`";
$mach = "ABCDEFGabcdef";
for($i=0; $i<=13-1; $i++){
$salt = str_replace($patterns[$i], $mach[$i], $salt);
}
$trip = crypt($tripkey, $salt);
$trip = substr($trip, -10);
}
$trip = '◆'.$trip;
return $trip;
} ?>
|