# Crypto
## 一些py函式
- chr()
- ex: 99 -> 'c'
- bytes.fromhex('str')
- ex: bytes().fromhex('617765736f6d65') -> b'awesome'
- 不要留0x 不然python3識別不出來
- bytes().decode('ascii')
- b'awesome' -> 'awesome'
- base64函式庫裡的b64encode('bytes_string')
- 轉換base64編碼
- Crypto.Util.number(install : pip install pycrypto)
- long_to_bytes
- bytes_to_long
## pwntools
- py module
- install : pip install pwntools
- convenience to write exploit
- 常用function
- process()
- remote()
- send(),sendline()
- sendafter(),sendlineafter()
- recv(),recvline()
- recvuntil()
### cryptohack/general/encoding challenge
## AES(Advanced Encryption Standard)
- 對稱式加密
- block length : 128bit
- key length : 128, 192 , 256bit
- 4*4bytes matrix(state)
- cryptohack/block cipher/Structure of AES
- 4 step
- AddRoundKey
- subBytes
- shiftRows
- Mixcolumns
- AddRoundKey
- 對應該次的key進行xor
- cryptohack/block cipher/Round key
- 
- subBytes
- state 透過 sbox inverse 出來的表去做線性轉換
- 混淆用的步驟 避免簡單的代數攻擊
- cryptohack/block cipher/Confusion through Substitution
- 
- shiftrows
- 將每個列向左位移一個數值
- 數值是該列的row值(第一列移0,第二列移1......)
- 
- Mixcolumns
- cryptohack/block cipher/Diffusion through Permutation
- 
- Bringing It All Together
## RSA
- fermat
- nextPrime()
- e太小 C直接取e root就是m
- 練習好站
- [cryptoHack](https://cryptohack.org/)
{%hackmd iaeIZ7VVT223x4UqDsJevQ %}