sdcd 0.1.2

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 (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/sdcd/version.rb +5 -0
  3. data/lib/sdcd.rb +76 -0
  4. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fc86dbf918d09eacd7d58b95732f19ed539a6e3f9b68285cdc8e5a58a8cf4580
4
+ data.tar.gz: fc70446b980fd09794e1d32edcd4dcd436d412d99e445ff600cce1e20358bf9e
5
+ SHA512:
6
+ metadata.gz: f517df65cd298978dfb7ba1bbdad83c10d76066f887cb3604ab4fdbfdbcf1ddbbcb65fbb56b1059142efde9791cce1d9b3551587443acb30624ee2335e455c81
7
+ data.tar.gz: 917be9dde4d66c25778b77175ff9dce9ecd3abb8a6dd95eab1257b2c48953a940c5bae1471d558bee3030ff0f3fbefda38760a4a517654cbfcd21a727e53c448
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sdcd
4
+ VERSION = "0.1.2"
5
+ end
data/lib/sdcd.rb ADDED
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sdcd/version"
4
+
5
+ class FormatError < IOError;end
6
+
7
+ def rot47(data, iter = 47)
8
+ tmp_value = ''
9
+ data.bytes.map do |c|
10
+ if c > 32 and c < 127
11
+ c += iter
12
+ loop do
13
+ if c > 126
14
+ c = (c - 126)+32
15
+ end
16
+ break if c > 32 and c < 127
17
+ end
18
+ end
19
+ tmp_value += c.chr
20
+ end
21
+ return tmp_value
22
+ end
23
+
24
+ module Sdcd
25
+ class SDCD
26
+ attr_accessor :format,:domain
27
+ def initialize
28
+ end
29
+
30
+ def compress(domain, list_subdomain)
31
+ @format = "\x01\xEE5&%&\xEE\xED\x03#{domain.strip}\xFA"
32
+ list_subdomain.map {|e| e.strip}.uniq.map do |s|
33
+ s = s.sub(".#{domain.strip}", "")
34
+ if s != ""
35
+ s+= "\xFA"
36
+ @format += s
37
+ end
38
+ end
39
+ return rot47(@format, 30)
40
+ end
41
+
42
+ def decompress(data, tmp = [])
43
+ data = rot47(data, 64).dump
44
+ data = data[1,data.length-2]
45
+ data = data.split('\xFA')
46
+ header = data[0]
47
+ if(header[0,24] == '\x01\xEE5&%&\xEE\xED\x03')
48
+ domain = header.split('\x03')[1]
49
+ subdomain = data[1,data.length-1]
50
+ subdomain.map do |s|
51
+ tmp.append("#{s}.#{domain}")
52
+ end
53
+ result = {}
54
+ result[domain] = tmp
55
+ return result
56
+ else
57
+ raise FormatError::new("Unknown SDCD data")
58
+ end
59
+ end
60
+
61
+ def write(file, domain, list_subdomain)
62
+ File.open(file, 'w') do |f|
63
+ return f.write(compress(domain, list_subdomain))
64
+ end
65
+ end
66
+
67
+ def read(file)
68
+ File.open(file, 'rb') do |f|
69
+ return decompress(f.read)
70
+ end
71
+ end
72
+
73
+ end
74
+ end
75
+
76
+ include Sdcd
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sdcd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Madhava-mng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Only for subdomains. it return back object
14
+ email:
15
+ - alformint1@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/sdcd.rb
21
+ - lib/sdcd/version.rb
22
+ homepage: https://github.com/Madhava-mng/sdcd
23
+ licenses: []
24
+ metadata:
25
+ allowed_push_host: https://rubygems.org
26
+ homepage_uri: https://github.com/Madhava-mng/sdcd
27
+ source_code_uri: https://github.com/Madhava-mng/sdcd
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.4.0
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.2.22
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Subdomain compresser
47
+ test_files: []