Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
GiTS Teaser
000000000000000000000000101010000010100100001010000000101111
100000010001000000000011001000000111111100100001101000100000
000000000000000100000000000000000100100010010001001000000001
111111111111110111111111111111000000001000000000010000000100
111111011111111101111111110001000000100000000000000100000000
000000001000000010000000011100011101101110001001101110111001
000000000000000000000100100100001110010101000011001111101010
110011000001101010011110010010111001110101010111011111110010
010111001110111111001011000101111001001001101000100011101011
001100010000101011010100001011000000000110000000000001000000
110111111111101110111011111011110000000000000000000000000000
001000000000111000000000010000100110110110110110110110110001
001000000001000000001000000001000000000010000000000000000000
011101110111001000111111110101000000000001000000000000000000
111000000000000000000000000000111110111111111011111101110110
100000000000000000000000000100100000000000111000000000000100
101111001011101100010111000111010000000000100000000000001000
101100111001000110101000111010010110110111001111000110111001
011111101000011011101100000110001110101011101010001111000100
110111101011001101110100111000000000000000000000000000000100
001010011100101110111111110111100001010111000000010000001001
010111011001101011100000110100111000000011110101011111000000
111111111111111111111111111111000000000000000000000000000000
000000000000000000000000000000000000000000000000000000101101
IDENT CTF
ABS
SST
ENTRY CTF * Program starts at CTF.
SYSCOM B1
SPACE 4,10
ORG 110B
FWA BSS 0
BUFL EQU 401B
F BSS 0
ZZZZZG0 FILEB FBUF,BUFL,DTY=2RTT
CTF BSS 0
SB1 1 * SET B1 TO 1. (Convention, never modified)
SA1 CTFB * A1 = CTFB. (First location created by DATA 1R)
BX6 X1 * COPY X1 TO X6
SB7 27 * B7 = 27. (Not modified)
SA6 A1 * A6 Now has the address to first DATA location.
SA2 CTFA * A2 has the address of first VFD.
MX0 30 * 30 1's AND 30 0's.
SA1 A2+B1 * A1 = (second VFD)
CTF2 BX6 X0*X1 * X0 AND X1.
ZR X6,CTF4 * JUMP TO CTF4 IF X6 IS ZERO.
JR FCT * JUMP WITH RETURN TO FCT.
SA6 A6+B1 * Address of next storage location.
BX6 -X0*X1 * COMPLEMENT(X0) AND X1.
ZR X6,CTF4 * JUMP TO CTF4 IF X6 IS ZERO.
JR FCT * JUMP WITH RETURN TO FCT.
SA6 A6+B1 * Address of next storage location.
SA1 A1+B1 * Next VFD Instruction.
NZ X1,CTF2 * JUMP TO CTF2 IF X1 IS NOT ZERO.
CTF4 WRITES F,CTFB,CTFBL * Write/Output.
ENDRUN * Exit/End.
FCT SUBR
CX6 X6 * COUNT THE NUMBER OF 1 BITS IN X6 AND STORE RESULTS IN X6.
SB6 X6 * SET B6 TO X6.
LT B6,B7,FCT2 * JUMP TO FCT2 IF B6 < (B7 = 27).
SB6 B6-B7
SB6 B6+B6
SB5 B6+B6
SB5 B5+B5
SB6 B5+B6 * B6 = 10 x (B6 - B7)
AX6 X2,B6 * RIGHT SHIFT X2 BY B6 AND STORE IN X6.
MX7 -10 *
BX6 -X7*X6 * COMPLEMENT(X7) AND X6. LEAST SIGNIFICANT 10 BITS OF X6.
FCT2 JP FCTX * Return to caller maybe? (No idea)
CTFA BSS 0
VFD 6/00B,9/000B,9/000B,9/520B,9/244B,9/120B,9/057B
VFD 6/40B,9/210B,9/003B,9/100B,9/774B,9/415B,9/040B
VFD 6/00B,9/000B,9/400B,9/000B,9/442B,9/211B,9/001B
VFD 6/77B,9/776B,9/777B,9/770B,9/010B,9/002B,9/004B
VFD 6/77B,9/377B,9/577B,9/610B,9/040B,9/000B,9/400B
VFD 6/00B,9/100B,9/200B,9/343B,9/556B,9/115B,9/671B
VFD 6/00B,9/000B,9/004B,9/441B,9/625B,9/031B,9/752B
VFD 6/63B,9/015B,9/236B,9/227B,9/165B,9/273B,9/762B
VFD 6/27B,9/167B,9/713B,9/057B,9/111B,9/504B,9/353B
VFD 6/14B,9/205B,9/324B,9/130B,9/006B,9/000B,9/100B
VFD 6/67B,9/775B,9/673B,9/736B,9/000B,9/000B,9/000B
VFD 6/10B,9/007B,9/000B,9/204B,9/666B,9/666B,9/661B
VFD 6/10B,9/010B,9/010B,9/010B,9/002B,9/000B,9/000B
VFD 6/35B,9/671B,9/077B,9/650B,9/001B,9/000B,9/000B
VFD 6/70B,9/000B,9/000B,9/007B,9/677B,9/737B,9/566B
VFD 6/40B,9/000B,9/000B,9/044B,9/000B,9/700B,9/004B
VFD 6/57B,9/135B,9/427B,9/072B,9/000B,9/400B,9/010B
VFD 6/54B,9/710B,9/650B,9/722B,9/667B,9/170B,9/671B
VFD 6/37B,9/503B,9/354B,9/061B,9/653B,9/521B,9/704B
VFD 6/67B,9/531B,9/564B,9/700B,9/000B,9/000B,9/004B
VFD 6/12B,9/345B,9/677B,9/674B,9/127B,9/002B,9/011B
VFD 6/27B,9/315B,9/340B,9/647B,9/003B,9/653B,9/700B
VFD 6/77B,9/777B,9/777B,9/770B,9/000B,9/000B,9/000B
VFD 6/00B,9/000B,9/000B,9/000B,9/000B,9/000B,9/055B
CTFB BSS 0
DUP 64,1
DATA 1R * 64 STORAGE LOCATIONS. R = Right aligned char with leading 0's.
CTFBL EQU *-CTFB
COMCPL XTEXT COMCCDD
COMCPL XTEXT COMCCIO
COMCPL XTEXT COMCCPM
COMCPL XTEXT COMCDXB
COMCPL XTEXT COMCLFM
COMCPL XTEXT COMCSYS
COMCPL XTEXT COMCWTS
COMCPL XTEXT COMCWTW
BUFFERS SPACE 4,10
USE BUFFERS
FBUF EQU *
RFL= EQU FBUF+BUFL+10
END
# Ruby code for LostToTime. GiTS teaser 2015.
class Solver
def initialize
# Read the data file. Equivalent to VFD in the COMPASS ASM.
f = File.open('data', 'r')
@data = f.read
@data = @data.split("\n")
@data.map { |x| x.strip }
f.close
# initializations
@x6 = 0
@x2 = @data[0].strip.to_i(2)
# Prepare mask of 30 1s and 30 0s
@x0 = ("1"*30 + "0"*30).to_i(2)
# We only start looping from the second VFD.
@data.shift
# @flag simulates the action of X6.
# We find 1 character of the flag at a time in X6 and insert into flag array.
@flag = []
end
def solve
ctf2
finish
end
def ctf2
@data.each do |x1|
x1 = x1.strip
@x6 = x1.to_i(2) & @x0
if @x6 == 0
return nil
end
fct
@flag << @x6
@x6 = x1.to_i(2) & ~@x0
if @x6 == 0
return nil
end
fct
@flag << @x6
end
end
def fct
@x6 = @x6.to_s(2).count("1")
b6 = @x6
if b6 < 27
return nil
end
b6 = 10 * (b6 - 27)
@x6 = @x2 >> b6
@x6 = ("0"*50 + "1"*10).to_i(2) & @x6
end
def finish
# Check documentation to see character representation in compass
@flag.each do |x|
print ('A'.ord + x - 1).chr
end
puts ""
end
end
# Same conventions/variable and function names as used in the assembly.
s = Solver.new
s.solve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment