Module: Matasano::Sets::Set1
- Included in:
- Matasano::Solver
- Defined in:
- lib/crypto-toolbox/matasano/sets/set1.rb
Instance Method Summary collapse
- #solve1(input) ⇒ Object
- #solve2(c1, c2) ⇒ Object
- #solve3(input) ⇒ Object
-
#solve4(hexstrings) ⇒ Object
challange: One of the 60-character strings in this file has been encrypted by single-character XOR.
- #solve5(input, key) ⇒ Object
- #solve6(input) ⇒ Object
- #solve7(input, key) ⇒ Object
- #solve8(ciphers) ⇒ Object
Instance Method Details
#solve1(input) ⇒ Object
5 6 7 |
# File 'lib/crypto-toolbox/matasano/sets/set1.rb', line 5 def solve1(input) CryptBuffer.from_hex(input).base64 end |
#solve2(c1, c2) ⇒ Object
9 10 11 |
# 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) ⇒ Object
13 14 15 16 17 18 |
# 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) ⇒ Object
challange: One of the 60-character strings in this file has been encrypted by single-character XOR.
22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
33 34 35 |
# 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) ⇒ Object
37 38 39 40 |
# 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) ⇒ Object
42 43 44 45 |
# 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) ⇒ Object
47 48 49 |
# File 'lib/crypto-toolbox/matasano/sets/set1.rb', line 47 def solve8(ciphers) Utils::EcbDetector.new.detect(ciphers).first end |