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.



Your result can be seen below.

Result of php executing





Full code of TripCodeTest.php

  1. <?php 
  2. index();
  3. function index(){
  4.     //Configure::write('debug', 2);
  5.  
  6.     // set key
  7.     $key = '#テスト';
  8.  
  9.     // UTF-8 to SJIS
  10.     //$key = mb_convert_encoding($key, "SJIS", "UTF-8");  // to, from
  11.     $key = mb_convert_encoding($key, "SJIS", "auto");  // to, from
  12.  
  13.     // exec
  14.     $ret = _makeTrip($key);
  15.  
  16.     // debug
  17.     //debug($ret);
  18.     printf($ret);
  19. }
  20.  
  21. /*-----------------------------------------------------
  22.  * make 2ch TRIP ( = DES ) by CASEY.JP 2010 GPL
  23.  *-----------------------------------------------------
  24.  * VERSION:
  25.  *   2010.08.17 0.01 alpha
  26.  * NOTE:
  27.  *   digit  8: -2002.10.03
  28.  *   digit 10: 2002.10.03-
  29.  *   digit 12: 2009.06.19-
  30.  * test data for digit 10:
  31.  *   $key = "#テスト";             // ◆SQ2Wyjdi7M
  32.  *   $key = '#Wikipedia';           // ◆Ig9vRBfuyA
  33.  *   $key = '#istrip';              // ◆/WG5qp963c
  34.  * test data for digit 12:
  35.  *   $key = '#TESTTESTTESTTEST';    // ◆TDxLX5/h3FIK
  36.  *   $key = '#テストテストテスト';   // ◆Iwo2kAiiMPp6
  37.  * SJIS CODE in SCRIPT
  38.  */
  39. function _makeTrip($key){
  40.     // check
  41.     preg_match('|^#(.*)$|', $key, $keys);
  42.     if(empty($keys[1])) return false;
  43.     $key = $keys[1];
  44.  
  45.     // start
  46.     if(strlen($key) >= 12){
  47.          // digit 12
  48.         $mark = substr($key, 0, 1);
  49.         if($mark == '#' || $mark == '$'){
  50.             if(preg_match('|^#([[:xdigit:]]{16})([./0-9A-Za-z]{0,2})$|', $key, $str)){
  51.                 $trip = substr(crypt(pack('H*', $str[1]), "$str[2].."), -10);
  52.             }else{
  53.                 // ext
  54.                 $trip = '???';
  55.             }
  56.         }else{
  57.             $trip = substr(base64_encode(sha1($key, TRUE)), 0, 12);
  58.             $trip = str_replace('+', '.', $trip);
  59.         }
  60.     }else{
  61.         // digit 10
  62.         $tripkey = htmlspecialchars($key, ENT_QUOTES);
  63.         $salt = htmlspecialchars($key, ENT_QUOTES);
  64.         $salt = substr($tripkey . 'H.', 1, 2);
  65.  
  66.         $pattern = '/[\x00-\x20\x7B-\xFF]/';
  67.         $salt = preg_replace($pattern, ".", $salt);
  68.  
  69.         $patterns = ":;<=>?@[\\]^_`";
  70.         $mach = "ABCDEFGabcdef";
  71.  
  72.         for($i=0; $i<=13-1; $i++){
  73.             $salt = str_replace($patterns[$i], $mach[$i], $salt);
  74.         }
  75.         //$salt
  76.         printf($salt."\n");
  77.         $trip = crypt($tripkey, "..");
  78.         //$trip = crypt("テスト", $salt);
  79.         $trip = substr($trip, -10);
  80.     }
  81.     //$trip = '◆'.$trip;
  82.     return $trip;
  83. } ?>
File Description
  • TripCodeTest
  • PHP Code
  • 07 Jan-2021
  • 2.41 Kb
You can Share it: