Bytecode VM with unchecked bounds
This is a REAL, runnable Python program (attached vm.py): a very small, stack-based bytecode virtual machine. There is a "working memory" of size WORKAREA_SIZE inside the program, but in reality it is only the BEGINNING part of a larger MEMORY list — immediately after it is the system's secret zone (encrypted flag), INSIDE THE EXACT SAME list!
| Opcode | Code | Definition |
|---|---|---|
HALT | 0 | Dasturni to'xtatadi. |
PUSH n | 1 | n sonini stekka qo'yadi. |
OUT | 2 | Stek tepasini belgi (chr) sifatida chiqaradi. |
LOAD idx | 3 | MEMORY[idx] ni stekka qo'yadi (chegarasi TEKSHIRILMAYDI). |
STORE idx | 4 | Stek tepasini MEMORY[idx] ga yozadi. |
ADD | 5 | Ikkita qiymatni qo'shadi (mod 256). |
XOR n | 6 | Stek tepasini n bilan XOR qiladi. |
Read the source code carefully: WORKAREA_SIZE = 14. The LOAD/STORE operations apply idx directly to MEMORY[idx] WITHOUT ANY bounds checking — meaning if idx ≥ 14, you step outside the WORKAREA, straight into the secret zone.
The values in the secret zone are stored XORed with _XOR_KALIT (which is clearly visible in the source code) — using the VM's own XOR n instruction, it is also possible to decode and output them directly INSIDE the VM!
Task: Run vm.py (or import it and call the bajar() function) and provide such a bytecode that it reads EVERY byte in the secret zone in sequence, decodes it with XOR, and outputs it.
Sequence for each secret byte: LOAD idx; XOR _XOR_KALIT; OUT — increment idx one by one starting from 14.