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($letters); while ($res > 7) { for ($i = 0; $i < $len; $i++) { $newres = ($res - $i) / 37; if (is_int($newres)) { $result .= $letters[$i]; $res = $newres; break; } } return strrev($result); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hbl18
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
   38    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/Hbl18
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
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        ASSIGN                                                   !2, 7
   16     3        STRLEN                                           ~6      !1
          4        ASSIGN                                                   !3, ~6
   17     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->16
   18     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
   17    15        PRE_INC                                                  !4
         16    >   IS_SMALLER                                               !4, !3
         17      > JMPNZ                                                    ~15, ->7
   20    18    > > RETURN                                                   !2
   21    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 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 6
Branch analysis from position: 26
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
1 jumps found. (Code = 62) Position 1 = -2
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/Hbl18
function name:  unhash
number of ops:  27
compiled vars:  !0 = $alphabet, !1 = $hash, !2 = $result, !3 = $len, !4 = $letters, !5 = $i, !6 = $newres, !7 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   24     2        ASSIGN                                                   !2, ''
   25     3        STRLEN                                           ~9      !4
          4        ASSIGN                                                   !3, ~9
   26     5      > JMP                                                      ->24
   27     6    >   ASSIGN                                                   !5, 0
          7      > JMP                                                      ->18
   28     8    >   SUB                                              ~12     !7, !5
          9        DIV                                              ~13     ~12, 37
         10        ASSIGN                                                   !6, ~13
   29    11        TYPE_CHECK                                   16          !6
         12      > JMPZ                                                     ~15, ->17
   30    13    >   FETCH_DIM_R                                      ~16     !4, !5
         14        ASSIGN_OP                                     8          !2, ~16
   31    15        ASSIGN                                                   !7, !6
   32    16      > JMP                                                      ->20
   27    17    >   PRE_INC                                                  !5
         18    >   IS_SMALLER                                               !5, !3
         19      > JMPNZ                                                    ~20, ->8
   36    20    >   INIT_FCALL                                               'strrev'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                         $21     
         23      > RETURN                                                   $21
   26    24    >   IS_SMALLER                                               7, !7
         25      > JMPNZ                                                    ~22, ->6
   38    26    > > RETURN                                                   null

End of function unhash

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.39 ms | 1404 KiB | 21 Q