write-ups-challenges-2021-2022/battleship/solution.py
2021-12-03 00:30:04 +00:00

21 lines
606 B
Python

msg = "EYTAQCTQRA{EYTCTARYEYRCTAEARYWQRCWQEYTQQHTQQHEQWAQHEYTY}"
pfix = "EYTAQCTQRA"
flag = "EYTCTARYEYRCTAEARYWQRCWQEYTQQHTQQHEQWAQHEYTY"
board = [['Q', 'W', 'E', 'R', 'T'], ['Y', 'U', 'I', 'O', 'P'], ['A', 'S', 'D', 'F', 'G'], ['H', 'K', 'L', 'Z', 'X'], ['C', 'V', 'B', 'N', 'M']]
cols = ['Q', 'Y', 'A', 'H', 'C']
flat = sum(board, [])
def secret(enc):
out = ''
pairs = [enc[i:i+2] for i in range(0, len(enc), 2)]
for p in pairs:
col = flat.index(p[0]) % 5
row = cols.index(p[1])
out += board[row][col]
return out
print(secret(pfix), '{', secret(flag), '}')