Skip to content

Instantly share code, notes, and snippets.

@hgarrereyn
Created November 29, 2020 14:38
Show Gist options
  • Select an option

  • Save hgarrereyn/598ac0e4e737a93ea6ed63669c167d8f to your computer and use it in GitHub Desktop.

Select an option

Save hgarrereyn/598ac0e4e737a93ea6ed63669c167d8f to your computer and use it in GitHub Desktop.
run run run disasm - Hitcon CTF 2020
var idx;
var flag;
function onLayout(dc) {
var v2;
WatchFace.onUpdate(dc);
myTimer.stop();
if (0 <= idx < size) {
v2 = solve() & 0xff;
v2 ^= magix[idx]; // ?
flag += v2.toChar().toString();
}
// 06CE
drawFlag(flag);
if (idx < size) {
// 06FE
myTimer.start(
method(:timerCallback),
(target[idx] + 1) * 100,
false
);
}
}
function timerCallback() {
idx += 1;
UI.requestUpdate();
}
function solve() {
var v1 = 0;
var v2 = 1;
var v3 = 1;
var v4 = 1;
while (v1 < target.idx) {
v1 += 1;
var temp = ((v2 * 2) + v3 + (v4 * 7)) % 0x7a69;
v4 = v3;
v3 = v2;
v2 = temp;
}
return v2;
}
function drawFlag(flag) {
setColor(Toybox_Graphics.COLOR_BLACK, Toybox_Graphics.COLOR_BLACK);
clear();
setColor(Toybox_Graphics.COLOR_WHITE, Toybox_Graphics.COLOR_TRANSPARENT);
drawText(
getWidth() / 2,
getHeight() / 2,
flag,
Toybox_Graphics.FONT_LARGE,
Toybox_Graphics.TEXT_JUSTIFY_CENTER | Toybox_Graphics.TEXT_JUSTIFY_VCENTER
);
}
magic = [0x62, 0x20, 0x54, 0xfd, 0xd9, 0x12, 0x5c, 0x16, 0x70, 0x8a, 0x93, 0x2e, 0xa8, 0xe5, 0x1f, 0x95, 0x48, 0x5e, 0xbf, 0x7c, 0x15, 0xb0, 0xa, 0x68, 0x9a, 0xd5, 0xeb, 0x19, 0xed, 0x3d, 0x12, 0xf]
target = [0x1, 0x3, 0x9, 0x1b, 0x51, 0xf3, 0x2d9, 0x88b, 0x19a1, 0x4ce3, 0xe6a9, 0x2b3fb, 0x81bf1, 0x1853d3, 0x48fb79, 0xdaf26b, 0x290d741, 0x7b285c3, 0x17179149, 0x4546b3db, 0xcfd41b91, 0x26f7c52b3, 0x74e74f819, 0x15eb5ee84b, 0x41c21cb8e1, 0xc546562aa3, 0x24fd3027fe9, 0x6ef79077fbb, 0x14ce6b167f31, 0x3e6b41437d93, 0xbb41c3ca78b9, 0x231c54b5f6a2b]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment