cryptools 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cryptools.rb +83 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dd0885e1bda6d70cabd8fd6a3b871c74c4fb7f5e
4
+ data.tar.gz: 39d75c7dc75fcf4626d33fc9156c8fc29a7832fa
5
+ SHA512:
6
+ metadata.gz: c2a7b4b853bc0d2beedddfefb98c237f35f387373ae8b50af665f27f6353f401e94a5ac4797a54f820e1549c66318aa53df3b1eb676fd1196deef3eeaf6f9251
7
+ data.tar.gz: 9c079fa383742014692e2bd3fb66234f5586da5bebcec7462721ad272dad90c04d34f69a4f364a95925538e7769e13cbc4bad335bfa43ee87db9c11a97ecb33c
@@ -0,0 +1,83 @@
1
+ require 'base64'
2
+
3
+ # Custom Error Class
4
+ CryptoolsError = Class.new(StandardError)
5
+
6
+ module Cryptools
7
+ module Converters
8
+ module_function
9
+
10
+ def hex2str(hexStr)
11
+ [hexStr].pack('H*')
12
+ end
13
+
14
+ def str2hex(str)
15
+ str.unpack('H*').first
16
+ end
17
+
18
+ def hex2bytes(hexStr)
19
+ hex2str(hexStr).unpack('C*')
20
+ end
21
+
22
+ def bytes2hex(bytes)
23
+ bytes.map{|b| b.to_s(16)}.join
24
+ end
25
+
26
+ def str2bytes(str)
27
+ str.split('').map!{|c| c.ord}
28
+ end
29
+ end
30
+
31
+ module Encoders
32
+ module_function
33
+
34
+ def b64_encode(str)
35
+ Base64.strict_encode64(str)
36
+ end
37
+
38
+ def b64_decode(str)
39
+ Base64.strict_decode64(str)
40
+ end
41
+ end
42
+
43
+ module BitOperations
44
+ module_function
45
+
46
+ def xor_bytes(bytes1, bytes2)
47
+ raise CryptoolsError, 'inputs are not the same length.' if bytes1.length != bytes2.length
48
+
49
+ bytes1.zip(bytes2).map{|(a, b)| a ^ b}
50
+ end
51
+ end
52
+
53
+ module Cryptanalysis
54
+ module_function
55
+
56
+ def index_of_coincidence(input)
57
+ fs = input.each_with_object(Hash.new(0)) { |word,counts| counts[word] += 1 }
58
+ phiO = 0
59
+ n = input.length
60
+ coin_rtext = 0.0385
61
+
62
+ fs.each {
63
+ |key, f|
64
+ phiO += f * (f - 1)
65
+ }
66
+
67
+ phiR = coin_rtext * n * (n - 1)
68
+ phiO / phiR
69
+ end
70
+
71
+ def english_freq_count(str)
72
+ str.scan(/[ETAOIN SHRDLU]/i).length
73
+ end
74
+ end
75
+
76
+ module Ciphers
77
+ module_function
78
+
79
+ def single_byte_repeating_xor(bytes, bytes_k)
80
+ bytes.map{|b| b ^ bytes_k.first}
81
+ end
82
+ end
83
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cryptools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - historypeats
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Library to help with cryptanalysis and exploitation
14
+ email: iam.historypeats@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/cryptools.rb
20
+ homepage: http://rubygems.org/gems/cryptools
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Tools to help with cryptanalysis and expoitation
44
+ test_files: []