crypto-toolbox 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/break-vigenere-xor +18 -0
- data/lib/crypto-toolbox/analyzers/vigenere_xor.rb +17 -19
- data/lib/crypto-toolbox/crypt_buffer.rb +12 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 403cf818e558bf451d876c20fbbb90cdff55a573
|
4
|
+
data.tar.gz: cd70a45a5d69397d691bd08a7eb5069affdbba1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 823cc7f89d4e7913affde18355b49b7a63415885c43a413f462e22b91c31b42f48f7ca9459f735a581a12dd9a41405ad8807f5d9ec61a82c9d8b3c38643b8c6b
|
7
|
+
data.tar.gz: 168e3ae351b6e89a006b956ca49e7ba02c431875f383880e7729db3582261606659261239ff5be724cf438e9c31f438359c9848fd186fb4451884d057926534d
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'crypto-toolbox'
|
4
|
+
|
5
|
+
if $0 == __FILE__
|
6
|
+
input = ARGV[0] || "0xF96DE8C227A259C87EE1DA2AED57C93FE5DA36ED4EC87EF2C63AAE5B9A7EFFD673BE4ACF7BE8923CAB1ECE7AF2DA3DA44FCF7AE29235A24C963FF0DF3CA3599A70E5DA36BF1ECE77F8DC34BE129A6CF4D126BF5B9A7CFEDF3EB850D37CF0C63AA2509A76FF9227A55B9A6FE3D720A850D97AB1DD35ED5FCE6BF0D138A84CC931B1F121B44ECE70F6C032BD56C33FF9D320ED5CDF7AFF9226BE5BDE3FF7DD21ED56CF71F5C036A94D963FF8D473A351CE3FE5DA3CB84DDB71F5C17FED51DC3FE8D732BF4D963FF3C727ED4AC87EF5DB27A451D47EFD9230BF47CA6BFEC12ABE4ADF72E29224A84CDF3FF5D720A459D47AF59232A35A9A7AE7D33FB85FCE7AF5923AA31EDB3FF7D33ABF52C33FF0D673A551D93FFCD33DA35BC831B1F43CBF1EDF67F0DF23A15B963FE5DA36ED68D378F4DC36BF5B9A7AFFD121B44ECE76FEDC73BE5DD27AFCD773BA5FC93FE5DA3CB859D26BB1C63CED5CDF3FE2D730B84CDF3FF7DD21ED5ADF7CF0D636BE1EDB79E5D721ED57CE3FE6D320ED57D469F4DC27A85A963FF3C727ED49DF3FFFDD24ED55D470E69E73AC50DE3FE5DA3ABE1EDF67F4C030A44DDF3FF5D73EA250C96BE3D327A84D963FE5DA32B91ED36BB1D132A31ED87AB1D021A255DF71B1C436BF479A7AF0C13AA14794"
|
7
|
+
analyzer = Analyzers::VigenereXor.new.analyze(input)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
@@ -1,7 +1,4 @@
|
|
1
1
|
|
2
|
-
#require 'shellwords'
|
3
|
-
require 'ffi/hunspell'
|
4
|
-
|
5
2
|
=begin
|
6
3
|
# References:
|
7
4
|
#
|
@@ -12,18 +9,20 @@ require 'ffi/hunspell'
|
|
12
9
|
module Analyzers
|
13
10
|
class VigenereXor
|
14
11
|
def jot(message, debug: false)
|
15
|
-
if ENV["
|
16
|
-
|
17
|
-
puts message
|
18
|
-
end
|
12
|
+
if debug == false || ENV["DEBUG_ANALYSIS"]
|
13
|
+
puts message
|
19
14
|
end
|
20
15
|
end
|
21
16
|
def print_delimiter_line
|
22
17
|
puts "====================================================================="
|
23
18
|
end
|
24
|
-
|
19
|
+
def acceptable_char?(byte)
|
20
|
+
(byte > 31 && byte < 123) && (byte != 60 && byte !=64)
|
21
|
+
end
|
22
|
+
|
25
23
|
def find_pattern(buf)
|
26
|
-
bitstring = buf.
|
24
|
+
bitstring = buf.nth_bits(0).join("")
|
25
|
+
|
27
26
|
1.upto([buf.bytes.length,62].min).map do |ksize|
|
28
27
|
parts = bitstring.scan(/.{#{ksize}}/)
|
29
28
|
if parts.uniq.length == 1
|
@@ -35,9 +34,6 @@ module Analyzers
|
|
35
34
|
end
|
36
35
|
|
37
36
|
def analyze(input)
|
38
|
-
require "crypto-toolbox"
|
39
|
-
require "byebug"
|
40
|
-
|
41
37
|
buf = CryptBuffer.new(input)
|
42
38
|
result = find_pattern(buf)
|
43
39
|
|
@@ -58,7 +54,7 @@ module Analyzers
|
|
58
54
|
|
59
55
|
candidate_map[key_byte]=[]
|
60
56
|
1.upto(255).each do |possible_key_value|
|
61
|
-
if smart_buf.xor_all_with(possible_key_value).bytes.all?{|
|
57
|
+
if smart_buf.xor_all_with(possible_key_value).bytes.all?{|byte| acceptable_byte?(byte) }
|
62
58
|
jot("YES: " + smart_buf.xor_all_with(possible_key_value).to_s,debug: true)
|
63
59
|
candidate_map[key_byte] << possible_key_value
|
64
60
|
else
|
@@ -81,20 +77,22 @@ module Analyzers
|
|
81
77
|
if ENV["SEMI_AUTO_ANALYSIS"] && ENV["DEBUG_ANALYSIS"]
|
82
78
|
print_candidate_encryptions(candidate_map,keylen,buf)
|
83
79
|
end
|
80
|
+
|
81
|
+
results = KeySearch::Filter::AsciiPlain.new(combinations,buf).filter
|
82
|
+
report_result(results,buf)
|
83
|
+
end
|
84
84
|
|
85
|
-
|
86
|
-
|
85
|
+
def report_result(results,buf)
|
86
|
+
unless results.empty?
|
87
87
|
jot "[Success] Found valid result(s)"
|
88
|
-
|
88
|
+
results.each do |r|
|
89
89
|
print_delimiter_line
|
90
90
|
jot r.xor(buf).str
|
91
91
|
print_delimiter_line
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
95
|
-
|
96
94
|
end
|
97
|
-
|
95
|
+
|
98
96
|
def print_candidate_encryptions(candidate_map,keylen,buf)
|
99
97
|
# printout for debugging. (Manual analysis of the characters)
|
100
98
|
print "======= Decryption result of first #{keylen} bytes with all candidate keys =======\n"
|
@@ -2,6 +2,9 @@ require 'aes'
|
|
2
2
|
require 'openssl'
|
3
3
|
|
4
4
|
class CryptBuffer
|
5
|
+
class OutOfRangeError < RuntimeError; end
|
6
|
+
|
7
|
+
|
5
8
|
attr_accessor :bytes
|
6
9
|
|
7
10
|
include Enumerable
|
@@ -31,6 +34,15 @@ class CryptBuffer
|
|
31
34
|
end
|
32
35
|
alias_method :s, :str
|
33
36
|
|
37
|
+
|
38
|
+
# Returns an array of the nth least sigificant by bit of each byte
|
39
|
+
def nth_bits(n)
|
40
|
+
raise OutOfRangeError if n < 0
|
41
|
+
raise OutOfRangeError if n > 7
|
42
|
+
|
43
|
+
bits.map{|b| b.reverse[n].to_i }
|
44
|
+
end
|
45
|
+
|
34
46
|
def bits
|
35
47
|
map{|b| "%08d" % b.to_s(2) }
|
36
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crypto-toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Sivia
|
@@ -41,10 +41,12 @@ dependencies:
|
|
41
41
|
description: |2
|
42
42
|
Easily work with primitives like arrays of Bytes or hextrings, to make learning und testing cryptographic methods work like a charme.
|
43
43
|
email: dev@d-coded.de
|
44
|
-
executables:
|
44
|
+
executables:
|
45
|
+
- break-vigenere-xor
|
45
46
|
extensions: []
|
46
47
|
extra_rdoc_files: []
|
47
48
|
files:
|
49
|
+
- bin/break-vigenere-xor
|
48
50
|
- lib/crypto-toolbox.rb
|
49
51
|
- lib/crypto-toolbox/analyzers/vigenere_xor.rb
|
50
52
|
- lib/crypto-toolbox/ciphers/caesar.rb
|