Created
December 13, 2011 13:50
-
-
Save keiya/1472183 to your computer and use it in GitHub Desktop.
謎のコンテンツ難読化(コンテンツをEPOCH Timeとメルセンヌツイスターで生成したランダムな値でXORにし、JSON Arrayでクライアントへ渡します)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $str = urlencode('僕は友達が少ない(驚愕)'); | |
| $rand = mt_rand(0,floor(time()/100)); | |
| $seed = floor(time()/100)+$rand; | |
| $char=array($rand); | |
| for($i=0;$i<mb_strlen($str,'utf-8');$i++){ | |
| $hex = bin2hex(mb_substr($str , $i, 1, 'utf-8')); | |
| $char[] = intval($hex,16)^$seed; | |
| } | |
| $json = json_encode($char); | |
| ?> | |
| <body> | |
| ###SERVER SIDE###<br /> | |
| <?php echo "Seed: $seed<br /><br />Encrypted JSON: $json"?> | |
| <script> | |
| var json = '<?php echo $json ?>'; | |
| var a=JSON.parse(json); | |
| var s=Math.floor(parseInt(new Date/100000))+a[0]; | |
| var r=''; | |
| for (i in a) { | |
| if (i==0) continue; | |
| r += String.fromCharCode(a[i]^s); | |
| } | |
| r=decodeURI(r); | |
| alert('###Client Side###\nSeed: '+s+'\nDecoded: '+r); | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment