passweird 0.1.3 → 0.2.1

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: 2e6d59497282552bfae629eb27790ab7052889936ed6cfe37b84ae34c308de1f
4
+ data.tar.gz: 79040059aad66e4eb6afaf2e6186b00017aeeed6697658960d7388768dc77f85
5
5
  SHA512:
6
- metadata.gz: ff7560b5ba0c011db5c5a92d2e700542e43c17fe0f8f2865b407057288454d4b35a152f4b7966409ce7deb95bb91bd55f2db7fb24b6d64a587ef18df42d29180
7
- data.tar.gz: 2693ae2624679e4381a2f93e0f310cf756882658ae5aa415b205231e7c477b5d97c172023a31b6f6604d0d0cddf085256123acfc3a6e1b55a8240c025dd3151d
6
+ metadata.gz: fdef30ff3536b8fcf72d9cbc2cca93793c2ac4a2802726e3c094d1c6b97ed7d35201dc392d9b4598d329aa31fe9240f84549975ef59cb1818ae95192072d8d20
7
+ data.tar.gz: ac5988d41745ce56cb3f071c104e2baa94b5adc0b0044f2188e8b3dd50c85b852af0e309149e66245f5d21d0ca0706b5f8466291c8654339ec6d14e4bfe26182
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.1)
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
@@ -38,29 +38,17 @@ module Passweird
38
38
  #
39
39
  # @return [Array<String>] an array of unique possible terms
40
40
  def possible_terms
41
- @possible_terms ||= all_substring_case_permutations.uniq
41
+ ([password] + substrings + unleeted_substrings).uniq
42
42
  end
43
43
 
44
44
  private
45
45
 
46
- def all_substring_case_permutations
47
- @all_substring_case_permutations ||= substrings + unleeted_substrings + downcased_substrings + upcased_substrings
46
+ def substrings
47
+ @substrings ||= Substringer.substrings(password.downcase)
48
48
  end
49
49
 
50
50
  def unleeted_substrings
51
51
  @unleeted_substrings ||= LeetSpeak.unleet_all(substrings)
52
52
  end
53
-
54
- def substrings
55
- @substrings ||= Substringer.substrings(password)
56
- end
57
-
58
- def downcased_substrings
59
- @downcased_substrings ||= substrings.map(&:downcase)
60
- end
61
-
62
- def upcased_substrings
63
- @upcased_substrings ||= substrings.map(&:upcase)
64
- end
65
53
  end
66
54
  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.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.1"
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.1
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