mirror of
https://github.com/cliffe/SecGen.git
synced 2026-02-23 04:08:02 +00:00
Task 18.2 - echo_string/medium.rb
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
# #####################
|
||||
# Programming Challenge
|
||||
# Echo string - Repeat a string and repeat back to the script
|
||||
# #####################
|
||||
|
||||
require 'securerandom'
|
||||
require 'timeout'
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# #####################
|
||||
# Programming Challenge
|
||||
# Echo string - Medium: Reverse a string and repeat it back to the script
|
||||
# #####################
|
||||
|
||||
require 'securerandom'
|
||||
require 'timeout'
|
||||
|
||||
$stdout.sync = true # Disable stdout caching (for challenges that can be run over the network)
|
||||
puts 'Prepare yourself. You need to work quickly for this challenge.'
|
||||
|
||||
sleep 2
|
||||
puts 'Echo the string back to me, in reverse, before the script times out. Try writing a script of your own to make it easier!'
|
||||
sleep 2
|
||||
puts 'Get ready, here we go...'
|
||||
sleep 2
|
||||
# Generate random string
|
||||
string = [SecureRandom.base64(rand(20..40)), SecureRandom.hex(rand(20..40))].sample
|
||||
|
||||
puts string
|
||||
STDOUT.flush
|
||||
|
||||
begin
|
||||
Timeout.timeout 5 do
|
||||
response = gets.chomp
|
||||
if response == string.reverse
|
||||
puts File.read('flag')
|
||||
else
|
||||
puts 'Incorrect answer!'
|
||||
exit
|
||||
end
|
||||
end
|
||||
rescue Timeout::Error
|
||||
puts 'Too slow!'
|
||||
exit
|
||||
end
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
<read_fact>difficulty</read_fact>
|
||||
|
||||
<default_input into="difficulty">
|
||||
<value>low</value>
|
||||
<!--TODO: implement higher difficulty options -->
|
||||
<!--<value>medium</value>-->
|
||||
<!--<value>low</value>-->
|
||||
<value>medium</value>
|
||||
<!--TODO: implement high difficulty options -->
|
||||
<!--<value>high</value>-->
|
||||
</default_input>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user