---
# System prepended metadata

title: Crypto 01 writeup
tags: [archive]

---

# Crypto 01 writeup

:::spoiler
[toc]
:::

## Lab：ASCII practice

```
65 115 99 73 73 115 79 69 97 115 89
```

可以到維基百科慢慢[查表](https://zh.wikipedia.org/zh-tw/ASCII#%E5%8F%AF%E6%98%BE%E7%A4%BA%E5%AD%97%E7%AC%A6) ；也可以選擇寫 python script：

```python=
cipher = [65, 115, 99, 73, 73, 115, 79, 69, 97, 115, 89]

for i in cipher:
    print(chr(i), end = '')
```

```
AscIIsOEasY
```

## Lab：numeric practice

```
請將 821091 轉成 16 進位
請將 0o337522 轉成 10 進位
請將 0b110011010 轉成 10 進位
```

可以選擇手算；也可以選擇寫 python script：

```python=
hex(821091)        # 0xc8763
print(0o337522)    # 114514
print(0b110011010) # 410
```

## Lab：Big Integer

```
cipher = 1001379969218778717835149010429266
```

你可以慢慢從整數->十六進位字串->整數->字元一路轉換下去：

```python=
cipher = 1001379969218778717835149010429266

hex_string = hex(cipher)[2:]
pt = ""

for i in range(0, len(hex_string), 2):
    pt += chr(int(hex_string[i:i+2], 16))
    
print(pt)
```

也可以直接用 `bytes.fromhex()`

```python=
cipher = 1001379969218778717835149010429266
print(bytes.fromhex(hex(cipher)[2:]))
```

```
1_10V3_INT36eR
```

## Lab：encode Misc Challenge

hint 1：Big Integer + base64
hint 2：jpg

[Download Here](https://drive.google.com/file/d/1ezJd1_6RXapxdoihDTzQkyPG03aBbEY9/view)

這題比較複雜一點了，轉換過程依序為整數->十六進位字串->base64 string->binary，最後還要寫檔

```python=
from base64 import b64decode
import sys

sys.set_int_max_str_digits(500000)

with open("challenge.txt", "r") as f:
    number = int(f.read())
    hex_string = hex(number)[2:]
    b64string = bytes.fromhex(hex_string)
    binary = b64decode(b64string)
    open("result.jpg", "wb").write(binary)
```

![](https://hackmd.io/_uploads/Byo_cjUZa.png)

## Lab：Caesar Cipher

```
# 請嘗試解密 cipher
cipher = "VTXLTKVBIAXKATVDXKWBLVHOXKLMAXABWWXGLXVKXML"
```

丟工具，解決！

```
CAESARCIPHERHACKERDISCOVERSTHEHIDDENSECRETS
```

## Lab：Simple Substitution Cipher

```
# 請嘗試解密 cipher
cipher = "EHOLKOVSDFWKRWSMSKSMVZDOSSOHWPIXOWBHFGSNTIBXOHOQIPMVOGISSOHVWIVJHOUOIDSTOWOBHOSPOWWIZOCMSTMVBNJO"
```

再丟工具，解決！

```
FREQUENTLYSUBSTITUTINGLETTERSMAKESCRYPTOHACKEREJAMINEPATTERNSANDREVEALTHESECRETMESSAGEWITHINCODE
```

## Lab：Vigenère cipher

```
# 請找出加密的 key
cipher = "KVCFNDIDJEYJDYSHKAJUWOEBNMBSMXPORTHKXHOUYIYLUWLYEHNVNEDDXKPGVZIRQSFTDIIMVEENEYZXHMUCQCFNDJWZCTOSFKJUHJKPAOMNEDUDQPOBFKPEGVHQNUHFWHTVOLIDIBNGPDDUUCLJIOBWJWEBJALJQRMCFHTSTJDYVJOHXGPJVCUCZOGHYFPODZJOIHNRCHQRVCGYXYHHJXAMKHFYFZSPRSVFCUPNVRNDRMMKCXELYWZMJEUCJAASFFTRNDELFCYSUWGJNWWUVLHNQCQBOSXSIUPMZOEMKAPLNVCCFCYBYJWZMTJFZGUAUOYARWMHQCTVNLFNPHFYFVOZESTPJETIYEDDCHYMPDWFGCYYXUXMXLLSZOTZAWKRBBXMKDSMZOUDRKDRCOUPGVXSUWGJNEEKCBDTQOVPRSHSUXJIYCACPXLXUGQRRFMMUBXAZZBSYXYKIMEGFGMNBBHVYWUBIBAVNZTZLHAJCQCVXWARFYDKIMUENHBTDQCYOSABYTTTUJVBVGVWYCXIVEENEHYKJPDBESWDUQGNGLPDIMSKPZWPBZBAUIDIVWKMVEJOUGQLQCYUELTMOJEMKAPSKYIRBTTAQIIJXPWMFYXGVZHGNZIWEIEZMTPXFGPNWITPRRRJQHHGVEAQKAPTGBHMVGLYYBAGVYCTZLSOPBYLGVXHEHCZMDKERFPXKXQLFCVNUJNVIOBHEWDNKHICYTTSUNXGZTJGZLZCPGQLQGHBUXPQZNKLVAPXGOEBNMMTTHPHVEEYVTDNCHUDHZVTDTXODZJHETDKPNUURVTAUSDHZEKNLKYGVDELFQTUYJPGOZYZJALIJZSIJVXSJXTVMNDHKXNZUJVMHFKJFKQGDNSQFMPZJZCYTBBKYSTIOHKQULZLVCUABBLYYJJODZJZEWENGYUAYOKFJYDIJQEMUXAKPYULPSMMUOLZMPOHXGTTIVFPBABXIEGTIZPDKHHNKXXCISKDQCTMDNWMNTDZQAQJYVXNHJWDNYKSVPLYCKHMZWLJJXPOVWHLVGJKUWBYPYFJDQHRZWHZJPSOVZCCAKHZBTQZBFWQRGEKGYJFRIGFBYTIVMHDIBRNVNEDYWYJBYQZMEUZEWENGKKPFIBYEVWVKAEMVLD"
```

一樣丟工具解決，像是 [guballa](https://www.guballa.de/vigenere-solver) 就可以直接解掉。

不過這題比較特別的是，其他三個工具正常情況都無法生效，因此這邊討論的是用 dCode 算 IC 的解法

首先到 [Index of Coincidence](https://www.dcode.fr/index-coincidence) ，算一下它的 IC 值，可以發現是 0.03896 ，低於英文的銘文 IC 值 0.0667，這代表它很可能是個多表替換的加密。

此時再試一下 CALCULATE PROBABLE KEY-LENGTHS 的功能，發現最有可能的密鑰長度大約是 20 ，此時再回去 [Vigenere Cipher](https://www.dcode.fr/vigenere-cipher) 那邊，在 Knowing the key-length/size, number of letters 輸入剛剛估計的 20，就會發現解出來的明文是正確的。

```
cvqynotfqqpvvlwzrtlg
```