ctf-party 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43e5c5fba11ab29415687644876bc3185a7b220adcc0da51bf36bac65b970600
4
- data.tar.gz: 6dc55b3100a380a0ff2c11e61eda9f67fd7a7a1ae5fc9effae3bae870cf701df
3
+ metadata.gz: f5b53f3731ce007357cb7033f6758bbb8136bd7f66deddc1d519aa246f9aee6c
4
+ data.tar.gz: 5c17753bd1e9bbf34e82f639531c9fe496ca8dffc68a83b30d32cc05b5c0cc5d
5
5
  SHA512:
6
- metadata.gz: 36b8f7a716e66fcfb1aed39b71f586d5ad73e9c099a11651c7dfd29093e09f60b15e278036f7e4e7d74150ceca1c374308864634f8f58b8e4078ca261f60a389
7
- data.tar.gz: 17618c1a863ed02b9f838bae87e2135e108d50350658c639494d9d9d2a7751319720a022f801a10a79a0bf0a03417d5262d043c137313d7a004dd08a81b5ab61
6
+ metadata.gz: 2788b1c3b60d2f5ed5a3d05c1971e013f3c02317219368a408b0f375ce9bc3e92d9d67090ca92a39f4dfc908d8c6775d90e4a8cee91736474fd8f3b0ea9e0870
7
+ data.tar.gz: eae30b24bf35a6f6a8caab27bf13f496cc262abefd3d348f7c5e58835141c0a36261162045a17d86236277a0576b64ed9670d66812e82d3536d066fad4b59807
data/lib/ctf_party.rb CHANGED
@@ -8,3 +8,4 @@ require 'ctf_party/flag'
8
8
  require 'ctf_party/hex'
9
9
  require 'ctf_party/case'
10
10
  require 'ctf_party/cgi'
11
+ require 'ctf_party/binary'
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ # Encode a string into binary
5
+ # @param opts [Hash] optional parameters
6
+ # @option opts [Symbol] :bitnumbering Display output with most significant bit
7
+ # first (+:MSB+ default) or least significant bit first (+:LSB+).
8
+ # @return [String] the binary encoded string
9
+ # @example
10
+ # 'binary'.to_bin # => "011000100110100101101110011000010111001001111001"
11
+ # 'binary'.to_bin(bitnumbering: :LSB) # => "010001101001011001110110100001100100111010011110"
12
+ def to_bin(opts = {})
13
+ opts[:bitnumbering] ||= :MSB
14
+ # convert
15
+ return unpack1('B*') if opts[:bitnumbering] == :MSB
16
+ return unpack1('b*') if opts[:bitnumbering] == :LSB
17
+
18
+ raise ArgumentError ':bitnumbering expects :MSB or :LSB'
19
+ end
20
+
21
+ # Alias for {String#to_bin}.
22
+ def str2bin(opts = {})
23
+ to_bin(opts)
24
+ end
25
+
26
+ # Encode a string into binary in place as described
27
+ # for {String#to_bin}.
28
+ # @example
29
+ # a = 'binary'
30
+ # a.to_bin!
31
+ # a # => "011000100110100101101110011000010111001001111001"
32
+ def to_bin!(opts = {})
33
+ replace(to_bin(opts))
34
+ end
35
+
36
+ # Alias for {String#to_bin!}.
37
+ def str2bin!(opts = {})
38
+ to_bin!(opts)
39
+ end
40
+
41
+ # Decode a binary string
42
+ # @param opts [Hash] optional parameters
43
+ # @option opts [Symbol] :bitnumbering Display input with most significant bit
44
+ # first (+:MSB+ default) or least significant bit first (+:LSB+).
45
+ # @return [String] the binary decoded string
46
+ # @example
47
+ # '011000100110100101101110011000010111001001111001'.from_bin # => "binary"
48
+ # '010001101001011001110110100001100100111010011110'.from_bin(bitnumbering: :LSB) # => "binary"
49
+ def from_bin(opts = {})
50
+ opts[:bitnumbering] ||= :MSB
51
+ # convert
52
+ return Array(self).pack('B*') if opts[:bitnumbering] == :MSB
53
+ return Array(self).pack('b*') if opts[:bitnumbering] == :LSB
54
+
55
+ raise ArgumentError ':bitnumbering expects :MSB or :LSB'
56
+ end
57
+
58
+ # Alias for {String#from_bin}.
59
+ def bin2str(opts = {})
60
+ from_bin(opts)
61
+ end
62
+
63
+ # Decode a binary string in place as described
64
+ # for {String#from_bin}.
65
+ # @example
66
+ # a = "011000100110100101101110011000010111001001111001"
67
+ # a.from_bin!
68
+ # a # => "binary"
69
+ def from_bin!(opts = {})
70
+ replace(from_bin(opts))
71
+ end
72
+
73
+ # Alias for {String#from_bin!}.
74
+ def bin2str!(opts = {})
75
+ from_bin!(opts)
76
+ end
77
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Version
4
- VERSION = '1.3.2'
4
+ VERSION = '1.3.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ctf-party
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre ZANNI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-13 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.80'
103
+ version: '1.8'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.80'
110
+ version: '1.8'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: yard
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +135,7 @@ files:
135
135
  - bin/ctf_party_console
136
136
  - lib/ctf_party.rb
137
137
  - lib/ctf_party/base64.rb
138
+ - lib/ctf_party/binary.rb
138
139
  - lib/ctf_party/case.rb
139
140
  - lib/ctf_party/cgi.rb
140
141
  - lib/ctf_party/digest.rb
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  - !ruby/object:Gem::Version
168
169
  version: '0'
169
170
  requirements: []
170
- rubygems_version: 3.1.2
171
+ rubygems_version: 3.1.4
171
172
  signing_key:
172
173
  specification_version: 4
173
174
  summary: A library to enhance and speed up script/exploit writing for CTF players