Encrypted bytecode VM (final)
The final challenge combines two techniques: a known-plaintext XOR attack and tracing a VM with a loop (the same VM as in challenge 11, with the same opcode set):
| Mnemonic | Code | Description |
|---|---|---|
PUSH | 1 | Operanddagi sonni stekka qo'yadi. |
STEP | 13 | MA'LUMOTLAR jadvalidan navbatdagi baytni oladi, uni KALIT jadvalidagi navbatdagi bayt bilan XOR qiladi, natijani stekka qo'yadi va ichki ko'rsatkichni 1 ga oshiradi. |
OUT | 5 | Stek tepasini belgi (chr) sifatida chiqaradi va olib tashlaydi. |
DEC | 11 | Stek tepasidan 1 ayiradi (mod 256). |
DUP | 6 | Stek tepasidagi qiymatni ikkilantiradi (nusxa qo'shadi). |
JZ | 9 | Stekdan qiymat oladi; agar u 0 bo'lsa, operand manziliga o'tadi, aks holda davom etadi. |
JMP | 8 | Operand ko'rsatgan manzilga (indeksga) o'tadi. |
HALT | 0 | Dasturni to'xtatadi. |
ALL programs in this VM version are built according to a single strict template (only one operand — the repetition count N — is different each time, ALL other bytes are constant):
[PUSH, N, STEP, OUT, DEC, DUP, JZ, 10, JMP, 2, HALT]
However, this program is given in a byte representation encrypted with a 4-byte repeating XOR key (below, as a list of decimal numbers):
203 220 134 88 193 193 130 87 194 197 139
Since EVERY byte in the template other than N is known, it is possible to fully recover the key: for each i (where i != 1) kalit[i mod 4] = shifr[i] XOR shablon[i].
Once the key is recovered, fully decode the program (which also reveals N) and run it. The VM's STEP instruction uses the following DATA and KEY tables (key length 3, periodic):
MA'LUMOTLAR: [94, 23, 138, 78, 25, 130, 103, 4, 224, 74, 9, 182, 100, 38, 182, 110, 34, 165, 113, 53, 161, 125, 53, 184, 121, 50, 174]
KEY (for STEP): [28, 86, 211]