Created
July 23, 2016 14:19
-
-
Save ReiFan49/39af26acbc8c187a4062e1b58a61a51c to your computer and use it in GitHub Desktop.
[201607-ABCTF] TGIF Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<<META | |
Contest: ABCTF | |
Author : Rei_Fan49 | |
Team : WhiteHat | |
Date : 2016/07/15 | |
META | |
# STL | |
require 'date' | |
# Basic framework | |
END { | |
err = 0 | |
begin | |
main(*ARGV) | |
rescue Interrupt => it | |
err = 2 | |
rescue Exception => ex | |
STDERR.puts([ex.class,ex.message].select{|x|(x.to_s).length>0}.compact * ': ') | |
STDERR.puts(ex.backtrace * $/) | |
err = 1 | |
ensure | |
exit(err) | |
end | |
} | |
# Main Program | |
def main(*argv) | |
<<-SOLVEDOC | |
To solve this via ruby, it might be simple, but the actual flag isn't what you expected. | |
1. Load the file and read all the lines into array buffer | |
2. Parse with Date STL that Ruby have | |
3. Shift the date 12 months ahead. | |
You get the number, how about the flag? | |
Well, as the instruction is simply to wrap with "abctf{(.+)}". | |
But there's something strange, if you just only submit the number, | |
let's say "abctf{123}". The grader will treat it as wrong thing. | |
Since the context is friday, how about we append 'friday' on the answer? | |
Something like "abctf{242fridays}" or something.' | |
Yeah, it kinda surprised me that the grader accepts that kind of answer. | |
(Of course it's 194 dude.) | |
SOLVEDOC | |
File.open('data.txt','r'){|f| | |
ary = f.readlines | |
ary.map!{ |d| Date.parse(d) } | |
ary.map! { |d| | |
nd = d << (-12) | |
# This will spam your STDOUT for sure | |
puts "#{d} #{d.friday?} => #{nd} #{nd.friday?}" | |
nd | |
} | |
puts ary.select{ |d| d.friday? }.length | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment