module Matasano::Sets::Set1

Public Instance Methods

solve1(input) click to toggle source
# File lib/crypto-toolbox/matasano/sets/set1.rb, line 5
def solve1(input)
  CryptBuffer.from_hex(input).base64
end
solve2(c1,c2) click to toggle source
# File lib/crypto-toolbox/matasano/sets/set1.rb, line 9
def solve2(c1,c2)
  (CryptBuffer.from_hex(c1) ^ CryptBuffer.from_hex(c2)).hex.downcase
end
solve3(input) click to toggle source
# File lib/crypto-toolbox/matasano/sets/set1.rb, line 13
def solve3(input)
  candidates = (1..256).map{ |guess| CryptBuffer.from_hex(input).xor_all_with(guess) }
  detector = Analyzers::Utils::HumanLanguageDetector.new
  
  detector.human_language_entries(candidates).first.to_s
end
solve4(hexstrings) click to toggle source

challange: One of the 60-character strings in this file has been encrypted by single-character XOR.

# File lib/crypto-toolbox/matasano/sets/set1.rb, line 22
def solve4(hexstrings)
  detector = Analyzers::Utils::HumanLanguageDetector.new
  result = hexstrings.map{|h| CryptBuffer.from_hex(h)}.map.with_index do |c,i|
    candidates = (1..256).map{ |guess| c.xor_all_with(guess) }
    matches = detector.human_language_entries(candidates)

    matches.empty? ? nil : matches
  end
  result.flatten.compact.map(&:str).first
end
solve5(input,key) click to toggle source
# File lib/crypto-toolbox/matasano/sets/set1.rb, line 33
def solve5(input,key)
  CryptBuffer(input).xor(key,expand_input: true).hex
end
solve6(input) click to toggle source
# File lib/crypto-toolbox/matasano/sets/set1.rb, line 37
def solve6(input)
  buffer = CryptBuffer.from_base64(input)
  Analyzers::VigenereXor.new.analyze(buffer.hex,Analyzers::VigenereXor::HammingDistanceKeyLengthFinder.new)
end
solve7(input,key) click to toggle source
# File lib/crypto-toolbox/matasano/sets/set1.rb, line 42
def solve7(input,key)
  data = CryptBuffer.from_base64(input).str
  Ciphers::Aes.new.decipher_ecb(key,data)
end
solve8(ciphers) click to toggle source
# File lib/crypto-toolbox/matasano/sets/set1.rb, line 47
def solve8(ciphers)
  Utils::EcbDetector.new.detect(ciphers).first
end