Class: Voltron::Encrypt
- Inherits:
-
Object
show all
- Defined in:
- lib/voltron/encrypt.rb,
lib/voltron/encrypt/engine.rb,
lib/voltron/encrypt/version.rb,
lib/generators/voltron/encrypt/install_generator.rb,
lib/voltron/encrypt/active_record/collection_association.rb
Defined Under Namespace
Modules: ActiveRecord, Generators
Classes: Engine
Constant Summary
collapse
- VERSION =
"0.2.0".freeze
Instance Method Summary
collapse
Instance Method Details
#blacklist(len = 6) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/voltron/encrypt.rb', line 53
def blacklist(len = 6)
if File.exist?(Voltron.config.encrypt.blacklist.to_s)
File.readlines(Voltron.config.encrypt.blacklist).map(&:strip).reject { |line| line.length > len }.join(" ")
else
""
end
end
|
#blacklisted?(input) ⇒ Boolean
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/voltron/encrypt.rb', line 38
def blacklisted?(input)
encoded = encode(input)
pattern = ["\\b([_\\-])*"]
encoded.chars.each do |c|
subs = translations[c.downcase] || []
c = "\\#{c}" if c == "-"
pattern << "[#{c}#{subs.join}]([_\\-])*"
end
pattern << "\\b"
regex = Regexp.new(pattern.join, Regexp::IGNORECASE)
!blacklist(encoded.length).match(regex).nil?
end
|
#decode(input) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/voltron/encrypt.rb', line 26
def decode(input)
inp = input.to_s.split("")
out = 0
begin
chr = inp.shift
out += (digits.length**inp.length)*digits.index(chr)
end until inp.empty?
out - Voltron.config.encrypt.offset.to_i end
|
#encode(input) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/voltron/encrypt.rb', line 10
def encode(input)
radix = digits.length
i = input.to_i + Voltron.config.encrypt.offset.to_i
raise ArgumentError.new("Value #{val} cannot be less than zero") if i < 0
out = []
begin
rem = i % radix
i /= radix
out << digits[rem]
end until i == 0
out.reverse.join
end
|