CTFs and solutions
This commit is contained in:
		
							
								
								
									
										41
									
								
								fool-the-oracle-v2/chall.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								fool-the-oracle-v2/chall.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | ||||
| from Cryptodome.Cipher import AES | ||||
| from Cryptodome.Util.Padding import pad, unpad | ||||
| from Cryptodome.Random import get_random_bytes | ||||
| #from secret import flag | ||||
| flag = "puppa" | ||||
| assert (len(flag) == len("CRYPTO25{}") + 36) | ||||
|  | ||||
| key = get_random_bytes(24) | ||||
| padding = get_random_bytes(5) | ||||
| flag = flag.encode() | ||||
|  | ||||
|  | ||||
| def encrypt() -> bytes: | ||||
|     data = bytes.fromhex(input("> ").strip()) | ||||
|     payload = padding + data + flag | ||||
|  | ||||
|     cipher = AES.new(key=key, mode=AES.MODE_ECB) | ||||
|     print(cipher.encrypt(pad(payload, AES.block_size)).hex()) | ||||
|  | ||||
|  | ||||
| def main(): | ||||
|     menu = \ | ||||
|         "What do you want to do?\n" + \ | ||||
|         "quit - quit the program\n" + \ | ||||
|         "enc - encrypt something\n" + \ | ||||
|         "help - show this menu again\n" + \ | ||||
|         "> " | ||||
|  | ||||
|     while True: | ||||
|         cmd = input(menu).strip() | ||||
|  | ||||
|         if cmd == "quit": | ||||
|             break | ||||
|         elif cmd == "help": | ||||
|             continue | ||||
|         elif cmd == "enc": | ||||
|             encrypt() | ||||
|  | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     main() | ||||
		Reference in New Issue
	
	Block a user
	 emln
					emln