TripCodeTest - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of TripCodeTest.php
- <?php
- index();
- function index(){
- //Configure::write('debug', 2);
- // set key
- $key = '#テスト';
- // UTF-8 to SJIS
- //$key = mb_convert_encoding($key, "SJIS", "UTF-8"); // to, from
- $key = mb_convert_encoding($key, "SJIS", "auto"); // to, from
- // exec
- $ret = _makeTrip($key);
- // debug
- //debug($ret);
- printf($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);
- }
- //$salt
- printf($salt."\n");
- $trip = crypt($tripkey, "..");
- //$trip = crypt("テスト", $salt);
- $trip = substr($trip, -10);
- }
- //$trip = '◆'.$trip;
- return $trip;
- } ?>