Class: CryptoChallanges::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto-toolbox/crypto_challanges/solver.rb

Instance Method Summary collapse

Instance Method Details

#solve1(input) ⇒ Object



4
5
6
7
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 4

def solve1(input)
  #CryptoChallanges::Set1::Challange1::Solver.run(input)
  CryptBuffer.from_hex(input).base64
end

#solve10(key, input, iv) ⇒ Object



54
55
56
57
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 54

def solve10(key,input,iv)
  data  = CryptBuffer.from_base64(input).str
  Ciphers::Aes.new(128,:ECB).decipher_cbc(key,data,iv: iv).str
end

#solve2(c1, c2) ⇒ Object



8
9
10
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 8

def solve2(c1,c2)
  (CryptBuffer.from_hex(c1) ^ CryptBuffer.from_hex(c2)).hex.downcase
end

#solve3(input) ⇒ Object



12
13
14
15
16
17
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 12

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) ⇒ Object

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



21
22
23
24
25
26
27
28
29
30
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 21

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) ⇒ Object



32
33
34
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 32

def solve5(input,key)
  CryptBuffer(input).xor(key,expand_input: true).hex
end

#solve6(input) ⇒ Object



36
37
38
39
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 36

def solve6(input)
  buffer = CryptBuffer.from_base64(input)
  Analyzers::VigenereXor.new.analyze(buffer.hex,Analyzers::VigenereXor::HammingDistanceKeyLengthFinder.new)
end

#solve7(input, key) ⇒ Object



41
42
43
44
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 41

def solve7(input,key)
  data = CryptBuffer.from_base64(input).str
  Ciphers::Aes.new(128,:ECB).decipher_ecb(key,data)
end

#solve8(ciphers) ⇒ Object



46
47
48
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 46

def solve8(ciphers)
  Utils::EcbDetector.new.detect(ciphers).first
end

#solve9(input) ⇒ Object



50
51
52
# File 'lib/crypto-toolbox/crypto_challanges/solver.rb', line 50

def solve9(input)
  CryptBuffer(input).pad(4).str
end