🦙 < Ruby でフラグチェッカーを書いてみるパカ!
require 'prime';print "flag> ";puts(Prime::Generator23.new.take(23).zip(STDIN.read(23).bytes).map{|x,y|x^y}.pack("C*")=="Coufhlj@bixm|UF\\\\JCjP^P<"?"Correct!":"Incorrect!")
STDIN.read(23).Prime::Generator23.new.take(23).x ^ y.Prime::Generator23Despite the name, Prime::Generator23 is not “generate primes”; it produces a sequence of integers that are candidates for primality (used internally by Ruby’s prime library). For solving the challenge, we don’t need to re-implement it. we can just call it the same way the challenge does.
The check is:
gen[i] ^ input[i] == target[i]Because XOR is reversible:
input[i] = gen[i] ^ target[i]So we just reproduce the generator sequence and XOR it with the target to recover the required input.
require "prime"
target = 'Coufhlj@bixm|UF\\JCjP^P<'
gen = Prime::Generator23.new.take(23)
puts gen.zip(target.bytes).map { |x, y| x ^ y }.pack("C*")