littlestitious 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/littlestitious.rb +196 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b8b4c89b5ba54b975101372b296c5c81e496ec9
4
+ data.tar.gz: cdd9e1d8facb2223f57af1a0d74452204a20d0ac
5
+ SHA512:
6
+ metadata.gz: 158d605eca9bd448bd08ca806fa0e0bd218526c4d0e8dd6745f4551df6e849ffad8b98bdfb825143b1d5f0a2d06efa1f40eb5dfcb8c90c3429d488833bd8055b
7
+ data.tar.gz: b43decf710be858ce0dfb662a77935bf88da369afff7d80bc68146e7c8441f7f1befff84d5f54d10a5c35688dad43eb17d9126248944f4b0f049216ab254dc4a
@@ -0,0 +1,196 @@
1
+ # coding: utf-8
2
+ module Littlestitious
3
+
4
+ def self.included(base)
5
+
6
+ base.instance_eval do
7
+ extend(ClassMethods)
8
+
9
+ initialize_littlestitious_vars(base)
10
+ end
11
+
12
+ end
13
+
14
+ module ClassMethods
15
+
16
+ def inheritable_attrs(*args)
17
+ args.flatten!
18
+ @inheritable_attrs ||= [:inheritable_attrs]
19
+
20
+ args -= @inheritable_attrs
21
+ @inheritable_attrs += args
22
+
23
+ args.each do |arg|
24
+ class_eval %(
25
+ class << self; attr_accessor :#{arg} end
26
+ )
27
+ end
28
+
29
+ @inheritable_attrs
30
+ end
31
+
32
+ def inherited(subclass)
33
+ @inheritable_attrs.each do |inheritable_attribute|
34
+
35
+ instance_var = "@#{inheritable_attribute}"
36
+ value = instance_variable_get instance_var
37
+
38
+ subclass.instance_variable_set instance_var, value
39
+
40
+ end
41
+ end
42
+
43
+ def initialize_littlestitious_vars(base)
44
+
45
+ @zero_width_chars = {
46
+ word_joiner: "\u2060",
47
+ mongolian_vowel_separator: "\u180e",
48
+ zero_width_non_joiner: "\u200c",
49
+ zero_width_joiner: "\u200d",
50
+ zero_width_space: "\u200b",
51
+ zero_width_non_breaking_space: "\ufeff"
52
+ }
53
+
54
+ @weird_space_chars = {
55
+ non_breaking_space: "\u00a0",
56
+ ogham_space: "\u1680",
57
+ en_quad_space: "\u2000",
58
+ em_quad_space: "\u2001",
59
+ en_space: "\u2002",
60
+ em_space: "\u2003",
61
+ three_per_em_space: "\u2004",
62
+ four_per_em_space: "\u2005",
63
+ six_per_em_space: "\u2006",
64
+ hair_space: "\u200a",
65
+ narrow_non_breaking_space: "\u202f",
66
+ medium_mathematical_space: "\u205f",
67
+ spc_symbol: "\u2420",
68
+ brail_pattern_blank: "\u2800",
69
+ ideographic_space: "\u3000"
70
+ }
71
+
72
+ # At some point work these into a newline fingerprint
73
+ # detector—it's harder than it looks because systems
74
+ # are inconsistent.
75
+ @new_line_chars = {
76
+ line_feed: "\u000a",
77
+ carriage_return: "\u000d"
78
+ }
79
+
80
+ @non_printing_chars = {
81
+ null: "\u0000",
82
+ start_of_heading: "\u0001",
83
+ start_of_text: "\u0002",
84
+ end_of_text: "\u0003",
85
+ end_of_transmission: "\u0004",
86
+ enquiry: "\u0005",
87
+ acknowledge: "\u0006",
88
+ bell_alert: "\u0007",
89
+ backspace: "\u0008",
90
+ character_tabulation: "\u0009",
91
+
92
+ line_tabulation: "\u000b",
93
+ form_feed: "\u000c",
94
+
95
+ shift_out: "\u000e",
96
+ shift_in: "\u000f",
97
+ data_link_escape: "\u0010",
98
+ device_control_1: "\u0011",
99
+ device_control_2: "\u0012",
100
+ device_control_3: "\u0013",
101
+ device_control_4: "\u0014",
102
+ negative_acknowledge: "\u0015",
103
+ synchronous_idle: "\u0016",
104
+ end_of_trans_block: "\u0017",
105
+ cancel: "\u0018",
106
+ end_of_medium: "\u0019",
107
+ substitute: "\u001a",
108
+ escape: "\u001b",
109
+ file_separator: "\u001c",
110
+ group_separator: "\u001d",
111
+ record_separator: "\u001e",
112
+ unit_separator: "\u001f",
113
+
114
+ reverse_line_feed: "\u008d",
115
+ cancel_character: "\u0094"
116
+ }
117
+
118
+ char_sub_group_syms = [ :weird_space_chars,
119
+ :non_printing_chars,
120
+ :zero_width_chars ]
121
+
122
+ char_sub_groups = char_sub_group_syms.map do |sym|
123
+ instance_variable_get "@#{sym}"
124
+ end
125
+
126
+ @all_chars = { checkmark: "\u2713" }
127
+
128
+ char_sub_groups.each { | group | @all_chars.merge! group }
129
+
130
+ @char_groups = [ @all_chars ] + char_sub_groups
131
+
132
+ @char_groups.map do |char_group|
133
+ char_group.transform_values! { |v| v.encode "utf-8" }
134
+ char_group.freeze
135
+ end
136
+
137
+ @char_lookup = {}
138
+ @all_chars.map { |k, v| @char_lookup[v] = k }
139
+
140
+ size_ok = @char_lookup.size == @all_chars.size
141
+ message = "Mismatched charater mapping"
142
+ raise AssertionError, message unless size_ok
143
+
144
+ class_instance_vars = \
145
+ [ :all_chars, :char_lookup ] + char_sub_group_syms
146
+
147
+ inheritable_attrs class_instance_vars
148
+
149
+ end
150
+
151
+ end
152
+
153
+ def includes_zero_width_characters?
154
+ self.class.zero_width_chars.each do | char_type, char |
155
+ return true if self.include? char
156
+ end
157
+
158
+ false
159
+ end
160
+
161
+ def includes_weird_spaces?
162
+ self.class.weird_space_chars.each do | char_type, char |
163
+ return true if self.include? char
164
+ end
165
+
166
+ false
167
+ end
168
+
169
+ def includes_non_printing_characters?
170
+ self.class.non_printing_chars.each do | char_type, char |
171
+ return true if self.include? char
172
+ end
173
+
174
+ false
175
+ end
176
+
177
+ def strange_character_count
178
+
179
+ char_count = Hash.new(0)
180
+
181
+ self.each_char do |char|
182
+ char_type = self.class.char_lookup[char]
183
+ next unless char_type
184
+ char_count[char_type] += 1
185
+ end
186
+
187
+ char_count
188
+
189
+ end
190
+ alias_method :count_strange_characters, :strange_character_count
191
+ alias_method :count_strange_chars, :strange_character_count
192
+ alias_method :count_strange, :strange_character_count
193
+ alias_method :strange_count, :strange_character_count
194
+ alias_method :strange_char_count, :strange_character_count
195
+
196
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: littlestitious
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Zach Aysan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Sometimes we all get a littlestitious of our strings
14
+ email: zachaysan@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/littlestitious.rb
20
+ homepage: https://github.com/zachaysan/littlestitious
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.6.13
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: String analyzer for fingerprinting and stenography
44
+ test_files: []