古典密碼學 === :::info 時間:10/3 19:00~21:00 地點:蘭潭校區 學活中心三樓 第三會議室 主題:古典密碼學 > [name=Curious] ::: :::success 簡報:[連結](https://drive.google.com/file/d/1tQWoSRY6yiaupGxT6aSrSe5cPq9vU5ci/view?usp=share_link) Lab:[連結](http://172.104.90.38) Flag Format:`NCYU_HACKERS{.*}` 回饋:[連結](https://forms.gle/zcyMNKMaCaFu1wkm7) ::: <!-- 以下區域開放共筆 --> :::spoiler Writeup-Base64 方法一:用線上解密系統 方法二:用 `Command Line` 進行指令 `echo "TkNZVV9IQUNLRVJTe0l0JzVfM25jb2QxbmdfbjA3X2VuKFJ5cDcxbkdfISEhfQ==" | base64 -d` ::: ::: warning 補充: 用`Linux`(虛擬機)方法: 純加密的話可以用`base64` 純解密的話可以用`base64 -d` 用`ipython1`方法: ```python = import base64 base64.decode(b'TkNZVV9IQUNLRVJTe0l0JzVfM25jb2QxbmdfbjA3X2VuKFJ5cDcxbkdfISEhfQ==') import base64 base64.encode(b'你想要encode的東西') ::: base64是4的倍數,所以可以用`len('字串')`來看多少個字 bytes.fromhex('hex') -> hex轉成string :::spoiler `Identify` Solve Script : ```python from pwn import * import base64 hex_char = '0123456789abcdef' base64_char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' def is_hex_string(string): if len(string) % 2 != 0: return False for char in string: if not char in hex_char: return False return True def is_base64_string(string): if len(string) % 4 != 0: return False for char in string: if not char in base64_char: return False return True r = remote('172.104.90.38', 10009) r.recvlines(3) for i in range(100): r.recvline() chal = r.recvline().strip().split(b' : ')[1].decode() if is_hex_string(chal): ans = bytes.fromhex(chal) elif is_base64_string(chal): ans = base64.b64decode(chal.encode()) else: ans = chal.encode() r.sendlineafter(b'> ', ans) r.interactive() ``` ::: ## Caesar Cipher ### 加密 1. 把明文中所有英文字母轉成大寫(或小寫) 2. 按照設定的偏移量改字母 ```python import hashlib plain = "得到的明文" print(f'flag{{{hashlib.md5(plain.encode()).hexdigest()}}}') ``` ## Affine Cipher <!--共筆結束囉--> <!-- 如果你能夠把它變得更好看再修改code --> <!-- 否則我會去找你 :D --> <style> .navbar-brand::after{content: " x NCYU_HACERS"; } </style>