3v4l.org

run code in 300+ PHP versions simultaneously
<?php function score_xor($line) { $score_arr = array(); $char_scores_arr = array( "a" => 9, "b" => 1, "c" => 3, "d" => 4, "e" => 13, "f" => 2, "h" => 6, "i" => 7, "j" => 0, "k" => 1, "l" => 4, "m" => 2, "n" => 7, "o" => 8, "p" => 2, "q" => 0, "r" => 6, "s" => 6, "t" => 9, "u" => 3, "v" => 1, "w" => 2, "x" => 0, "y" => 2, "z" => 0 ); #$input = pack("H*", "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"); $input = pack("H*", $line); for ($i = 0; $i < 128; $i++) { $ciphertext = array(); $score = 0; for ($j = 0; $j < strlen($input); $j++) { $to_add = chr(ord($input[$j]) ^ $i); array_push($ciphertext, $to_add); if (array_key_exists(strtolower($to_add), $char_scores_arr)) $score += $char_scores_arr[strtolower($to_add)] + ord($to_add); } $ciphertext = implode("", $ciphertext); $score_arr[$ciphertext] = $score; } arsort($score_arr); $count = 5; $ret = array(); foreach ($score_arr as $ciphertext => $score) { if ($count--) array_push($ret, "Text: $ciphertext\n\tScore: $score\n"); else break; } return $ret; } $txt = file_get_contents("http://cryptopals.com/static/challenge-data/4.txt"); $lines = explode("\n", $txt); $results = array(); foreach ($lines as $line) { array_push($results, score_xor($line)); } var_dump($results); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/HQ54M
function name:  (null)
number of ops:  25
compiled vars:  !0 = $txt, !1 = $lines, !2 = $results, !3 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   INIT_FCALL                                               'file_get_contents'
          1        SEND_VAL                                                 'http%3A%2F%2Fcryptopals.com%2Fstatic%2Fchallenge-data%2F4.txt'
          2        DO_ICALL                                         $4      
          3        ASSIGN                                                   !0, $4
   64     4        INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%0A'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !1, $6
   65     9        ASSIGN                                                   !2, <array>
   67    10      > FE_RESET_R                                       $9      !1, ->20
         11    > > FE_FETCH_R                                               $9, !3, ->20
   68    12    >   INIT_FCALL                                               'array_push'
         13        SEND_REF                                                 !2
         14        INIT_FCALL                                               'score_xor'
         15        SEND_VAR                                                 !3
         16        DO_FCALL                                      0  $10     
         17        SEND_VAR                                                 $10
         18        DO_ICALL                                                 
   67    19      > JMP                                                      ->11
         20    >   FE_FREE                                                  $9
   71    21        INIT_FCALL                                               'var_dump'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                                 
   72    24      > RETURN                                                   1

Function score_xor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 10
Branch analysis from position: 55
2 jumps found. (Code = 77) Position 1 = 61, Position 2 = 77
Branch analysis from position: 61
2 jumps found. (Code = 78) Position 1 = 62, Position 2 = 77
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 75
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
Branch analysis from position: 77
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 14
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 10
Branch analysis from position: 55
Branch analysis from position: 10
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 41
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 14
Branch analysis from position: 45
Branch analysis from position: 14
Branch analysis from position: 41
filename:       /in/HQ54M
function name:  score_xor
number of ops:  80
compiled vars:  !0 = $line, !1 = $score_arr, !2 = $char_scores_arr, !3 = $input, !4 = $i, !5 = $ciphertext, !6 = $score, !7 = $j, !8 = $to_add, !9 = $count, !10 = $ret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    4     2        ASSIGN                                                   !2, <array>
   33     3        INIT_FCALL                                               'pack'
          4        SEND_VAL                                                 'H%2A'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $13     
          7        ASSIGN                                                   !3, $13
   35     8        ASSIGN                                                   !4, 0
          9      > JMP                                                      ->53
   36    10    >   ASSIGN                                                   !5, <array>
   37    11        ASSIGN                                                   !6, 0
   39    12        ASSIGN                                                   !7, 0
         13      > JMP                                                      ->42
   40    14    >   INIT_FCALL                                               'chr'
         15        INIT_FCALL                                               'ord'
         16        FETCH_DIM_R                                      ~19     !3, !7
         17        SEND_VAL                                                 ~19
         18        DO_ICALL                                         $20     
         19        BW_XOR                                           ~21     !4, $20
         20        SEND_VAL                                                 ~21
         21        DO_ICALL                                         $22     
         22        ASSIGN                                                   !8, $22
   41    23        INIT_FCALL                                               'array_push'
         24        SEND_REF                                                 !5
         25        SEND_VAR                                                 !8
         26        DO_ICALL                                                 
   42    27        INIT_FCALL                                               'strtolower'
         28        SEND_VAR                                                 !8
         29        DO_ICALL                                         $25     
         30        ARRAY_KEY_EXISTS                                         $25, !2
         31      > JMPZ                                                     ~26, ->41
   43    32    >   INIT_FCALL                                               'strtolower'
         33        SEND_VAR                                                 !8
         34        DO_ICALL                                         $27     
         35        FETCH_DIM_R                                      ~28     !2, $27
         36        INIT_FCALL                                               'ord'
         37        SEND_VAR                                                 !8
         38        DO_ICALL                                         $29     
         39        ADD                                              ~30     ~28, $29
         40        ASSIGN_OP                                     1          !6, ~30
   39    41    >   PRE_INC                                                  !7
         42    >   STRLEN                                           ~33     !3
         43        IS_SMALLER                                               !7, ~33
         44      > JMPNZ                                                    ~34, ->14
   45    45    >   INIT_FCALL                                               'implode'
         46        SEND_VAL                                                 ''
         47        SEND_VAR                                                 !5
         48        DO_ICALL                                         $35     
         49        ASSIGN                                                   !5, $35
   46    50        ASSIGN_DIM                                               !1, !5
         51        OP_DATA                                                  !6
   35    52        PRE_INC                                                  !4
         53    >   IS_SMALLER                                               !4, 128
         54      > JMPNZ                                                    ~39, ->10
   49    55    >   INIT_FCALL                                               'arsort'
         56        SEND_REF                                                 !1
         57        DO_ICALL                                                 
   50    58        ASSIGN                                                   !9, 5
   51    59        ASSIGN                                                   !10, <array>
   53    60      > FE_RESET_R                                       $43     !1, ->77
         61    > > FE_FETCH_R                                       ~44     $43, !6, ->77
         62    >   ASSIGN                                                   !5, ~44
   54    63        POST_DEC                                         ~46     !9
         64      > JMPZ                                                     ~46, ->75
   55    65    >   INIT_FCALL                                               'array_push'
         66        SEND_REF                                                 !10
         67        ROPE_INIT                                     5  ~48     'Text%3A+'
         68        ROPE_ADD                                      1  ~48     ~48, !5
         69        ROPE_ADD                                      2  ~48     ~48, '%0A%09Score%3A+'
         70        ROPE_ADD                                      3  ~48     ~48, !6
         71        ROPE_END                                      4  ~47     ~48, '%0A'
         72        SEND_VAL                                                 ~47
         73        DO_ICALL                                                 
         74      > JMP                                                      ->76
   57    75    > > JMP                                                      ->77
   53    76    > > JMP                                                      ->61
         77    >   FE_FREE                                                  $43
   60    78      > RETURN                                                   !10
   61    79*     > RETURN                                                   null

End of function score_xor

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
189.35 ms | 1398 KiB | 34 Q