3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('ALPHABET', 'acdegilmnoprstuw'); $hash = 680131659347; $string = 'leepadg'; echo sprintf('Hash of string «%s» is «%s».', $string, get_hash(ALPHABET, $string)), PHP_EOL , sprintf('String of hash «%s» is «%s».', $hash, unhash(ALPHABET, $hash)) ; function get_hash($alphabet, $string) { $h = 7; $len = strlen($string); for($i = 0; $i < $len; $i++) { $h = ($h * 37 + strpos($alphabet, $string[$i])); } return $h; } function unhash($alphabet, $hash) { $result = ''; $len = strlen($alphabet); while ($hash > 7) { for ($i = 0; $i < $len; $i++) { $newres = ($hash - $i) / 37; if (is_int($newres)) { $result .= $alphabet[$i]; $hash = $newres; break; } } } return strrev($result); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RMT4Q
function name:  (null)
number of ops:  30
compiled vars:  !0 = $hash, !1 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'ALPHABET'
          2        SEND_VAL                                                 'acdegilmnoprstuw'
          3        DO_ICALL                                                 
    5     4        ASSIGN                                                   !0, 680131659347
    6     5        ASSIGN                                                   !1, 'leepadg'
    8     6        INIT_FCALL                                               'sprintf'
          7        SEND_VAL                                                 'Hash+of+string+%C2%AB%25s%C2%BB+is+%C2%AB%25s%C2%BB.'
          8        SEND_VAR                                                 !1
          9        INIT_FCALL_BY_NAME                                       'get_hash'
         10        FETCH_CONSTANT                                   ~5      'ALPHABET'
         11        SEND_VAL_EX                                              ~5
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0  $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                         $7      
         16        ECHO                                                     $7
         17        ECHO                                                     '%0A'
    9    18        INIT_FCALL                                               'sprintf'
         19        SEND_VAL                                                 'String+of+hash+%C2%AB%25s%C2%BB+is+%C2%AB%25s%C2%BB.'
         20        SEND_VAR                                                 !0
         21        INIT_FCALL_BY_NAME                                       'unhash'
         22        FETCH_CONSTANT                                   ~8      'ALPHABET'
         23        SEND_VAL_EX                                              ~8
         24        SEND_VAR_EX                                              !0
         25        DO_FCALL                                      0  $9      
         26        SEND_VAR                                                 $9
         27        DO_ICALL                                         $10     
         28        ECHO                                                     $10
   36    29      > RETURN                                                   1

Function get_hash:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 7
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 7
Branch analysis from position: 18
Branch analysis from position: 7
filename:       /in/RMT4Q
function name:  get_hash
number of ops:  20
compiled vars:  !0 = $alphabet, !1 = $string, !2 = $h, !3 = $len, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        ASSIGN                                                   !2, 7
   14     3        STRLEN                                           ~6      !1
          4        ASSIGN                                                   !3, ~6
   15     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->16
   16     7    >   MUL                                              ~9      !2, 37
          8        INIT_FCALL                                               'strpos'
          9        SEND_VAR                                                 !0
         10        FETCH_DIM_R                                      ~10     !1, !4
         11        SEND_VAL                                                 ~10
         12        DO_ICALL                                         $11     
         13        ADD                                              ~12     ~9, $11
         14        ASSIGN                                                   !2, ~12
   15    15        PRE_INC                                                  !4
         16    >   IS_SMALLER                                               !4, !3
         17      > JMPNZ                                                    ~15, ->7
   18    18    > > RETURN                                                   !2
   19    19*     > RETURN                                                   null

End of function get_hash

Function unhash:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 6
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 8
Branch analysis from position: 20
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 8
Branch analysis from position: 20
Branch analysis from position: 8
filename:       /in/RMT4Q
function name:  unhash
number of ops:  27
compiled vars:  !0 = $alphabet, !1 = $hash, !2 = $result, !3 = $len, !4 = $i, !5 = $newres
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        ASSIGN                                                   !2, ''
   23     3        STRLEN                                           ~7      !0
          4        ASSIGN                                                   !3, ~7
   24     5      > JMP                                                      ->20
   25     6    >   ASSIGN                                                   !4, 0
          7      > JMP                                                      ->18
   26     8    >   SUB                                              ~10     !1, !4
          9        DIV                                              ~11     ~10, 37
         10        ASSIGN                                                   !5, ~11
   27    11        TYPE_CHECK                                   16          !5
         12      > JMPZ                                                     ~13, ->17
   28    13    >   FETCH_DIM_R                                      ~14     !0, !4
         14        ASSIGN_OP                                     8          !2, ~14
   29    15        ASSIGN                                                   !1, !5
   30    16      > JMP                                                      ->20
   25    17    >   PRE_INC                                                  !4
         18    >   IS_SMALLER                                               !4, !3
         19      > JMPNZ                                                    ~18, ->8
   24    20    >   IS_SMALLER                                               7, !1
         21      > JMPNZ                                                    ~19, ->6
   35    22    >   INIT_FCALL                                               'strrev'
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $20     
         25      > RETURN                                                   $20
   36    26*     > RETURN                                                   null

End of function unhash

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.54 ms | 1404 KiB | 21 Q