Challenge

🦙 < 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!")
  1. Reads exactly 23 bytes from stdin: STDIN.read(23).
  2. Generates a 23-element integer sequence using Prime::Generator23.new.take(23).
  3. XORs each generated integer with the corresponding input byte: x ^ y.
  4. Packs the result into a 23-byte string and compares it against the fixed target string

Solution

About Prime::Generator23

Despite 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.

Idea

The check is:

Because XOR is reversible:

So we just reproduce the generator sequence and XOR it with the target to recover the required input.

Final Script

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*")