---
# System prepended metadata

title: Misc/Wheel Cipher（輪轉機）
tags: [攻防世界新手區]

---

###### tags: `攻防世界新手區`
# Misc/Wheel Cipher（輪轉機）
- 題目：
    - 加密表：
    1: < ZWAXJGDLUBVIQHKYPNTCRMOSFE <
    2: < KPBELNACZDTRXMJQOYHGVSFUWI <
    3: < BDMAIZVRNSJUWFHTEQGYXPLOCK <
    4: < RPLNDVHGFCUKTEBSXQYIZMJWAO <
    5: < IHFRLABEUOTSGJVDKCPMNZQWXY <
    6: < AMKGHIWPNYCJBFZDRUSLOQXVET <
    7: < GWTHSPYBXIZULVKMRAFDCEONJQ <
    8: < NOZUTWDCVRJLXKISEFAPMYGHBQ <
    9: < XPLTDSRFHENYVUBMCQWAOIKZGJ <
    10: < UDNAJFBOWTGVRSCZQKELMXYIHP <
    11： < MNBVCXZQWERTPOIUYALSKDJFHG <
    12： < LVNCMXZPQOWEIURYTASBKJDFHG <
    13： < JZQAWSXCDERFVBGTYHNUMKILOP <
    密鑰為：2，3，7，5，13，12，9，1，8，10，4，11，6
    密文為：NFQKSEVOQOFNP


- 解題思路：
    - 密鑰數字的排序對應加密表的重新組合，再依序觀察密文字母，將其順位偏移至第一位。
    2: < KPBELNACZDTRXMJQOYHGVSFUWI <
    3: < BDMAIZVRNSJUWFHTEQGYXPLOCK <
    7: < GWTHSPYBXIZULVKMRAFDCEONJQ <
    5: < IHFRLABEUOTSGJVDKCPMNZQWXY <
    13: < JZQAWSXCDERFVBGTYHNUMKILOP <
    12: < LVNCMXZPQOWEIURYTASBKJDFHG <
    9: < XPLTDSRFHENYVUBMCQWAOIKZGJ <
    1: < ZWAXJGDLUBVIQHKYPNTCRMOSFE <
    8: < NOZUTWDCVRJLXKISEFAPMYGHBQ <
    10: < UDNAJFBOWTGVRSCZQKELMXYIHP <
    4: < RPLNDVHGFCUKTEBSXQYIZMJWAO <
    11: < MNBVCXZQWERTPOIUYALSKDJFHG <
    6: < AMKGHIWPNYCJBFZDRUSLOQXVET <

    - 修正過後的加密表，由上而下依序讀入字串，flag即為其中一項。

``` python
original_wheel = ['ZWAXJGDLUBVIQHKYPNTCRMOSFE',
                  'KPBELNACZDTRXMJQOYHGVSFUWI',
                  'BDMAIZVRNSJUWFHTEQGYXPLOCK',
                  'RPLNDVHGFCUKTEBSXQYIZMJWAO',
                  'IHFRLABEUOTSGJVDKCPMNZQWXY',
                  'AMKGHIWPNYCJBFZDRUSLOQXVET',
                  'GWTHSPYBXIZULVKMRAFDCEONJQ',
                  'NOZUTWDCVRJLXKISEFAPMYGHBQ',
                  'XPLTDSRFHENYVUBMCQWAOIKZGJ',
                  'UDNAJFBOWTGVRSCZQKELMXYIHP',
                  'MNBVCXZQWERTPOIUYALSKDJFHG',
                  'LVNCMXZPQOWEIURYTASBKJDFHG',
                  'JZQAWSXCDERFVBGTYHNUMKILOP ']
shifted_wheel = []
key = [2,3,7,5,13,12,9,1,8,10,4,11,6]
ciphertext = 'NFQKSEVOQOFNP'

for i in key:
    shifted_wheel.append(original_wheel[i-1])
print('Messages:\n',shifted_wheel)

for i in range(len(shifted_wheel)):
    index = shifted_wheel[i].index(ciphertext[i])
    shifted_wheel[i] = shifted_wheel[i][index:]+shifted_wheel[i][0:index]
print('Resort messages:\n',shifted_wheel)

print('output')
for i in range(1,len(shifted_wheel[0])):
    for j in range(len(shifted_wheel)):
        A = chr( ord( shifted_wheel[j][i] ) + 32 )    # 大寫轉小轉(ASCII偏移)
        print( A, end='' )
    print('\n')
```