commit 1b4e112bf6f845651d0a02a37322e3049df4616f Author: Francois JUMELLE Date: Mon Jun 12 10:56:25 2023 +0200 Introduction diff --git a/course_introduction.py b/course_introduction.py new file mode 100644 index 0000000..8fe8a29 --- /dev/null +++ b/course_introduction.py @@ -0,0 +1,65 @@ +#ascii +print("ASCII") +input = [99, 114, 121, 112, 116, 111, 123, 65, 83, 67, 73, 73, 95, 112, 114, 49, 110, 116, 52, 98, 108, 51, 125] +print("".join(chr(o) for o in input)) +print() + +#hex +print("HEX") +input = "63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6c6f747d" +print(bytes.fromhex(input)) +print() + +#base64 +print("Base64") +input = "72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf" +import base64 +print(base64.b64encode(bytes.fromhex(input))) +print() + +#bytes and big integers +print("Bytes and big integers") +input = 11515195063862318899931685488813747395775516287289682636499965282714637259206269 +print(bytes.fromhex(f"{input:X}")) +print() + +#xor starter +print("XOR starter") +input = "label" +print("crypto{" + "".join(chr(ord(c)^13) for c in input) + "}") +print() + +#xor properties +print("XOR properties") +key1 = "a6c8b6733c9b22de7bc0253266a3867df55acde8635e19c73313" +key2_xor_key1 = "37dcb292030faa90d07eec17e3b1c6d8daf94c35d4c9191a5e1e" +key2_xor_key3 = "c1545756687e7573db23aa1c3452a098b71a7fbf0fddddde5fc1" +flag_xor_key1_xor_key3_xor_key2 = "04ee9855208a2cd59091d04767ae47963170d1660df7f56f5faf" +def xor(data1, data2): + if len(data1) != len(data2): + raise ValueError(f"Both data shall have the same length: {data1} ({len(data1)} char) vs {data2} ({len(data2)} char)") + return f"{int(data1, 16)^int(data2, 16):0{len(data1)}X}" +flag = xor(xor(flag_xor_key1_xor_key3_xor_key2, key2_xor_key3), key1) +print(bytes.fromhex(flag)) +print() + +#favourite bytes +print("Favourite byte") +input = "73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d" +for i in range(256): + res = bytes.fromhex(xor(input, f"{i:02X}"*(len(input)//2))) + if res.startswith(b"crypto"): + print(res) + break +print() + +#You either know, XOR you don't +print("You either know, XOR you don't") +flag_format = "".join(f"{ord(c):02X}" for c in "crypto{") +input = "0e0b213f26041e480b26217f27342e175d0e070a3c5b103e2526217f27342e175d0e077e263451150104" +key = xor(flag_format, input[:len(flag_format)]) +print(key) +key = "6D79584F526B6579" #myXORkey +key = key*(len(input)//len(key)+1) +res = xor(key[:len(input)], input) +print(bytes.fromhex(res))