3v4l.org

run code in 300+ PHP versions simultaneously
<?php // https://trello.com/jobs/windows-mobile-developer $alphabet = 'acdegilmnoprstuw'; // test data $hash = 680131659347; $string = 'leepadg'; $task_hash = 696005871397; 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)) , PHP_EOL , sprintf('Solution for hash «%s» is «%s».', $task_hash, unhash($alphabet, $task_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/QMfO9
function name:  (null)
number of ops:  37
compiled vars:  !0 = $alphabet, !1 = $hash, !2 = $string, !3 = $task_hash
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 'acdegilmnoprstuw'
    7     1        ASSIGN                                                   !1, 680131659347
    8     2        ASSIGN                                                   !2, 'leepadg'
    9     3        ASSIGN                                                   !3, 696005871397
   11     4        INIT_FCALL                                               'sprintf'
          5        SEND_VAL                                                 'Hash+of+string+%C2%AB%25s%C2%BB+is+%C2%AB%25s%C2%BB.'
          6        SEND_VAR                                                 !2
          7        INIT_FCALL_BY_NAME                                       'get_hash'
          8        SEND_VAR_EX                                              !0
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0  $8      
         11        SEND_VAR                                                 $8
         12        DO_ICALL                                         $9      
         13        ECHO                                                     $9
   12    14        ECHO                                                     '%0A'
   13    15        INIT_FCALL                                               'sprintf'
         16        SEND_VAL                                                 'String+of+hash+%C2%AB%25s%C2%BB+is+%C2%AB%25s%C2%BB.'
         17        SEND_VAR                                                 !1
         18        INIT_FCALL_BY_NAME                                       'unhash'
         19        SEND_VAR_EX                                              !0
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0  $10     
         22        SEND_VAR                                                 $10
         23        DO_ICALL                                         $11     
         24        ECHO                                                     $11
   14    25        ECHO                                                     '%0A'
   15    26        INIT_FCALL                                               'sprintf'
         27        SEND_VAL                                                 'Solution+for+hash+%C2%AB%25s%C2%BB+is+%C2%AB%25s%C2%BB.'
         28        SEND_VAR                                                 !3
         29        INIT_FCALL_BY_NAME                                       'unhash'
         30        SEND_VAR_EX                                              !0
         31        SEND_VAR_EX                                              !3
         32        DO_FCALL                                      0  $12     
         33        SEND_VAR                                                 $12
         34        DO_ICALL                                         $13     
         35        ECHO                                                     $13
   43    36      > 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/QMfO9
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
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        ASSIGN                                                   !2, 7
   20     3        STRLEN                                           ~6      !1
          4        ASSIGN                                                   !3, ~6
   21     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->16
   22     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
   21    15        PRE_INC                                                  !4
         16    >   IS_SMALLER                                               !4, !3
         17      > JMPNZ                                                    ~15, ->7
   25    18    > > RETURN                                                   !2
   26    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/QMfO9
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
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   29     2        ASSIGN                                                   !2, ''
   30     3        STRLEN                                           ~7      !0
          4        ASSIGN                                                   !3, ~7
   31     5      > JMP                                                      ->20
   32     6    >   ASSIGN                                                   !4, 0
          7      > JMP                                                      ->18
   33     8    >   SUB                                              ~10     !1, !4
          9        DIV                                              ~11     ~10, 37
         10        ASSIGN                                                   !5, ~11
   34    11        TYPE_CHECK                                   16          !5
         12      > JMPZ                                                     ~13, ->17
   35    13    >   FETCH_DIM_R                                      ~14     !0, !4
         14        ASSIGN_OP                                     8          !2, ~14
   36    15        ASSIGN                                                   !1, !5
   37    16      > JMP                                                      ->20
   32    17    >   PRE_INC                                                  !4
         18    >   IS_SMALLER                                               !4, !3
         19      > JMPNZ                                                    ~18, ->8
   31    20    >   IS_SMALLER                                               7, !1
         21      > JMPNZ                                                    ~19, ->6
   42    22    >   INIT_FCALL                                               'strrev'
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $20     
         25      > RETURN                                                   $20
   43    26*     > RETURN                                                   null

End of function unhash

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.06 ms | 1396 KiB | 19 Q