passweird 0.1.3 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19a3653441105d1e3b9a361e8164673754157f373c06d140e3c309045044412d
4
- data.tar.gz: '0594f7b975f7946301c6fddc90e056ce44110e91f126c7a6757676903ffe9c6b'
3
+ metadata.gz: 8a90a6f24240691ccdd65ca1185eeda32e95dfc65302d1eb4fa118a5b8e45504
4
+ data.tar.gz: 463bf49ad884574607e5682bd00de52008fca4ee272e9a49f4723c846d306d1c
5
5
  SHA512:
6
- metadata.gz: ff7560b5ba0c011db5c5a92d2e700542e43c17fe0f8f2865b407057288454d4b35a152f4b7966409ce7deb95bb91bd55f2db7fb24b6d64a587ef18df42d29180
7
- data.tar.gz: 2693ae2624679e4381a2f93e0f310cf756882658ae5aa415b205231e7c477b5d97c172023a31b6f6604d0d0cddf085256123acfc3a6e1b55a8240c025dd3151d
6
+ metadata.gz: 940795845301e0ca6c127c168b70b7731fbfba2c779a95bfacf56bdb830e3d1cedfbc79d95e846da41d558f763e7478402450c5fde7c5e24c524af6ef657d201
7
+ data.tar.gz: e20d91623ec83339f47f662f83787af532146c77964f67aa59f52c9ff584ef0d49ca825f33f588d870b803fb90ac17d6b65e0ed1b0d6ece93ffbcb8563289300
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- passweird (0.1.3)
4
+ passweird (0.2.0)
5
5
  activerecord (>= 7.0, < 8.0)
6
6
 
7
7
  GEM
@@ -24,7 +24,7 @@ module Passweird
24
24
  #
25
25
  # @return [Boolean] true if the password is blacklisted, false otherwise
26
26
  def blacklisted?
27
- @blacklisted ||= BlacklistedTerm.where(term: possible_terms).exists?
27
+ @blacklisted ||= BlacklistedTerm.exists?(term: possible_terms)
28
28
  end
29
29
 
30
30
  # Retrieves the blacklisted terms that match the possible terms
@@ -47,6 +47,10 @@ module Passweird
47
47
  @all_substring_case_permutations ||= substrings + unleeted_substrings + downcased_substrings + upcased_substrings
48
48
  end
49
49
 
50
+ def all_substrings
51
+ @all_substrings ||= (substrings + unleeted_substrings).uniq
52
+ end
53
+
50
54
  def unleeted_substrings
51
55
  @unleeted_substrings ||= LeetSpeak.unleet_all(substrings)
52
56
  end
@@ -56,11 +60,11 @@ module Passweird
56
60
  end
57
61
 
58
62
  def downcased_substrings
59
- @downcased_substrings ||= substrings.map(&:downcase)
63
+ @downcased_substrings ||= all_substrings.map(&:downcase)
60
64
  end
61
65
 
62
66
  def upcased_substrings
63
- @upcased_substrings ||= substrings.map(&:upcase)
67
+ @upcased_substrings ||= all_substrings.map(&:upcase)
64
68
  end
65
69
  end
66
70
  end
@@ -8,41 +8,92 @@ module Passweird
8
8
  # leet_speak = Passweird::LeetSpeak.new("example")
9
9
  # leet_string = leet_speak.leet
10
10
  # # => "3x4mpl3"
11
- # normal_string = leet_speak.unleeted
11
+ # normal_string = leet_speak.unleet
12
12
  # # => "example"
13
13
  class LeetSpeak
14
14
  attr_reader :given_string
15
15
 
16
- LEET_CHAR_EQUIVALENTS = {
17
- "T" => "7", "t" => "7",
18
- "E" => "3", "e" => "3",
19
- "I" => "1", "i" => "1",
20
- "L" => "1", "l" => "1",
21
- "O" => "0", "o" => "0",
22
- "S" => "5", "s" => "5",
23
- "A" => "4", "a" => "4",
24
- "G" => "6", "g" => "6",
25
- "B" => "8", "b" => "8"
16
+ ALPHABET_TO_SIMPLE_LEET = {
17
+ # Uppercase
18
+ "A" => "4",
19
+ "B" => "8",
20
+ "C" => "(",
21
+ "E" => "3",
22
+ "F" => "ƒ",
23
+ "G" => "6",
24
+ "H" => "#",
25
+ "I" => "1",
26
+ "N" => "И",
27
+ "O" => "0",
28
+ "R" => "Я",
29
+ "S" => "5",
30
+ "T" => "7",
31
+ "U" => "U",
32
+ "Y" => "¥",
33
+ "Z" => "2",
34
+ # Downcase
35
+ "a" => "4",
36
+ "b" => "8",
37
+ "c" => "(",
38
+ "e" => "3",
39
+ "f" => "ƒ",
40
+ "g" => "6",
41
+ "h" => "#",
42
+ "i" => "1",
43
+ "n" => "и",
44
+ "o" => "0",
45
+ "r" => "я",
46
+ "s" => "5",
47
+ "t" => "7",
48
+ "u" => "u",
49
+ "y" => "¥",
50
+ "z" => "2"
26
51
  }.freeze
27
52
 
53
+ # Reference: https://en.wikipedia.org/wiki/Leet#Table_of_leet-speak_substitutes_for_normal_letters
54
+ # Excluded leet speak equivalents that has 3 or more characters
55
+ LEET_TO_ALPHABET = {
56
+ "4" => "A", "@" => "A", "Д" => "A",
57
+ "8" => "B", "ß" => "B",
58
+ "(" => "C", "{" => "C",
59
+ "3" => "E", "£" => "E", "€" => "E",
60
+ "ƒ" => "F",
61
+ "6" => "G", "9" => "G",
62
+ "#" => "H",
63
+ "1" => "I", "!" => "I",
64
+ "И" => "N", "ท" => "N",
65
+ "0" => "O", "Ø" => "O",
66
+ "Я" => "R",
67
+ "5" => "S", "$" => "S",
68
+ "7" => "T",
69
+ "พ" => "W", "₩" => "W", "ω" => "W",
70
+ "¥" => "Y",
71
+ "2" => "Z"
72
+ }.freeze
73
+
74
+
28
75
  def self.leet(given_string)
29
76
  new(given_string).leet
30
77
  end
31
78
 
79
+ def self.leet?(given_string)
80
+ new(given_string).leet?
81
+ end
82
+
32
83
  def self.leet_all(array_of_strings)
33
84
  raise ArgumentError, "array_of_strings must be an Array" unless array_of_strings.is_a?(Array)
34
85
 
35
86
  array_of_strings.map { |string| leet(string) }
36
87
  end
37
88
 
38
- def self.unleeted(given_string)
39
- new(given_string).unleeted
89
+ def self.unleet(given_string)
90
+ new(given_string).unleet
40
91
  end
41
92
 
42
93
  def self.unleet_all(array_of_strings)
43
94
  raise ArgumentError, "array_of_strings must be an Array" unless array_of_strings.is_a?(Array)
44
95
 
45
- array_of_strings.map { |string| unleeted(string) }
96
+ array_of_strings.map { |string| unleet(string) }
46
97
  end
47
98
 
48
99
  def initialize(given_string)
@@ -55,7 +106,7 @@ module Passweird
55
106
  #
56
107
  # @return [String] the converted leet speak string
57
108
  def leet
58
- given_string.gsub(/[#{LEET_CHAR_EQUIVALENTS.keys.join}]/, LEET_CHAR_EQUIVALENTS)
109
+ given_string.gsub(/[#{ALPHABET_TO_SIMPLE_LEET.keys.join}]/, ALPHABET_TO_SIMPLE_LEET)
59
110
  end
60
111
 
61
112
  def leet?
@@ -65,8 +116,8 @@ module Passweird
65
116
  # Converts the leet speak string back to normal text
66
117
  #
67
118
  # @return [String] the converted normal text string
68
- def unleeted
69
- given_string.gsub(/[#{LEET_CHAR_EQUIVALENTS.values.join}]/, LEET_CHAR_EQUIVALENTS.invert)
119
+ def unleet
120
+ given_string.upcase.gsub(/[#{LEET_TO_ALPHABET.keys.join}]/, LEET_TO_ALPHABET)
70
121
  end
71
122
  end
72
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Passweird
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passweird
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rupert Señga
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-23 00:00:00.000000000 Z
11
+ date: 2025-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord