百度图片搜索url百度图片加密url解码

2015年07月02日 03:43 by:hbuxiaoshe

抓取百度图片搜索的时候发现百度大部分图片是加密的,百度了一番找到了网友分享的内容:

从百度中抓取图片的时候百度对图片地址是加密的,如ippr_z2C$qAzdH3FAzddadsdsaaastfpAzdH3Fda8candnAzdH3FWada8candnn98c9lndadl9_z&e3B3r2。

解密方法很简单,秘钥是一个字符的对应关系,有2种映射:

(1)多个字符映射为一个字符,'_z2C$q'=>':','_z&e3B'=>'.','AzdH3F'=>'/'

(2)单个字符映射为单字符。根据这个关系可将密文解密为明文,实现并不困难。

php解析百度图片url串

  1. <?PHP
  2. $f = array('w'=>'a','k'=>'b','v'=>'c','1'=>'d','j'=>'e','u'=>'f','2'=>'g','i'=>'h','t'=>'i','3'=>'j','h'=>'k','s'=>'l','4'=>'m','g'=>'n','5'=>'o','r'=>'p','q'=>'q','6'=>'r','f'=>'s','p'=>'t','7'=>'u','e'=>'v','o'=>'w','8'=>'1','d'=>'2','n'=>'3','9'=>'4','c'=>'5','m'=>'6','0'=>'7','b'=>'8','l'=>'9','a'=>'0','_z2C$q'=>':','_z&e3B'=>'.','AzdH3F'=>'/');
  3.  
  4. $url = 'ippr_z2C$qAzdH3FAzdH3Ft4f_z&e3Bw6ptg2nmc_z&e3Bv54AzdH3Fg51jAzdH3F8da90bAzdH3F'; // 这里需要用单引号

  5. $url = preg_replace_callback('/_z2C$q|_z&e3B|AzdH3F/', function($matches){ global $f; return $f[$matches[0]]; }, $url); 
  6. $url = preg_replace_callback('/[a-wd]/', function($matches){ global $f; return $f[$matches[0]]; }, $url); 
  7. echo $url;
  8. ?>

javascript解密百度图片url:

  1. <script type="text/javascript">
  2.   var f = {   w: "a",   k: "b",   v: "c",   1: "d",   j: "e",   u: "f",   2: "g",   i: "h",   t: "i",   3: "j",   h: "k",   s: "l",   4: "m",   g: "n",   5: "o",   r: "p",   q: "q",   6: "r",   f: "s",   p: "t",   7: "u",   e: "v",   o: "w",   8: "1",   d: "2",   n: "3",   9: "4",   c: "5",   m: "6",   0: "7",   b: "8",   l: "9",   a: "0",   _z2C$q: ":",   "_z&e3B": ".",   AzdH3F: "/"   };
  3.   var url = "ippr_z2C$qAzdH3FAzdH3Fjgp_z&e3Bvg6_z&e3BvgAzdH3FstfpAzdH3Fda8candnAzdH3FWada8candnn98c9lndadl9_z&e3B3r2";
  4.   var h = /(_z2C$q|_z&e3B|AzdH3F)/g;
  5.   var e = url.replace(h, function(t, e) { return f[e] });  
  6.   var s = /([a-wd])/g;
  7.   e = e.replace(s, function(t, e) { return f[e] });
  8.   document.write(e);
  9. </script>

C语言解密百度加密的url

  1. #include <stdio.h>
  2. #include <string.h>


  3. // return length;
  4. int Decode(const char *src, const char *table, char *dest) {
  5.   char *d = dest;
  6.   const char *p = src;
  7.   while (*p != 0) {
  8.     if (*p == '_') {
  9.       if (strncmp(p, "_z2C$q", 6) == 0) {
  10.         *dest++ = ':';
  11.         p += 6;
  12.       } else if (strncmp(p, "_z&e3B", 6) == 0) {
  13.         *dest++ = '.';
  14.         p += 6;
  15.       } else {
  16.         *dest++ = *p++;
  17.       }
  18.     } else if (*p == 'A') {
  19.       if (strncmp(p, "AzdH3F", 6) == 0) {
  20.         *dest++ = '/';
  21.         p += 6;
  22.       } else {
  23.         *dest++ = *p++;
  24.       }
  25.     } else if (table[*p] == 0) {
  26.       *dest++ = *p++;
  27.     } else {
  28.       *dest++ = table[*p++];
  29.     }
  30.   }
  31.   *dest = 0;
  32.   return dest - d;
  33. }


  34. int main(int argc, char **argv) {
  35.   static char table[128] = {0};
  36.   table['w'] = 'a';
  37.   table['k'] = 'b';
  38.   table['v'] = 'c';
  39.   table['1'] = 'd';
  40.   table['j'] = 'e';
  41.   table['u'] = 'f';
  42.   table['2'] = 'g';
  43.   table['i'] = 'h';
  44.   table['t'] = 'i';
  45.   table['3'] = 'j';
  46.   table['h'] = 'k';
  47.   table['s'] = 'l';
  48.   table['4'] = 'm';
  49.   table['g'] = 'n';
  50.   table['5'] = 'o';
  51.   table['r'] = 'p';
  52.   table['q'] = 'q';
  53.   table['6'] = 'r';
  54.   table['f'] = 's';
  55.   table['p'] = 't';
  56.   table['7'] = 'u';
  57.   table['e'] = 'v';
  58.   table['o'] = 'w';
  59.   table['8'] = '1';
  60.   table['d'] = '2';
  61.   table['n'] = '3';
  62.   table['9'] = '4';
  63.   table['c'] = '5';
  64.   table['m'] = '6';
  65.   table['0'] = '7';
  66.   table['b'] = '8';
  67.   table['l'] = '9';
  68.   table['a'] = '0';


  69.   char *url = "ippr_z2C$qAzdH3FAzdH3Ft428_z&e3Bd0_z&e3BvgAzdH3Ft4w2jfAzdH3Fda8a8aAzdH3FddAzdH3F8db00d0dnd_9amln8aa_z&e3B3r2";
  70.   char dest[1024];
  71.   Decode(url, table, dest);
  72.   printf("%sn", dest);
  73.   return 0;
  74. }

标签:百度 url解密