关于虾米音乐“凯撒方阵”解密算法请教
本帖最后由 autoit3CN 于 2017-5-8 10:58 编辑http://www.xiami.com/song/playlist/id/3589515
每次刷新该链接location的值都会变化,去除location的值第一个数字剩下的字符串用凯撒方阵解密后就是一个下载链接:
http://om6.alicdn.com/135/135/1675685427/3589515_10545365_h.mp3?auth_key=f2fd2ed0af29981a8ffa2473cd7fcf67-1494817200-0-null<playlist xmlns="http://xspf.org/ns/0/" version="1">
<trackList>
<track>
<songId>3589515</songId>
<songName>于心有愧</songName>
<subName/>
<albumId>322467</albumId>
<artistId>135</artistId>
<singers>陈奕迅</singers>
<mvId>66694</mvId>
<cdSerial>1</cdSerial>
<track>3</track>
<pinyin>yu xin you kui</pinyin>
<bakSongId>0</bakSongId>
<panFlag>0</panFlag>
<musicType>NORMAL</musicType>
<bakSong/>
<lyricInfo>Array</lyricInfo>
<songwriters>林夕</songwriters>
<composer>钟达茵</composer>
<arrangement>Gary Tong</arrangement>
<boughtCount>0</boughtCount>
<pace>135</pace>
<albumLanguage>粤语</albumLanguage>
<recommendCount>1374</recommendCount>
<collectCount>12676</collectCount>
<playCount>4189141</playCount>
<songStringId>bAYIda1c9e</songStringId>
<albumStringId>nWulf29ae</albumStringId>
<artistStringId>O9fc383</artistStringId>
<singerIds>Array</singerIds>
<demoCreateTime>1237737600000</demoCreateTime>
<artist>
<!]>
</artist>
<songOpt>NORMAL</songOpt>
<purviews>Array</purviews>
<publishStatus>PUBLISH</publishStatus>
<demo/>
<s>4189141</s>
<song_id>3589515</song_id>
<album_id>322467</album_id>
<name>于心有愧</name>
<title>
<!]>
</title>
<album_name>
<!]>
</album_name>
<sub_title/>
<song_sub_title/>
<artist_name>陈奕迅</artist_name>
<artist_id>135</artist_id>
<cd_serial>1</cd_serial>
<singersSource>Array</singersSource>
<length>238</length>
<recommends>1374</recommends>
<collects>12676</collects>
<key_words/>
<music_type>0</music_type>
<play_volume>89</play_volume>
<flag/>
<album_logo>images/album/img35/135/3224671375670448_1.jpg</album_logo>
<needpay>0</needpay>
<mvUrl>K66bRw</mvUrl>
<playstatus>1</playstatus>
<downloadstatus>1</downloadstatus>
<downloadjson>
%7B%22LOW%22%3A%22FREE%22%2C%22HIGH%22%3A%22FREE%22%7D
</downloadjson>
<can_show>1</can_show>
<can_check>1</can_check>
<location>
7h%md2F14513pt325a2615nt25nF1628%63hD358%-7EutF..1377955%_41eb512-lp%ac355%5E_3kac18E4%%l%2lo5%6215lFef68299553Fim%28F54.ayb86394EEAoc%2F53_5mu%8fed28%-
</location>
<lyric>
http://img.xiami.net/lyric/15/3589515_1418436385329_3170.lrc
</lyric>
<lyric_url>
http://img.xiami.net/lyric/15/3589515_1418436385329_3170.lrc
</lyric_url>
<object_id>3589515</object_id>
<object_name>default</object_name>
<insert_type>1</insert_type>
<background>http://img.xiami.net/res/player/bimg/bg-5.jpg</background>
<aritst_type/>
<artist_url>http://www.xiami.com/artist/135</artist_url>
<grade>-1</grade>
<tryhq>0</tryhq>
<pic>
http://img.xiami.net/images/album/img35/135/3224671375670448_1.jpg
</pic>
<album_pic>
http://img.xiami.net/images/album/img35/135/3224671375670448.jpg
</album_pic>
<rec_note/>
</track>
</trackList>
<uid>8926016</uid>
<lastSongId>0</lastSongId>
<type>default</type>
<type_id>1</type_id>
<clearlist/>
<vip>1</vip>
<vip_role>2</vip_role>
<hqset>1</hqset>
<message/>
</playlist>以下是一个大神的解密算法,可惜是php的,有熟悉php的换写为AU3代码吗?function get_location($str) {
try{
$a1=(int)$str{0};
$a2=substr($str, 1);
$a3=floor(strlen($a2) / $a1);
$a4=strlen($a2) % $a1;
$a5=array();
$a6=0;
$a7='';
for(;$a6 < $a4; ++$a6) {
$a5[$a6]=substr($a2, ($a3 + 1) * $a6, ($a3 + 1));
}
for(;$a6 < $a1; ++$a6) {
$a5[$a6]=substr($a2, $a3 * ($a6 - $a4) + ($a3 + 1) * $a4, $a3);
}
for($i=0, $a5_0_length=strlen($a5); $i < $a5_0_length; ++$i) {
for($j=0, $a5_length=count($a5); $j < $a5_length; ++$j) {
if (isset($a5[$j]{$i})) $a7.=$a5[$j]{$i};
}
}
$a7=str_replace('^', '0', urldecode($a7));
return $a7;
} catch(Exception $e) {
return false;
}
} 本帖最后由 afan 于 2017-5-8 15:06 编辑
没用过php,但貌似容易看懂,顺带引用以前写的一个函数$sCode = '7h%md2F14513pt325a2615nt25nF1628%63hD358%-7EutF..1377955%_41eb512-lp%ac355%5E_3kac18E4%%l%2lo5%6215lFef68299553Fim%28F54.ayb86394EEAoc%2F53_5mu%8fed28%-'
MsgBox(0, '', $sCode & @LF & '解码后:' & @LF & _Get_location($sCode))
Func _Get_location($str)
Local $iL = Int(StringLeft($str, 1))
Local $sData = StringMid($str, 1 + 1)
Local $iXh = Floor(StringLen($sData) / $iL)
Local $iMod = Mod(StringLen($sData), $iL)
Local $aL[$iL], $ixx = 0, $sOut = ''
While $ixx < $iMod
$aL[$ixx] = StringMid($sData, ($iXh + 1) * $ixx + 1, ($iXh + 1))
$ixx += 1
WEnd
While $ixx < $iL
$aL[$ixx]= StringMid($sData, $iXh * ($ixx - $iMod) + ($iXh + 1) * $iMod + 1, $iXh)
$ixx += 1
WEnd
Local $ii = 0, $aL0_len = StringLen($aL), $ss = ''
While $ii < $aL0_len
For $jj = 0 To UBound($aL) - 1
$ss = StringMid($aL[$jj], $ii + 1, 1)
if $ss <> '' Then $sOut &= $ss
Next
$ii += 1
WEnd
$sOut = _URLEncodeToString($sOut)
Return StringReplace($sOut, '^', '0')
EndFunc ;==>_Get_location
Func _URLEncodeToString($URL_str, $Encode = 1)
;afan 提示:转换经ANSI(GB2312)URL编码后的字符串为原始字符串
;$URL_str - URL编码字符串
;$Encode - URL编码格式 ;1 (默认) = ANSI ;2 = UTF16 小 ;3 = UTF16 大 ;4 = UTF8
;返回值:成功 - 返回编码字符串的原始字符串; 失败 - 返回原字符串并设置 @Error = 1
Local $Rstr, $aSR, $str_Tmp, $i
$Rstr = StringReplace($URL_str, '+', ' ')
$aSR = StringRegExp($Rstr, '(?:%\w{2})+', 3)
If @error Then Return SetError(1, 0, $Rstr)
For $i = 0 To UBound($aSR) - 1
$str_Tmp = BinaryToString('0x' & StringReplace($aSR[$i], '%', ''), $Encode)
$Rstr = StringReplace($Rstr, $aSR[$i], $str_Tmp, 1)
Next
Return $Rstr
EndFunc ;==>_URLEncodeToString 回复 2# afan
在公司看到了,到家的工夫,afan已经写好了。
#NoTrayIcon
#RequireAdmin
#PRE_UseX64=n
$sCode = '7h%md2F14513pt325a2615nt25nF1628%63hD358%-7EutF..1377955%_41eb512-lp%ac355%5E_3kac18E4%%l%2lo5%6215lFef68299553Fim%28F54.ayb86394EEAoc%2F53_5mu%8fed28%-'
MsgBox(0, '', $sCode & @LF & '解码后:' & @LF & _Get_location($sCode))
Func _Get_location($str)
Local $a1 = Int(StringLeft($str, 0 + 1))
Local $a2 = StringMid($str, 1 + 1);
Local $a3 = Floor(StringLen($a2) / $a1);
Local $a4 = Mod(StringLen($a2), $a1)
Local $a5[$a1];
Local $a6 = 0;
Local $a7 = '';
For $a6 = 0 To $a4 - 1
$a5[$a6] = StringMid($a2, (($a3 + 1) * $a6) + 1, ($a3 + 1));
Next
For $a6 = $a4 To $a1 - 1
$a5[$a6] = StringMid($a2, ($a3 * ($a6 - $a4) + ($a3 + 1) * $a4) + 1, $a3);
Next
Local $a5_0_length = StringLen($a5)
Local $a5_length = UBound($a5)
For $i = 0 To $a5_0_length - 1
For $j = 0 To $a5_length - 1
If StringMid($a5[$j], $i + 1, 1) <> '' Then $a7 &= StringMid($a5[$j], $i + 1, 1)
Next
Next
$a7 = StringReplace(_URLEncodeToString($a7), '^', '0');
Return $a7;
EndFunc ;==>_Get_location
Func _URLEncodeToString($URL_str, $Encode = 1)
;afan 提示:转换经ANSI(GB2312)URL编码后的字符串为原始字符串
;$URL_str - URL编码字符串
;$Encode - URL编码格式 ;1 (默认) = ANSI ;2 = UTF16 小 ;3 = UTF16 大 ;4 = UTF8
;返回值:成功 - 返回编码字符串的原始字符串; 失败 - 返回原字符串并设置 @Error = 1
Local $Rstr, $aSR, $str_Tmp, $i
$Rstr = StringReplace($URL_str, '+', ' ')
$aSR = StringRegExp($Rstr, '(?:%\w{2})+', 3)
If @error Then Return SetError(1, 0, $Rstr)
For $i = 0 To UBound($aSR) - 1
$str_Tmp = BinaryToString('0x' & StringReplace($aSR[$i], '%', ''), $Encode)
$Rstr = StringReplace($Rstr, $aSR[$i], $str_Tmp, 1)
Next
Return $Rstr
EndFunc ;==>_URLEncodeToString
谢谢上面两位大神帮忙,我不是伸手党,我也花了很多时间在这里,只是我的解题思路太烂了{:face (319):}#include <Array.au3>
;~ $L = 'h2.c5255%53ebfa%1%5tFao%F485_Fy858545Et%lm2129Ela%25bE9E-p2i%F6755.u33e894%n%Fc217%14mtD112985u3odF35255ph4c8321ElAmn156F_33_a66d67-l%5.3%8316%kf8e2-2%'
;~ $L = 'h2.c922E_23eEb72885utFao%F171_Fydf82f1Elt%lm21%21la%%4dfb7-lp2i%F6287.u357b1-2%%Fc238F42mtDE2%41%53odF8%2%1ph71e5a45EAmn395%583_%91E19E-%5.8%E5E5%k5a2864%n'
$L = 'hFl%3%%E2F%525145lt%i2855__a3EeE68Elt2cF9EE1luD11881-pFd3%271.t7922f7%%on82127mh%a72b253m.9F%82p_5b8f-%EA5c%12413kEfd115-%.o26F%8%ed4b44En2amF82553y%7%a9%u'
;~ $L = 'h2.c%5%2774ph245a11EltFao2E277613_a3E3d7-lt%lmF2F5484%k5afc-2%p2i%5%55%_43efee91%5%Fc2952%51_Fy2bd245E3odF3E32E6la%81c79E-Amn7477F74.u3612b4%n%5.7%79186mtDe%7a85u'
$LV = 9
;~ 即使今后虾米音乐更改相关的URL,获取下载地址的原理还是不会变的.并且只有在使用VIP帐号时的cookie访问http://www.xiami.com/song/gethqsong/sid/时才能获取到高音质的location,所以非VIP用户想要通过试听的途径获取到高音质音乐是不可能了(如果虾米不限制IP和Cookie下载的话).
$S = StringSplit($L, '')
$Link = ''
MsgBox(0,0,StringLen($L))
If StringLen($L) = 151 Then
;~ h2.c5255%53ebfa%1%5
;~ tFao%F485_Fy858545E
;~ t%lm2129Ela%25bE9E-
;~ p2i%F6755.u33e894%n
;~ %Fc217%14mtD112985u
;~ 3odF35255ph4c8321El
;~ Amn156F_33_a66d67-l
;~ %5.3%8316%kf8e2-2%
For $i = 1 To 18
$Link = $Link & $S[$i] & $S[$i + 19] & $S[$i + 38] & $S[$i + 57] & $S[$i + 76] & $S[$i + 95] & $S[$i + 114] & $S[$i + 133]
Next
$Link = $Link & '5E-null'
EndIf
If StringLen($L) = 155 Then
;~ h2.c922E_23eEb72885u
;~ tFao%F171_Fydf82f1El
;~ t%lm21%21la%%4dfb7-l
;~ p2i%F6287.u357b1-2%
;~ %Fc238F42mtDE2%41%5
;~ 3odF8%2%1ph71e5a45E
;~ Amn395%583_%91E19E-
;~ %5.8%E5E5%k5a2864%n
;~ MsgBox(0,0,$S)
;~ For $i = 1 To 19
;~ $Link = $Link & $S[$i] & $S[$i + 20] & $S[$i + 40] & $S[$i + 60] & $S[$i + 79] & $S[$i + 98] & $S[$i + 117] & $S[$i + 136]
;~ Next
;~ $Link = $Link & 'ull'
If $LV = 9 Then
For $i = 1 To 17
$Link = $Link & $S[$i] & $S[$i + 18] & $S[$i + 36] & $S[$i + 53] & $S[$i + 70] & $S[$i + 87] & $S[$i + 104] & $S[$i + 121]& $S[$i + 138]
Next
$Link = $Link & 'll'
EndIf
EndIf
MsgBox(0, '拼接链接', $Link)
$Link = StringReplace($Link, '%3A', ':')
$Link = StringReplace($Link, '%2F', '/')
$Link = StringReplace($Link, '%5E', '0')
$Link = StringReplace($Link, '%3F', '?')
$Link = StringReplace($Link, '%3D', '=')
MsgBox(0, '下载链接', $Link)
ConsoleWrite($Link)
ClipPut($Link)
回复 2# afan {"status":1,"info":"<div class="info-item"><img src="http:\/\/img.xiami.net\/images\/album\/img35\/135\/3224671375670448_1.jpg"><div><p>\u9648\u5955\u8fc5 - \u4e8e\u5fc3\u6709\u6127<\/p><strong>\u6807\u9898\uff1a<\/strong>\u4e8e\u5fc3\u6709\u6127<\/div><div><strong>\u827a\u4eba\uff1a<\/strong><a href="javascript:void(0);" onclick="setinput('xiami.com\/artist\/135')">\u9648\u5955\u8fc5<\/a><\/div><div><strong>\u4e13\u8f91\uff1a<\/strong><a href="javascript:void(0);" onclick="setinput('xiami.com\/album\/322467')">H\u00b3M<\/a><\/div><div><strong>\u6b4c\u8bcd\uff1a<\/strong><a href="?xmlyric=http:\/\/img.xiami.net\/lyric\/15\/3589515_1418436385329_3170.lrc&title=\u9648\u5955\u8fc5 - \u4e8e\u5fc3\u6709\u6127">\u9648\u5955\u8fc5 - \u4e8e\u5fc3\u6709\u6127.lrc(\u70b9\u51fb\u4e0b\u8f7d)<\/a><\/div><strong id="song">\u6b4c\u66f2\uff1a<\/strong><div id="case"><label id="case-label"><input id="src" readonly onmouseover="this.select()" value="http:\/\/om6.alicdn.com\/135\/135\/1675685427\/3589515_10545365_h.mp3?auth_key=bf34528326f783d656813501d06a3ffc-1494990000-0-null"><\/label><\/div><div class="close" title="\u5173\u95ed">\u00d7<\/div><\/div>","src":"http:\/\/om6.alicdn.com\/135\/135\/1675685427\/3589515_10545365_h.mp3?auth_key=bf34528326f783d656813501d06a3ffc-1494990000-0-null"}用http://tool.chinaz.com/tools/unicode.aspx的unicode转中文 转换成以下:{"status":1,"info":"<div class="info-item"><img src="http:\/\/img.xiami.net\/images\/album\/img35\/135\/3224671375670448_1.jpg"><div><p>陈奕迅 - 于心有愧<\/p><strong>标题:<\/strong>于心有愧<\/div><div><strong>艺人:<\/strong><a href="javascript:void(0);" onclick="setinput('xiami.com\/artist\/135')">陈奕迅<\/a><\/div><div><strong>专辑:<\/strong><a href="javascript:void(0);" onclick="setinput('xiami.com\/album\/322467')">H3M<\/a><\/div><div><strong>歌词:<\/strong><a href="?xmlyric=http:\/\/img.xiami.net\/lyric\/15\/3589515_1418436385329_3170.lrc&title=陈奕迅 - 于心有愧">陈奕迅 - 于心有愧.lrc(点击下载)<\/a><\/div><strong id="song">歌曲:<\/strong><div id="case"><label id="case-label"><input id="src" readonly onmouseover="this.select()" value="http:\/\/om6.alicdn.com\/135\/135\/1675685427\/3589515_10545365_h.mp3?auth_key=bf34528326f783d656813501d06a3ffc-1494990000-0-null"><\/label><\/div><div class="close" title="关闭">×<\/div><\/div>","src":"http:\/\/om6.alicdn.com\/135\/135\/1675685427\/3589515_10545365_h.mp3?auth_key=bf34528326f783d656813501d06a3ffc-1494990000-0-null"}请问版主,如何用au3如何转码(俺对算法一窍不通)?{:face (245):} $singer = Encode2Unicode(StringReplace($SongInfo, "\u", ";&#x") & ";")
Func Encode2Unicode($EncodedString, $qz = '&#x', $hz = ';')
;将 Unicode UTF 编码还原为字符 By afan
Local $Unicode, $i, $S2H, $Us
$S2H = StringRegExp($EncodedString, $qz & '(\w{4})' & $hz, 3)
If @error Then Return $EncodedString
For $i = 0 To UBound($S2H) - 1
$Us = ChrW(Dec($S2H[$i]))
$Unicode = StringReplace($EncodedString, $qz & $S2H[$i] & $hz, $Us, 1)
$EncodedString = $Unicode
Next
Return $Unicode
EndFunc ;==>Encode2Unicode尝试过这样,结果显示:{"status":1,"info":"<div class="info-item"><img src="http:\/\/img.xiami.net\/images\/album\/img35\/135\/3224671375670448_1.jpg"><div><p>;陈奕迅 - ;于心有愧<\/p><strong>;标题:<\/strong>;于心有愧<\/div><div><strong>;艺人:<\/strong><a href="javascript:void(0);" onclick="setinput('xiami.com\/artist\/135')">;陈奕迅<\/a><\/div><div><strong>;专辑:<\/strong><a href="javascript:void(0);" onclick="setinput('xiami.com\/album\/322467')">H;³M<\/a><\/div><div><strong>;歌词:<\/strong><a href="?xmlyric=http:\/\/img.xiami.net\/lyric\/15\/3589515_1418436385329_3170.lrc&title=;陈奕迅 - ;于心有愧">;陈奕迅 - ;于心有愧.lrc(;点击下载)<\/a><\/div><strong id="song">;歌曲:<\/strong><div id="case"><label id="case-label"><input id="src" readonly onmouseover="this.select()" value="http:\/\/om6.alicdn.com\/135\/135\/1675685427\/3589515_10545365_h.mp3?auth_key=bf34528326f783d656813501d06a3ffc-1494990000-0-null"><\/label><\/div><div class="close" title=";关闭">;×<\/div><\/div>","src":"http:\/\/om6.alicdn.com\/135\/135\/1675685427\/3589515_10545365_h.mp3?auth_key=bf34528326f783d656813501d06a3ffc-1494990000-0-null"};貌似中文部分有缺失 Local $sSource = ''
$sSource &= '{"status":1,"info":"<div class="info-item"><img src="http:\/\/img.xiami.net\/images\/album\/img35\/135\/3224671375670448_1.jpg"><div><p>\u9648\u5955\u8fc5 - \u4e8e\u5fc3\u6709\u6127<\/p><strong>\u6807\u9898\uff1a<\/strong>\u4e8e\u5fc3\u6709\u6127<\/div><div><strong>\u827a\u4eba\uff1a<\/strong><a href="javascript:void(0);" onclick="setinput(' & "'xiami.com\/artist\/135')">\u9648\u5955\u8fc5<\/a><\/div><div><strong>\u4e13\u8f91\uff1a<\/strong><a href="javascript:void(0);" onclick="setinput('xiami.com\/album\/322467')">H\u00b3M<\/a><\/div><div><strong>\u6b4c\u8bcd\uff1a<\/strong><a href="?xmlyric=http:\/\/img.xiami.net\/lyric\/15\/3589515_1418436385329_3170.lrc&title=\u9648\u5955\u8fc5 - \u4e8e\u5fc3\u6709\u6127">\u9648\u5955\u8fc5 - \u4e8e\u5fc3\u6709\u6127.lrc(\u70b9\u51fb\u4e0"
$sSource &= 'b\u8f7d)<\/a><\/div><strong id="song">\u6b4c\u66f2\uff1a<\/strong><div id="case"><label id="case-label"><input id="src" readonly onmouseover="this.select()" value="http:\/\/om6.alicdn.com\/135\/135\/1675685427\/3589515_10545365_h.mp3?auth_key=bf34528326f783d656813501d06a3ffc-1494990000-0-null"><\/label><\/div><div class="close" title="\u5173\u95ed">\u00d7<\/div><\/div>","src":"http:\/\/om6.alicdn.com\/135\/135\/1675685427\/3589515_10545365_h.mp3?auth_key=bf34528326f783d656813501d06a3ffc-1494990000-0-null"}'
MsgBox(0, '还原', _UnicodeEncodeToString($sSource, '\u', ''))
Func _UnicodeEncodeToString($sEncode, $sPrefix = '&#x', $sSuffix = ';')
;afan 提示:将 Unicode 编码还原为字符
;$sEncode - 编码字符串 ;$sPrefix - [可选]前缀字符 ;$sSuffix - [可选]后缀字符
Local $sUnicode, $ii, $sCW
Local $s_PrefixZY = StringReplace($sPrefix, '\', '\\')
Local $aEC = StringRegExp($sEncode, $s_PrefixZY & '(\w{4})' & $sSuffix, 3)
If @error Then Return $sEncode
For $ii = 0 To UBound($aEC) - 1
$sCW = ChrW(Dec($aEC[$ii]))
$sUnicode = StringReplace($sEncode, $sPrefix & $aEC[$ii] & $sSuffix, $sCW, 1)
$sEncode = $sUnicode
Next
$sUnicode = StringReplace($sUnicode, '<', '<')
$sUnicode = StringReplace($sUnicode, '>', '>')
$sUnicode = StringReplace($sUnicode, '"', '"')
Return $sUnicode
EndFunc ;==>_UnicodeEncodeToString 回复 7# afan
终于解决我的问题了,学无止境学以致用,非常感谢afan版主!{:face (427):}
页:
[1]