Skip to content

Commit

Permalink
Merge pull request #5 from FlowCrypt/db-path-error
Browse files Browse the repository at this point in the history
Use correct path (non-cwd) to homographs.json for library
  • Loading branch information
Tom J authored Jun 22, 2020
2 parents b92f961 + 0425728 commit a33d4fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions homograph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from homograph.homograph import homographic
from homograph.homograph import homographs
from homograph.homograph import is_homoglyph
from homograph.homograph import is_homograph
from homograph.homograph import homoglyphs
from homograph.homograph import homographs
12 changes: 6 additions & 6 deletions homograph/homograph.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import json
import string
import pathlib

# The simchar data from ShamFinder could be structured
# waaay more efficiently & less redundantly
hgdb_file = open('homographs.json')
libdir = pathlib.Path(__file__).parent.absolute()
hgdb_file = open(str(libdir) + '/homographs.json')
hgdb = json.load(hgdb_file)
hgdb_file.close

# Checks whether two individual characters are equivalent
def homoglyphic(letter1, letter2):
def is_homoglyph(letter1, letter2):
if letter1 == letter2:
return True

return letter2 in [entry['char'] for entry in hgdb[letter1]['similar_char']]

def homographic(domain1, domain2):
def is_homograph(domain1, domain2):
"""
Determine whether two domains are homographic (visually equivalent or nearly so)
"""
Expand All @@ -26,7 +26,7 @@ def homographic(domain1, domain2):

for letter1, letter2 in zip(domain1, domain2):

if not homoglyphic(letter1, letter2):
if not is_homoglyph(letter1, letter2):
return False

return True
Expand Down

0 comments on commit a33d4fa

Please sign in to comment.