# 某些CTF密码算法的PHP解法

jopen 5年前

`<code id="code0"><?php          echo encrypt('mi.txt', 'asadsasdasdasdasdasdasdasdasdasdqwesqf');                function encrypt(\$source, \$key){                  if(file_exists(\$source)){                          \$content = '';                          \$keylen = strlen(\$key);                          \$index = 0;                         \$fp = fopen(\$source, 'rb');                         while(!feof(\$fp)){                                 \$tmp = fread(\$fp, 1);                                 \$content .= \$tmp ^ substr(\$key,\$index%\$keylen,1);                                 \$index++;                         }                         fclose(\$fp);                         return \$content;                      }else{                          return false;                  }          }                ?></code>`

`01    <?php      02    \$a='98554799767';      03    \$a=floatval(\$a);      04      05    for((float)\$i=2;\$i<(float)\$a;\$i++){      06            \$num=fmod(\$a,\$i);      07            if(\$num==0){      08                    echo \$i."\n";      09                    break;      10            }      11    }      12    \$j=\$a/\$i;      13    echo \$j."\n";      14    echo md5(\$i.\$j);      15    ?>`

`01    <?php      02    \$str='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';      03    \$cou=strlen(\$str);      04    for(\$i=0;\$i<\$cou-1;\$i++){      05            for(\$j=0;\$j<\$cou-1;\$j++){      06                    for(\$k=0;\$k<\$cou-1;\$k++){      07                            for(\$l=0;\$l<\$cou-1;\$l++){      08                                    \$ret=md5(\$str[\$i].\$str[\$j].\$str[\$k].\$str[\$l]);      09                                    if(substr(\$ret,0,10)=='c2979c7124'){      10                                            echo \$ret;die();      11                                    }      12                            }      13                    }      14            }      15    }      16    ？>`