lib/ctf_party/xor.rb in ctf-party-1.5.0 vs lib/ctf_party/xor.rb in ctf-party-2.0.0
- old
+ new
@@ -9,12 +9,12 @@
# 'key'.ulxor('hello') # => "he\a\t\u0016"
def ulxor(key)
b1 = unpack('U*')
b2 = key.unpack('U*')
longest = [b1.length, b2.length].max
- b1 = [0] * (longest - b1.length) + b1
- b2 = [0] * (longest - b2.length) + b2
+ b1 = ([0] * (longest - b1.length)) + b1
+ b2 = ([0] * (longest - b2.length)) + b2
b1.zip(b2).map { |a, b| a ^ b }.pack('U*')
end
# UTF-8 XOR with key (padding left) in place as described for {String#ulxor}.
def ulxor!(key)
@@ -34,11 +34,11 @@
raise 'The key is not ASCII' unless b2.ascii_only?
b1 = b1.chars.map(&:ord)
b2 = b2.chars.map(&:ord)
longest = [b1.length, b2.length].max
- b1 = [0] * (longest - b1.length) + b1
- b2 = [0] * (longest - b2.length) + b2
+ b1 = ([0] * (longest - b1.length)) + b1
+ b2 = ([0] * (longest - b2.length)) + b2
b1.zip(b2).map { |a, b| (a ^ b).chr }.join
end
# ASCII XOR with key (padding left) in place as described for {String#alxor}.
def alxor!(key)