rex-text 0.2.21 → 0.2.22

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
  SHA1:
3
- metadata.gz: 1636b1450848233f216d0ebebefb2da5d642ff97
4
- data.tar.gz: 99503e08430646adc6d2ba25b3ec66dfbf9701f8
3
+ metadata.gz: 190d1c71b613ee194a0aac2cf30a1f9e64aa3840
4
+ data.tar.gz: 5be68027d74cf0f41e7cd988274f0f95ef2d6568
5
5
  SHA512:
6
- metadata.gz: b1cc678bd8df6bbc0aa3066504dface1ea3b44c9a50189c6df3a596b13f4a68ebc35f69b15fc90e3df009ef82bd59410c0751dd86fab49e35bc29241e5b317d6
7
- data.tar.gz: 521b2dc5498cc0183c85b80abea0f070542b438a5d2cf15d04420817ffdd8d120cad65dfb07488555e835ada36972951702bc4063a05299dedae4ebdb7c69a64
6
+ metadata.gz: 0cfce79358cf4dcfae393fa5af505e5c5b319553e5c163fcdfd6ca038049078cc2a2d1280bde198af9ed8efc883643acb248b1af77ae8853671885d948de8230
7
+ data.tar.gz: 3359f81978ca710c11ae51f774cc370598d8289cbe640c536e9279f07cba5c8293a10c527cbedecb7dd2131543ca56d86e8a9940fffc2cc0e94631a16baecd48
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Text
3
- VERSION = "0.2.21"
3
+ VERSION = "0.2.22"
4
4
  end
5
5
  end
@@ -1,28 +1,38 @@
1
1
  # -*- coding: binary -*-
2
2
 
3
- module Rex
4
- module Text
3
+ module Rex::Text
4
+ # XOR a string against a variable-length key
5
+ #
6
+ # @param key [String] XOR key
7
+ # @param value [String] String to XOR
8
+ # @return [String] XOR'd string
9
+ def self.xor(key, value)
10
+ unless key && value
11
+ raise ArgumentError, 'XOR key and value must be supplied'
12
+ end
5
13
 
6
- # Returns a XOR'd string.
7
- #
8
- # @param key [String] XOR key.
9
- # @param value [String] The string to XOR.
10
- # @return [String] An XOR'd string.
11
- def self.xor(key, value)
12
- xor_key = key.kind_of?(Integer) || key.nil? ? key.to_i : key.to_i(16)
13
- unless xor_key.between?(0, 255)
14
- raise ArgumentError, 'XOR key should be between 0x00 to 0x0f'
15
- end
14
+ xor_key =
15
+ case key
16
+ when String
17
+ if key.empty?
18
+ raise ArgumentError, 'XOR key must not be empty'
19
+ end
16
20
 
17
- buf = ''
21
+ key
22
+ when Integer
23
+ unless key.between?(0x00, 0xff)
24
+ raise ArgumentError, 'XOR key must be between 0x00 and 0xff'
25
+ end
18
26
 
19
- value.each_byte do |byte|
20
- xor_byte = byte ^ xor_key
21
- buf << [xor_byte].pack('c')
27
+ # Convert integer to string
28
+ [key].pack('C')
22
29
  end
23
30
 
24
- buf
25
- end
31
+ # Get byte arrays for key and value
32
+ xor_key = xor_key.bytes
33
+ xor_value = value.bytes
26
34
 
35
+ # XOR value against cycled key
36
+ xor_value.zip(xor_key.cycle).map { |v, k| v ^ k }.pack('C*')
27
37
  end
28
- end
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rex-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.21
4
+ version: 0.2.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - David 'thelightcosine' Maloney
@@ -88,7 +88,7 @@ cert_chain:
88
88
  G+Hmcg1v810agasPdoydE0RTVZgEOOMoQ07qu7JFXVWZ9ZQpHT7qJATWL/b2csFG
89
89
  8mVuTXnyJOKRJA==
90
90
  -----END CERTIFICATE-----
91
- date: 2018-06-13 00:00:00.000000000 Z
91
+ date: 2019-07-22 00:00:00.000000000 Z
92
92
  dependencies:
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: bundler
metadata.gz.sig CHANGED
Binary file