☠️†卍️ 兵庫県警に補導される難解スクリプト️ ️卍†☠️

# スクリプト

※以下を実行すると無限アラートになります。

見えづらかったので、文字を小さくしたスクショを追記↓
<img width="1792" alt="Screen Shot 2019-03-07 at 12.59.49.png" src="https://qiita-image-store.s3.amazonaws.com/0/91558/c81fce44-9f3c-8d88-bab1-42eba0332ea6.png">


```script.js
                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                        [][                            
                                                                                                  (![]                                                                        +[]                                                     )[+[]]+(                         
                                                                                                 [![]]+                                                                       [][[                                                   ]])[+!+[]                         
                                                                                                +[+[]]]+                                                                     (![]+[]                                                 )[!+[]+!+[                        
                                                                                                ]]+(!![]+                                                                   [])[+[]]+                                                (!![]+[])[                        
                                                                                                !+[]+!+[]                                                                   +!+[]]+(!                                                ![]+[])[+!                        
                                                                                                +[]]][([                                                                   ][(![]+[])                                                 [+[]]+([!                        
                                                                                                []]+[][[                                                                   ]])[+!+[]+[                                                +[]]]+(![                        
                                                                                                ]+[])[!+                                                                  []+!+[]]+(!!                                                []+[])[+[                        
                                          ]]+(!![]+[])[!+                                       []+!+[]+                                                                 !+[]]+(!![]+                                                 [])[+!+[]                        
      ]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]                                      +[][[]])                                                                [+!+[]+[+[]]                                                   ]+(![]+[                        
     ])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]                                      ]+(!![]+                                                                [])[+!+[]]]                                                    )[+!+[]+                        
     [+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!!                                     []+[])[+                                                               []]+(!![]+[]                                                    )[+!+[]]+                       
     ([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]                                    +[+[]]]+                                                              (![]+[])[!+[                                                     ]+!+[]]+(                       
     !![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]                                    ]]+[])[!                                                              +[]+!+[]+!+                                                      []]+(!![]+                      
     [])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+                                    []]]+(![                                                             ]+[])[!+[]+                                                       !+[]]+(!![]     +[])[+[]]+      
     (!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]                                   ]+(!![]+                                                            [])[+!+[]]](                                                       (+(!+[]+!+[]+!+[]+[!+[]+!+      
     []]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[                                   ]])[+!+[]                                                           +[+[]]]+(![]                                                        +[])[!+[]+!+[]]+(!![]+[])[+     
     []]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]                                   +[+[]]]+(+!                                                         []+([]+[])[(                                       [][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+     
     (![]+[])[!+[]+!+[]]+(!![]+[])[+[]]     +(!![]+[])[!+[                ]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(                                   !![]+[][(![]                                       +[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])     
     [!+[]+!+[]]+(!![]+[])[+[]]+(!!         []+[])[!+[]+!+               []+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+                                  !+[]]+(![]+[                                       ])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!     
                            +[]]+([         ][[]]+[])[+[]               ]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])                                [!+[]+!+[]]+                                        (!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]     
                            +[])[+!         +[]]]+[])[!+                []+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![                               ]]+[][[]])[+                                         !+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]     
                            +(!![]+        [])[!+[]+!+[                 ]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]                              ])[+!+[]+[+[                                           ]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[]     
                            [[]])[+!      +[]+[+[]]]+([                 ][[]]+[])[+!+[]]+(+![]+[![]]+([]+[])[([][(![]+[])[+[]]+(                             [![]]+[][[]]                                            )[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]          
                           +[])[+[]]     +(!![]+[])[!+                  []+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![                            ]+[][(![]+[]                                             )[+[]]+([![]]+[][[]])[+!+[]+[+[]]]                
                           +(![]+[])     [!+[]+!+[]]+                   (!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]                            ]])[+!+[]+[+                                              []]]+([][[]]+[])[+!+[]]+(![]+[])                 
                           [!+[]+!+[]   +!+[]]+(!![]                    +[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])                           [+[]]+([![]]                                                                    +[][[]])[+!                 
                           +[]+[+[]]]  +(![]+[])[!+                     []+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+                          [])[+!+[]]]+                                                                      [])[!+[]+!                 
                           +[]+!+[]]+(!![]+[])[+[]]                      +(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(!                          []+[])[!+[]+                                                                        !+[]]+(!!                 
                           []+[])[+[]]+(!![]+[])[!                                            +[]+!+[]+!+                                               []]+(!![]+[]                                                                         )[+!+[]]])                
                           [+!+[]+[+[]]]+(!![]+[]                                              )[+!+[]]]                                                )[!+[]+!+[]                                                                          +[+[]]]](!+               
                           []+!+[]+!+[]+[!+[]+!+                                                []+!+[]]                                               )+(+(+!+[]+[                                                                           +[]]+[+!+[               
                           ]]))[(!![]+[])[+[]]+(                                                !![]+[][                                              (![]+[])[+[]                                                                             ]+([![]]+[              
                           ][[]])[+!+[]+[+[]]]                                    +(!           []+[])[!          +[]                                 +!+[]]+(!![                                                                              ]+[])[+[]]+             
                           (!![]+[])[!+[]+!+[]                                    +!+[          ]]+(!![]         +[])[                                +!+[]]])[+                                                                               !+[]+[+[]]]             
                           +(+![]+([]+[])[([]                                    [(![]+[        ])[+[]]+        ([![]]+                              [][[]])[+!                                                                                 +[]+[+[]]]+            
                           (![]+[])[!+[]+!+[                                     ]]+(!![]+      [])[+[]]       +(!![]+[                              ])[!+[]+!+                                                                                 []+!+[]]+(!!           
                           []+[])[+!+[]]]+[                                     ])[!+[]+!+      []+!+[]]       +(!![]+[]                             [(![]+[])[                                                                                 +[]]+([![]]+[          
                           ][[]])[+!+[]+[+                                      []]]+(![]+      [])[!+[]      +!+[]]+(!![                             ]+[])[+[]]                                                                  +(!![]+[])[!+[]+!+[]+!+[]]+(         
                           !![]+[])[+ !+[                                       ]]])[+!+[]      +[+[]]]+      ([][[]]+[])                             [+!+[]]+(!                                                               []+[])[!+[]+!+[]+!+[]]+(!![]+[])        
                           [+[]]+(!![                                          ]+[])[+!+[]      ]+([][[]      ]+[])[+[]]+(                            [][(![]+[])                                                             [+[]]+([![]]+[][[]])[+!+[]+[+[]]]+       
                           (![]+[])[                                           !+[]+!+[]]       +(!![]+[      ])[+[]]+(!![]                           +[])[!+[]+!+                                                          []+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!      
                           +[]+!+[]]                                          +(!![]+[])[       +[]]+(!!       []+[][(![]+[                            ])[+[]]+([![                                                        ]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!     
                           +[]]+(!![                                          ]+[])[+[]]        +(!![]+[        ])[!+[]+!+[]                            +!+[]]+(!![]                                                      +[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+     
                           []]])[+!+                                         []+[+[]]]+         (!![]+[]         )[+[]]+(!![]                           +[])[+!+[]]+(                                                    [![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+    
                          []]+(+![]                                          +[![]]+([]         +[])[([]         [(![]+[])[+[                            ]]+([![]]+[][                                                   []])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![    
                          ]+[])[+[]                                          ]+(!![]+[]         )[!+[]+!          +[]+!+[]]+(!                            ![]+[])[+!+[]                                                 ]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+     
                          []]+([![]                                         ]+[][[]])[+         !+[]+[+[           ]]]+(![]+[])                            [!+[]+!+[]]+(                                               !![]+[])[+[]]               +(!![]+[])[!+[]     
                          +!+[]+!+                                         []]+(!![]+[          ])[+!+[]           ]])[+!+[]+[+                             []]]+([][[]]+                                              [])[+!+[]]+                    (![]+[])[!+      
                         []+!+[]+!                                         +[]]+(!![]           +[])[+[]            ]+(!![]+[])[                             +!+[]]+([][[]                                             ]+[])[+[]]                       +([][(![       
                        ]+[])[+[]]                                         +([![]]+[]           [[]])[+!             +[]+[+[]]]+                              (![]+[])[!+[]                                            +!+[]]+(!                           ![]+        
                        [])[+[]]+(                                        !![]+[])[!+           []+!+[]+             !+[]]+(!![]+                              [])[+!+[]]]+[                                           ])[!+[]+                                        
                        !+[]+!+[]                                         ]+(!![]+[]            )[+[]]+(              !![]+[][(![                              ]+[])[+[]]+([!                                          []]+[][[                                        
                       ]])[+!+[]+                                        [+[]]]+(![]            +[])[!+[              ]+!+[]]+(!![                               ]+[])[+[]]+(!                                         ![]+[])                                         
                      [!+[]+!+[]+                                        !+[]]+(!![             ]+[])[+!               +[]]])[+!+[                               ]+[+[]]]+(!![                                         ]+[])[+                                         
                      !+[]]])[!+                                        []+!+[]+[+[             ]]]](!+[               ]+!+[]+[+!+                                []])[+!+[]]+(                                        [![]]+[                                         
                     ][[]])[+!+[                                        ]+[+[]]]+(              ![]+[])[                !+[]+!+[]]                                 +(!![]+[])[!+                                       []+!+[]+                                        
                    !+[]]+(![]+                                        [][(![]+[])              [+[]]+([                 ![]]+[][[                                  ]])[+!+[]+[+[                                      ]]]+(![]                                        
                   +[])[!+[]+!+                                        []]+(!![]+               [])[+[]]                 +(!![]+[]                                   )[!+[]+!+[]+!                                     +[]]+(!![                                       
                  ]+[])[+!+[]]                                          ])[!+[]+!               +[]+[+[]                  ]]+[+!                                      +[]]+(!![]+[]                                    [(![]+[])[                                      
                 +[]]+([![]]+[                                           ][[]])[                +!+[]+[+                  []]]+                                        (![]+[])[!+[                                    ]+!+[]]+(!!                                     
                []+[])[+[]]+(                                             !![]+[                ])[!+[]+                   !+[                                         ]+!+[]]+(!![]                                    +[])[+!+[]]                                    
               ])[!+[]+!+[]+                                                [+[                 ]]]+(![]                                                                +[])[+!+[]]+(                                   ![]+[])[!+[]+!+[]]                             
              +(!![]+[])[!+[                                                                    ]+!+[]+!                                                                 +[]]+(!![]+[                                    ])[+!+[]]+(!![]+[])[+[]]+(![]+[][             
             (![]+[])[+[]]+                                                                     ([![]]+[                                                                 ][[]])[+!+[]+                                   [+[]]]+(![]+[])[!+[]+!+[]]+(!![]+             
             [])[+[]]+(!![                                                                      ]+[])[!+                                                                   []+!+[]+!+[]                                   ]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+            
            []]]+(!![]+[]                                                                       [(![]+[]                                                                   )[+[]]+([![]                                    ]+[][[]])[+!+[]+[+[]]]+(![]+[])[            
             !+[]+!+[]]+(                                                                       !![]+[])                                                                    [+[]]+(!![]                                    +[])[!+[]+!+[]+!+[]]+(!![]+[])[+            
             !+[]]])[!+                                                                         []+!+[]+                                                                     [+[]]])()                                       

```

※兵庫県警は**優秀**だからきっと難読化されたスクリプトを直すなんてお手のものだから上のコードをみるだけで`while(1)alert()`と等価だとわかっちゃうはず。


# せっかくなので作り方

## 下準備 JSFuckコードの作成

以下のコードをJsFuckにぶち込む.
[JSFuck - Write any JavaScript with 6 Characters: []()!+](http://www.jsfuck.com/)

```script.js
while(1)alert()
```

すると

```script.js
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[
...(5138文字)
```

になる。

参考: [JSFuck - Wikipedia](https://ja.wikipedia.org/wiki/JSFuck)

## 味付け

味気ないのでコードに味付けする。
適当な画像を用意する。

元となる画像↓
![base.jpg](https://qiita-image-store.s3.amazonaws.com/0/91558/319aaa6a-302e-53aa-d9fd-7c3f651460d4.jpeg)

ジェネレータの仕様上、画像の上下左右の空白を削除し縦に伸ばしておくとよい↓
![image.jpg](https://qiita-image-store.s3.amazonaws.com/0/91558/bf492d16-85ad-2037-c6bd-112ef576d4b0.jpeg)

上の画像を以下のコードにぶちこむ。~~(だいぶ雑なので直したい)~~

```sample.py
import numpy as np
import cv2

src_path = "./script.js"
img_path = "./image.jpg"

# read source file
with open(src_path, 'r') as f:
    source_txt = f.read()

# read image
img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
org_width, org_height = img.shape

# bin search
min_scale = 0.1;
max_scale = 30;
now_scale = 1;

while True:
    img = cv2.resize(img, (int(org_width*now_scale), int(org_height*now_scale) ))
    count_of_black = np.sum(img < 128)

    if len(source_txt) < count_of_black < len(source_txt)+1000:
        break

    if count_of_black < len(source_txt):
        min_scale = now_scale
        now_scale = (max_scale + now_scale) / 2
    else:
        max_scale = now_scale
        now_scale = (min_scale + now_scale) / 2

# resize image
img = cv2.resize(img, (int(org_width*now_scale), int(org_height*now_scale) )) < 128

# create output text
out_text = ""
pointer = 0

for y in range(img.shape[0]):
    for x in range(img.shape[1]):
        add_char = " "
        if img[y,x]:
            if pointer < len(source_txt):
                add_char = source_txt[pointer]
                pointer += 1
        out_text += add_char
    out_text += "\n"

# output
with open("out.txt", 'w') as f:
    f.write(out_text)
```

## 盛り付け

以下のコードをどっかのウェブサーバに置いておく。

```ahokusa.html
<script>
{ 上記のアホくさコード }
</script>
```

## 完成
ウェブサーバに置いたリンクをどこかの掲示板に貼る。
どこかの警察から補導されるまで待ちましょう。

※以上の記事の内容はすべてフィクションです。