summaryrefslogtreecommitdiffhomepage
path: root/vhosts/blog/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-02-24 06:27:07 +0900
committernsfisis <nsfisis@gmail.com>2025-02-24 06:27:07 +0900
commit13b159c6dd499b5c67a110e02780d9e741f0ecdb (patch)
tree85e254e8ac1962f1d16ed5f3a4c1b8964834622f /vhosts/blog/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html
parentac0be4b5207aa3375b745cad7c96533c3f2380b6 (diff)
downloadnsfisis.dev-13b159c6dd499b5c67a110e02780d9e741f0ecdb.tar.gz
nsfisis.dev-13b159c6dd499b5c67a110e02780d9e741f0ecdb.tar.zst
nsfisis.dev-13b159c6dd499b5c67a110e02780d9e741f0ecdb.zip
feat(blog/nuldoc): do not insert whitespace to linebreaks between Japanese sentences
Diffstat (limited to 'vhosts/blog/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html')
-rw-r--r--vhosts/blog/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html40
1 files changed, 20 insertions, 20 deletions
diff --git a/vhosts/blog/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html b/vhosts/blog/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html
index bf288a77..147d7a81 100644
--- a/vhosts/blog/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html
+++ b/vhosts/blog/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html
@@ -64,7 +64,7 @@
<section id="section--intro">
<h2><a href="#section--intro">はじめに</a></h2>
<p>
- 2023 年 3 月 23 日から 25 日にかけて開催予定 (記事執筆時点) の <a href="https://phperkaigi.jp/2023/" rel="noreferrer" target="_blank">PHPerKaigi 2023</a> において、 昨年と同様に、弊社 <a href="https://www.dgcircus.com/" rel="noreferrer" target="_blank">デジタルサーカス株式会社</a> からトークン問題を出題予定である。
+ 2023 年 3 月 23 日から 25 日にかけて開催予定 (記事執筆時点) の <a href="https://phperkaigi.jp/2023/" rel="noreferrer" target="_blank">PHPerKaigi 2023</a> において、昨年と同様に、弊社 <a href="https://www.dgcircus.com/" rel="noreferrer" target="_blank">デジタルサーカス株式会社</a> からトークン問題を出題予定である。
</p>
<p>
@@ -72,11 +72,11 @@
</p>
<p>
- すでに 2023 年用の問題は作成済みであるが、その制作過程の中でいくつかボツ問ができた。せっかくなので、PHPerKaigi 開催を待つ間に紹介しようと思う。
+ すでに 2023 年用の問題は作成済みであるが、その制作過程の中でいくつかボツ問ができた。せっかくなので、PHPerKaigi 開催を待つ間に紹介しようと思う。
</p>
<p>
- 10 月から 2 月まで、毎月 1 記事ずつ公開していく予定 (忘れていなければ)。
+ 10 月から 2 月まで、毎月 1 記事ずつ公開していく予定 (忘れていなければ)。
</p>
<p>
@@ -87,7 +87,7 @@
<section id="section--quiz">
<h2><a href="#section--quiz">問題</a></h2>
<p>
- 注意: これはボツ問なので、得られたトークンを PHPerKaigi で入力してもポイントにはならない。
+ 注意: これはボツ問なので、得られたトークンを PHPerKaigi で入力してもポイントにはならない。
</p>
<pre class="highlight" language="php"><code class="highlight"><span class="hljs-meta">&lt;?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">&quot;​&quot;</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">&#x27;​&lt;?php printf((isset($s)?fn($s)=&gt;trim($s,&quot;​&quot;):fn($s)=&gt;chr(strlen($s)/3))($s=%s).&quot;\n&quot;,&quot;\x27$s\x27&quot;);?&gt;&#x27;</span>).<span class="hljs-string">&quot;\n&quot;</span>,<span class="hljs-string">&quot;\x27<span class="hljs-subst">$s</span>\x27&quot;</span>);<span class="hljs-meta">?&gt;</span>
@@ -102,14 +102,14 @@
<span class="hljs-meta">&lt;?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">&quot;​&quot;</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">&#x27;​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​&lt;?php printf((isset($s)?fn($s)=&gt;trim($s,&quot;​&quot;):fn($s)=&gt;chr(strlen($s)/3))($s=%s).&quot;\n&quot;,&quot;\x27$s\x27&quot;);?&gt;&#x27;</span>).<span class="hljs-string">&quot;\n&quot;</span>,<span class="hljs-string">&quot;\x27<span class="hljs-subst">$s</span>\x27&quot;</span>);<span class="hljs-meta">?&gt;</span></code></pre>
<p>
- &quot;And Then There Were None&quot; (そして誰もいなくなった) と名付けた作品。変則 quine (自分自身と同じソースコードを出力するプログラム) になっている。
+ &quot;And Then There Were None&quot; (そして誰もいなくなった) と名付けた作品。変則 quine (自分自身と同じソースコードを出力するプログラム) になっている。
</p>
</section>
<section id="section--how-to-obtain-token">
<h2><a href="#section--how-to-obtain-token">トークン入手方法</a></h2>
<p>
- 実行してみると、次のような出力が得られる。
+ 実行してみると、次のような出力が得られる。
</p>
<pre class="highlight" language="php"><code class="highlight"><span class="hljs-comment">#</span>
@@ -124,7 +124,7 @@
<span class="hljs-meta">&lt;?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">&quot;​&quot;</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">&#x27;​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​&lt;?php printf((isset($s)?fn($s)=&gt;trim($s,&quot;​&quot;):fn($s)=&gt;chr(strlen($s)/3))($s=%s).&quot;\n&quot;,&quot;\x27$s\x27&quot;);?&gt;&#x27;</span>).<span class="hljs-string">&quot;\n&quot;</span>,<span class="hljs-string">&quot;\x27<span class="hljs-subst">$s</span>\x27&quot;</span>);<span class="hljs-meta">?&gt;</span></code></pre>
<p>
- 1 行目を除き、先ほどのコードとほぼ同じものが出てきた。もう一度実行してみる。
+ 1 行目を除き、先ほどのコードとほぼ同じものが出てきた。もう一度実行してみる。
</p>
<pre class="highlight" language="php"><code class="highlight"><span class="hljs-comment">#</span>
@@ -139,7 +139,7 @@ W
<span class="hljs-meta">&lt;?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">&quot;​&quot;</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">&#x27;​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​&lt;?php printf((isset($s)?fn($s)=&gt;trim($s,&quot;​&quot;):fn($s)=&gt;chr(strlen($s)/3))($s=%s).&quot;\n&quot;,&quot;\x27$s\x27&quot;);?&gt;&#x27;</span>).<span class="hljs-string">&quot;\n&quot;</span>,<span class="hljs-string">&quot;\x27<span class="hljs-subst">$s</span>\x27&quot;</span>);<span class="hljs-meta">?&gt;</span></code></pre>
<p>
- 今度は 2 行目が書き換えられた。すべての行が変化するまで繰り返すと次のようになる。
+ 今度は 2 行目が書き換えられた。すべての行が変化するまで繰り返すと次のようになる。
</p>
<pre class="highlight" language="php"><code class="highlight"><span class="hljs-comment">#</span>
@@ -154,24 +154,24 @@ H
P</code></pre>
<p>
- トークン「#WELOVEPHP」が手に入った。
+ トークン「#WELOVEPHP」が手に入った。
</p>
</section>
<section id="section--commentary">
<h2><a href="#section--commentary">解説</a></h2>
<p>
- 一見すると同じ行が 10 行並んでいるだけなのにも関わらず、なぜそれぞれの行で出力が変わるのか。ソースコードをコピーして、適当なエディタに貼り付けるとわかりやすい。
+ 一見すると同じ行が 10 行並んでいるだけなのにも関わらず、なぜそれぞれの行で出力が変わるのか。ソースコードをコピーして、適当なエディタに貼り付けるとわかりやすい。
</p>
<p>
- Vim で開くと次のようになる (1 行目を抜粋)。
+ Vim で開くと次のようになる (1 行目を抜粋)。
</p>
<pre class="highlight" language="php"><code class="highlight"><span class="hljs-meta">&lt;?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">&quot;&lt;200b&gt;&quot;</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">&#x27;&lt;200b&gt;&lt;?php printf((isset($s)?fn($s)=&gt;trim($s,&quot;&lt;200b&gt;&quot;):fn($s)=&gt;chr(strlen($s)/3))($s=%s).&quot;\n&quot;,&quot;\x27$s\x27&quot;);?&gt;&#x27;</span>).<span class="hljs-string">&quot;\n&quot;</span>,<span class="hljs-string">&quot;\x27<span class="hljs-subst">$s</span>\x27&quot;</span>);<span class="hljs-meta">?&gt;</span></code></pre>
<p>
- <code>&lt;200b&gt;</code> と表示されているのは、Unicode の U+200b で、ゼロ幅スペースである。
+ <code>&lt;200b&gt;</code> と表示されているのは、Unicode の U+200b で、ゼロ幅スペースである。
</p>
<div class="admonition">
@@ -180,44 +180,44 @@ P</code></pre>
</div>
<div class="admonition-content">
<p>
- エディタによっては、ゼロ幅スペースが見えないことがある。VSCode ではブラウザと同様に不可視だった。
+ エディタによっては、ゼロ幅スペースが見えないことがある。VSCode ではブラウザと同様に不可視だった。
</p>
</div>
</div>
<p>
- 文字列リテラルの中にゼロ幅スペースを仕込むことで、見た目を変えずに情報をエンコードすることが可能となる。
+ 文字列リテラルの中にゼロ幅スペースを仕込むことで、見た目を変えずに情報をエンコードすることが可能となる。
</p>
<p>
- 続いて、トークンへの変換ロジックを解析する。注目すべきはこの部分だ。以下、ゼロ幅スペースは Vim での表示に合わせて <code>&lt;200b&gt;</code> と記載する。
+ 続いて、トークンへの変換ロジックを解析する。注目すべきはこの部分だ。以下、ゼロ幅スペースは Vim での表示に合わせて <code>&lt;200b&gt;</code> と記載する。
</p>
<pre class="highlight" language="php"><code class="highlight"><span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=&gt;</span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>)</code></pre>
<p>
- PHP の <code>strlen()</code> は文字列のバイト数を返す。1 行目の <code>$s</code> は以下の内容となっており、
+ PHP の <code>strlen()</code> は文字列のバイト数を返す。1 行目の <code>$s</code> は以下の内容となっており、
</p>
<pre class="highlight" language="php"><code class="highlight"><span class="hljs-variable">$s</span>=<span class="hljs-string">&#x27;&lt;200b&gt;&lt;?php printf((isset($s)?fn($s)=&gt;trim($s,&quot;&lt;200b&gt;&quot;):fn($s)=&gt;chr(strlen($s)/3))($s=%s).&quot;\n&quot;,&quot;\x27$s\x27&quot;);?&gt;&#x27;</span></code></pre>
<p>
- このソースコードは UTF-8 で書かれているので、105 バイトになる。それを 3 で割ると 35 となり、これは <code>#</code> の ASCII コードと一致する。他の行も、同様にしてゼロ幅スペースを詰めることで文字列長を調整し、トークンをエンコードしている。
+ このソースコードは UTF-8 で書かれているので、105 バイトになる。それを 3 で割ると 35 となり、これは <code>#</code> の ASCII コードと一致する。他の行も、同様にしてゼロ幅スペースを詰めることで文字列長を調整し、トークンをエンコードしている。
</p>
<p>
- デコード部以外の部分は、quine のための記述である。
+ デコード部以外の部分は、quine のための記述である。
</p>
</section>
<section id="section--outro">
<h2><a href="#section--outro">おわりに</a></h2>
<p>
- <a href="https://blog.rust-lang.org/2021/11/01/cve-2021-42574.html" rel="noreferrer" target="_blank">CVE-2021-42574</a> に着想を得た作品。この脆弱性は、Unicode の制御文字である left-to-right mark と right-to-left mark を利用し、ソースコードの実際の内容を欺く、というもの。簡単のためゼロ幅スペースを用いることとし、ついでに quine にもするとこうなった。
+ <a href="https://blog.rust-lang.org/2021/11/01/cve-2021-42574.html" rel="noreferrer" target="_blank">CVE-2021-42574</a> に着想を得た作品。この脆弱性は、Unicode の制御文字である left-to-right mark と right-to-left mark を利用し、ソースコードの実際の内容を欺く、というもの。簡単のためゼロ幅スペースを用いることとし、ついでに quine にもするとこうなった。
</p>
<p>
- ボツになった理由は、ゼロ幅スペースを表示してくるエディタが想像以上に多かったため。「同じ行が並んでいるだけなのに出力が異なる」というアイデアの根幹を崩されてしまうので、この問題は不採用となった。
+ ボツになった理由は、ゼロ幅スペースを表示してくるエディタが想像以上に多かったため。「同じ行が並んでいるだけなのに出力が異なる」というアイデアの根幹を崩されてしまうので、この問題は不採用となった。
</p>
</section>
</div>