Cyptohack Introduction_to_CryptoHack Writeup
ASCII 题目
解 用Python自带的chr()
函数即可:
1 2 3 4 5 6 7 8 9 str_list = [99 , 114 , 121 , 112 , 116 , 111 , 123 , 65 , 83 , 67 , 73 , 73 , 95 , 112 , 114 , 49 , 110 , 116 , 52 , 98 , 108 , 51 , 125 ] flag = "" for i in str_list: flag+= chr (i) print (flag)
Hex 题目
解 用Python自带的bytes.fromhex()
函数即可:
1 2 3 4 hex_str = "63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6c6f747d" print (bytes .fromhex(hex_str).decode())
Base64 题目
解 需要用到base64这个库的base64.b64encode()函数:
1 2 3 4 5 6 7 8 9 import base64hex_content = "72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf" b_c = bytes .fromhex(hex_content) print (base64.b64encode(b_c).decode())
Bytes and Big Integers 题目
解 需要用到PyCryptodome
库的Crypto.Util.number
的long_to_bytes()
函数:
1 2 3 4 5 6 from Crypto.Util.number import *m = 11515195063862318899931685488813747395775516287289682636499965282714637259206269 print (long_to_bytes(m))
XOR Starter 题目
解 1 2 3 4 5 6 7 8 s = "label" new_s = "" for i in s: new_s += chr ((ord (i) ^ 13 )) print (f"crypto{{{new_s} }}" )
或者用pwntolls
库的xor()
函数:
1 2 3 4 5 6 7 8 9 from pwn import *s = "label" new_s = xor(s,13 ).decode() print (f"crypto{{{new_s} }}" )
XOR Properties 题目
解 1 2 3 4 5 6 7 8 9 10 from pwn import *k1 = bytes .fromhex("a6c8b6733c9b22de7bc0253266a3867df55acde8635e19c73313" ) k12 = bytes .fromhex("37dcb292030faa90d07eec17e3b1c6d8daf94c35d4c9191a5e1e" ) k23 = bytes .fromhex("c1545756687e7573db23aa1c3452a098b71a7fbf0fddddde5fc1" ) f123 = bytes .fromhex("04ee9855208a2cd59091d04767ae47963170d1660df7f56f5faf" ) flag = xor( xor(f123,k23) , k1) print (flag)
Favourite byte 题目
解 1 2 3 4 5 6 7 8 9 10 11 c = bytes .fromhex("73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d" ) m =b"" for key in range (256 ): m = bytes ([b ^ key for b in c]) if b"crypto" in m: print (key) print (m) break
You either know, XOR you don’t 题目
解 通过已知的flag格式开头可以确定前几位密钥(myXORke
),再根据flag格式结尾(}
)确定密钥的最后一位(y
)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 from pwn import *c = bytes .fromhex("0e0b213f26041e480b26217f27342e175d0e070a3c5b103e2526217f27342e175d0e077e263451150104" ) known_flag = b"crypto{" known_key_begin = xor( c[0 :len (known_flag)] , known_flag ) known_key_end = xor( c[-1 ] , b"}" ) key = b'myXORkey' flag = xor(c,key) print (flag)