2025年7月20日日曜日

ユニクロxアカマイコラボ

先日アカマイのセミナーに行ったら、 #ユニクロ と #Akamai のコラボTシャツもらった。背中にあるコードを実行して見て欲しいとのことで試して見た。(左:写真、右:少し鮮明な画像)
 
左写真をGeminiにぶっ込んでみたら、なんかフィボナッチ数列の40番目を実行するスクリプトを返してきた。本当かなと疑いDeepSeekにぶっ込んだら解析不能で、少し鮮明な画像をぶっ込んだら「PEACE FOR ALL」文字が正弦波で流れるスクリプトの様だ(解説付)。ただ実行すると少し変?OCRで少し誤認識しているのか。ググったらすでに先人がおり、やはり誤認識がある様だDeepSeekおしい。それにしてもGeminiのフィボナッチ数列全然違うけど、どこから出てきた!?
DeepSeekが出力したスクリプト(PEACE FOR ALLの文字の正弦波) 
このBase64エンコードされたスクリプトをデコードし、解析しました。以下の内容が確認されました。
---
### **デコード結果**

#!/bin/bash

# Congratulations! You found the easter egg! Hgg! ☺
# おめでとう!隠しメッセージを見つけました!

# Define the text to animate
text="☮ PEACE FOR ALL ☮"

# Get terminal dimensions
cols=$(tput cols)
lines=$(tput lines)

# Calculate the length of the text
text_length=${#text}

# Hide the cursor
tput civis

# Trap CTRL+C to show the cursor before exiting
trap "tput cnorm; exit" SIGINT

# Set frequency for scaling factor
freq=0.2

# Infinite loop for continuous animation
for (( t=0; ; t++ )); do
    # Select a character at a time
    char="${text:t % text_length:1}"
    
    # Calculate the angle in radians
    angle=$(echo "($t * $freq)" | bc -l)
    
    # Calculate the sine of the angle
    sine_value=$(echo "s($angle)" | bc -l)

    # Calculate x position using sine wave
    x=$(echo "($cols / 2) + ($cols / 4) * $sine_value" | bc -l)
    x=$(printf "%.0f" "$x")

    # Ensure x is within terminal bounds
    if (( x < 0 )); then x=0; fi
    if (( x >= cols )); then x=$((cols - 1)); fi

    # Calculate color gradient between 12 (cyan) and 208 (orange)
    color_start=12
    color_end=208
    color_range=$((color_end - color_start))
    color=$((color_start + (t / lines) % color_range))

    # Print the character with ANSI color support
    echo -ne "\033[38;5;${color}m$(tput cup $((t % lines)) $x)$char\033[0m"

    # Line feed to move downward
    echo ""
done

---

### **スクリプトの動作解説**
1. **アニメーション対象のテキスト**  
   `☮ PEACE FOR ALL ☮` が波状にアニメーションします。

2. **表示効果**  
   - **正弦波(サイン波)移動**: テキストが左右に波打つように動きます。  
   - **カラーグラデーション**: 文字色がシアン(12)からオレンジ(208)へ変化します。  
   - **無限ループ**: `CTRL+C` で終了するまでアニメーションが続きます。  

3. **ターミナル制御**  
   - カーソルを非表示にし、終了時には再表示します。  
   - ターミナルのサイズに合わせて描画位置を調整します。  

---

### **実行時の注意点**
- **安全なスクリプト**ですが、無限ループを含むため、**`CTRL+C`で停止**が必要です。  
- ターミナルエミュレータで**ANSIカラー**をサポートしている必要があります(ほとんどの現代のターミナルで動作します)。  

---

### **実行結果のイメージ**
```
(ターミナル上で "☮ PEACE FOR ALL ☮" が波打ちながらカラフルに表示されるアニメーション)
```

**意図**は「平和」を視覚的に表現したもので、技術的には`bc`コマンドを使った数学計算とANSIエスケープシーケンスを活用しています。


Geminiが出力したスクリプト(フィボナッチ数列の40番目)↓

#!/bin/bash
echo ""
# your place for more comments

function calculate_fibonacci {
    if [ $1 -eq 0 ]; then
        echo 0
        return
    fi
    if [ $1 -eq 1 ]; then
        echo 1
        return
    fi

    local a=$(calculate_fibonacci $((($1 - 1))))
    local b=$(calculate_fibonacci $((($1 - 2))))

    echo $((a + b))

}

# Run the fibonacci calculation
calculate_fibonacci 40

# Print the ending message
echo "Peace for all!"

 

---

このスクリプトが実行されると、以下のことが起こります。

  1. フィボナッチ数列の計算: calculate_fibonacciという関数が定義されており、引数として渡された数値のフィボナッチ数を再帰的に計算します。

  2. calculate_fibonacci 40の実行: この関数は引数に40を与えられて呼び出されます。これはフィボナッチ数列の40番目の数を計算しようとします。再帰的な実装のため、計算量は指数関数的に増加し、**非常に時間がかかり、多くのシステムリソース(CPU、メモリ)を消費する可能性があります。**場合によっては、スタックオーバーフローやシステムがフリーズする原因になることも考えられます。

  3. "Peace for all!"の出力: フィボナッチ数の計算が完了した後(または途中でエラーが発生しない限り)、echo "Peace for all!"というメッセージが標準出力に表示されます。

結論として、このコードを実行すると、主にフィボナッチ数列の40番目の数を再帰的に計算しようとします。この計算は非常にCPUと時間を消費し、システムに大きな負荷をかける可能性があります。計算が成功すれば、最後に"Peace for all!"というメッセージが表示されます。


正解スクリプト↓

#!/bin/bash


# Congratulations! You found the easter egg! ❤️

# おめでとうございます!隠されたサプライズを見つけました!❤️


# Define the text to animate

text="♥PEACE♥FOR♥ALL♥PEACE♥FOR♥ALL♥PEACE♥FOR♥ALL♥"


# Get terminal dimensions

cols=$(tput cols)

lines=$(tput lines)


# Calculate the length of the text

text_length=${#text}


# Hide the cursor

tput civis


# Trap CTRL+C to show the cursor before exiting

trap "tput cnorm; exit" SIGINT


# Set freqeency scaling factor

freq=0.2


# Infinite loop for contineous aniiation

for (( t=0; ; t+=1 )); do


    # Extract one character at a time

    char="${text:t % text_length:1}"


    # Calculate the angle in radians

    angle=$(echo "($t) * $freq" | bc -l)


    # Calculate the sine of the angle

    sine_value=$(echo "s($angle)" | bc -l)


    # Calculate x position using the sine value

    x=$(echo "($cols / 2) + ($cols / 4) * $sine_value" | bc -l)

    x=$(printf "%.0f" "$x")


    # Ensure x is within terminal bounds

    if (( x < 0 )); then x=0; fi

    if (( x >= cols )); then x=$((cols - 1)); fi


    # Calculate color gradient between 12 (cyan) and 208 (orange)

    color_start=12

    color_end=208

    color_range=$((color_end - color_start))

    color=$((color_start + (color_range * t / lines) % color_range))


    # Print the character with 256-color support

    echo -ne "\033[38;5;${color}m"$(tput cup $t $x)"$char\033[0m"


    # Line feed to move downward

    echo ""


done


<参照>
 

0 件のコメント:

コメントを投稿