Initial commit

This commit is contained in:
Sainan 2021-10-05 18:22:51 +02:00
commit 7c39943d54
7 changed files with 1080 additions and 0 deletions

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# Homoglpyhs
Transform lookalikes into their Latin counterparts.
## Usage
The data gets turned into PHP and C++ code, which you can find in `src/`.
The PHP file is also available for easy inclusion via composer: `composer install sainan/homoglpyhs`

61
codegen.php Normal file
View File

@ -0,0 +1,61 @@
<?php
$cpp = <<<EOC
namespace Sainan
{
inline void transform_homoglyph(wchar_t& c)
{
switch(c)
{
EOC;
$php = <<<EOC
<?php
function transform_homoglyphs(\$str)
{
EOC;
$latin = NULL;
$homoglyphs = [];
foreach(explode("\n", file_get_contents("data.txt")) as $line)
{
$line = rtrim($line, "\r");
if($line === "")
{
if($latin !== NULL)
{
$latin_char = '\'';
if(in_array($latin, ['\'', '\\']))
{
$latin_char .= '\\';
}
$latin_char .= $latin;
$latin_char .= '\'';
foreach($homoglyphs as $homoglyph)
{
$cpp .= "\n\t\tcase L'{$homoglyph}':";
}
$cpp .= "\n\t\t\tc = L".$latin_char.";\n";
$cpp .= "\t\t\tbreak;\n";
$php .= "\t\$str = str_replace(['".join("', '", $homoglyphs)."'], {$latin_char}, \$str);\n";
$latin = NULL;
$homoglyphs = [];
}
}
else if($latin === NULL)
{
$latin = $line;
}
else
{
array_push($homoglyphs, $line);
}
}
$cpp .= "\t\t}\n\t}\n}\n";
$php .= "\treturn \$str;\n}\n";
file_put_contents("src/homoglyphs.hpp", $cpp);
file_put_contents("src/homoglyphs.php", $php);

12
composer.json Normal file
View File

@ -0,0 +1,12 @@
{
"name": "sainan/homoglyphs",
"description": "Transform lookalikes into their Latin counterparts.",
"homepage": "https://github.com/Sainan/Homoglyphs",
"type": "library",
"license": "Unlicense",
"autoload": {
"files": [
"src/homoglyphs.php"
]
}
}

375
data.txt Normal file
View File

@ -0,0 +1,375 @@
,
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
a
а
à
á
ą
b
c
с
ƈ
ċ
d
ԁ
ɗ
e
е
ė
ė
é
è
f
g
ġ
h
һ
i
і
í
ì
ï
j
ј
ʝ
k
κ
l
ӏ
m
n
ո
o
о
ο
օ
ȯ
ơ
ö
ó
ò
p
р
q
զ
r
s
ʂ
t
u
υ
ս
ü
ú
ù
v
ν
ѵ
w
x
х
ҳ
y
у
ý
z
ʐ
ż
:
;
!
?
´
^
~
¯
_
_
&
@
#
%
+
-
*
=
(
)
[
]
{
}
|
¦
/
¬
$
£
¢
¥
\
,
.
"
`
<
>
'

489
src/homoglyphs.hpp Normal file
View File

@ -0,0 +1,489 @@
namespace Sainan
{
inline void transform_homoglyph(wchar_t& c)
{
switch(c)
{
case L'':
c = L',';
break;
case L'':
c = L'0';
break;
case L'':
c = L'1';
break;
case L'':
c = L'2';
break;
case L'':
c = L'3';
break;
case L'':
c = L'4';
break;
case L'':
c = L'5';
break;
case L'':
c = L'6';
break;
case L'':
c = L'7';
break;
case L'':
c = L'8';
break;
case L'':
c = L'9';
break;
case L'':
c = L'A';
break;
case L'':
c = L'B';
break;
case L'':
c = L'C';
break;
case L'':
c = L'D';
break;
case L'':
c = L'E';
break;
case L'':
c = L'F';
break;
case L'':
c = L'G';
break;
case L'':
c = L'H';
break;
case L'':
c = L'I';
break;
case L'':
c = L'J';
break;
case L'':
c = L'K';
break;
case L'':
c = L'L';
break;
case L'':
c = L'M';
break;
case L'':
c = L'N';
break;
case L'':
c = L'O';
break;
case L'':
c = L'P';
break;
case L'':
c = L'Q';
break;
case L'':
c = L'R';
break;
case L'':
c = L'S';
break;
case L'':
c = L'T';
break;
case L'':
c = L'U';
break;
case L'':
c = L'V';
break;
case L'':
c = L'W';
break;
case L'':
c = L'X';
break;
case L'':
c = L'Y';
break;
case L'':
c = L'Z';
break;
case L'':
case L'а':
case L'à':
case L'á':
case L'':
case L'ą':
c = L'a';
break;
case L'':
c = L'b';
break;
case L'':
case L'с':
case L'ƈ':
case L'ċ':
c = L'c';
break;
case L'':
case L'ԁ':
case L'ɗ':
c = L'd';
break;
case L'':
case L'е':
case L'':
case L'ė':
case L'ė':
case L'é':
case L'è':
c = L'e';
break;
case L'':
c = L'f';
break;
case L'':
case L'ġ':
c = L'g';
break;
case L'':
case L'һ':
c = L'h';
break;
case L'':
case L'і':
case L'í':
case L'ì':
case L'ï':
c = L'i';
break;
case L'':
case L'ј':
case L'ʝ':
c = L'j';
break;
case L'':
case L'κ':
c = L'k';
break;
case L'':
case L'ӏ':
case L'':
c = L'l';
break;
case L'':
c = L'm';
break;
case L'':
case L'ո':
c = L'n';
break;
case L'':
case L'о':
case L'ο':
case L'օ':
case L'ȯ':
case L'':
case L'':
case L'ơ':
case L'ö':
case L'ó':
case L'ò':
c = L'o';
break;
case L'':
case L'р':
c = L'p';
break;
case L'':
case L'զ':
c = L'q';
break;
case L'':
c = L'r';
break;
case L'':
case L'ʂ':
c = L's';
break;
case L'':
c = L't';
break;
case L'':
case L'υ':
case L'ս':
case L'ü':
case L'ú':
case L'ù':
c = L'u';
break;
case L'':
case L'ν':
case L'ѵ':
c = L'v';
break;
case L'':
c = L'w';
break;
case L'':
case L'х':
case L'ҳ':
c = L'x';
break;
case L'':
case L'у':
case L'ý':
c = L'y';
break;
case L'':
case L'ʐ':
case L'ż':
c = L'z';
break;
case L'':
c = L':';
break;
case L'':
c = L';';
break;
case L'':
c = L'!';
break;
case L'':
c = L'?';
break;
case L'':
c = L'´';
break;
case L'':
c = L'^';
break;
case L'':
c = L'~';
break;
case L'':
c = L'¯';
break;
case L'_':
c = L'_';
break;
case L'':
c = L'&';
break;
case L'':
c = L'@';
break;
case L'':
c = L'#';
break;
case L'':
c = L'%';
break;
case L'':
c = L'+';
break;
case L'':
c = L'-';
break;
case L'':
c = L'*';
break;
case L'':
c = L'=';
break;
case L'':
c = L'(';
break;
case L'':
c = L')';
break;
case L'':
c = L'[';
break;
case L'':
c = L']';
break;
case L'':
c = L'{';
break;
case L'':
c = L'}';
break;
case L'':
c = L'';
break;
case L'':
c = L'';
break;
case L'':
c = L'|';
break;
case L'':
c = L'¦';
break;
case L'':
c = L'/';
break;
case L'':
c = L'¬';
break;
case L'':
c = L'$';
break;
case L'':
c = L'£';
break;
case L'':
c = L'¢';
break;
case L'':
c = L'';
break;
case L'':
c = L'¥';
break;
case L'':
c = L'\\';
break;
case L'':
case L'':
c = L',';
break;
case L'':
case L'':
c = L'.';
break;
case L'':
case L'':
c = L'"';
break;
case L'':
case L'':
c = L'`';
break;
case L'':
case L'':
c = L'<';
break;
case L'':
case L'':
c = L'>';
break;
case L'':
case L'':
c = L'\'';
break;
}
}
}

110
src/homoglyphs.php Normal file
View File

@ -0,0 +1,110 @@
<?php
function transform_homoglyphs($str)
{
$str = str_replace([''], ',', $str);
$str = str_replace([''], '0', $str);
$str = str_replace([''], '1', $str);
$str = str_replace([''], '2', $str);
$str = str_replace([''], '3', $str);
$str = str_replace([''], '4', $str);
$str = str_replace([''], '5', $str);
$str = str_replace([''], '6', $str);
$str = str_replace([''], '7', $str);
$str = str_replace([''], '8', $str);
$str = str_replace([''], '9', $str);
$str = str_replace([''], 'A', $str);
$str = str_replace([''], 'B', $str);
$str = str_replace([''], 'C', $str);
$str = str_replace([''], 'D', $str);
$str = str_replace([''], 'E', $str);
$str = str_replace([''], 'F', $str);
$str = str_replace([''], 'G', $str);
$str = str_replace([''], 'H', $str);
$str = str_replace([''], 'I', $str);
$str = str_replace([''], 'J', $str);
$str = str_replace([''], 'K', $str);
$str = str_replace([''], 'L', $str);
$str = str_replace([''], 'M', $str);
$str = str_replace([''], 'N', $str);
$str = str_replace([''], 'O', $str);
$str = str_replace([''], 'P', $str);
$str = str_replace([''], 'Q', $str);
$str = str_replace([''], 'R', $str);
$str = str_replace([''], 'S', $str);
$str = str_replace([''], 'T', $str);
$str = str_replace([''], 'U', $str);
$str = str_replace([''], 'V', $str);
$str = str_replace([''], 'W', $str);
$str = str_replace([''], 'X', $str);
$str = str_replace([''], 'Y', $str);
$str = str_replace([''], 'Z', $str);
$str = str_replace(['', 'а', 'à', 'á', 'ạ', 'ą'], 'a', $str);
$str = str_replace([''], 'b', $str);
$str = str_replace(['', 'с', 'ƈ', 'ċ'], 'c', $str);
$str = str_replace(['', 'ԁ', 'ɗ'], 'd', $str);
$str = str_replace(['', 'е', 'ẹ', 'ė', 'ė', 'é', 'è'], 'e', $str);
$str = str_replace([''], 'f', $str);
$str = str_replace(['', 'ġ'], 'g', $str);
$str = str_replace(['', 'һ'], 'h', $str);
$str = str_replace(['', 'і', 'í', 'ì', 'ï'], 'i', $str);
$str = str_replace(['', 'ј', 'ʝ'], 'j', $str);
$str = str_replace(['', 'κ'], 'k', $str);
$str = str_replace(['', 'ӏ', 'ḷ'], 'l', $str);
$str = str_replace([''], 'm', $str);
$str = str_replace(['', 'ո'], 'n', $str);
$str = str_replace(['', 'о', 'ο', 'օ', 'ȯ', 'ọ', 'ỏ', 'ơ', 'ö', 'ó', 'ò'], 'o', $str);
$str = str_replace(['', 'р'], 'p', $str);
$str = str_replace(['', 'զ'], 'q', $str);
$str = str_replace([''], 'r', $str);
$str = str_replace(['', 'ʂ'], 's', $str);
$str = str_replace([''], 't', $str);
$str = str_replace(['', 'υ', 'ս', 'ü', 'ú', 'ù'], 'u', $str);
$str = str_replace(['', 'ν', 'ѵ'], 'v', $str);
$str = str_replace([''], 'w', $str);
$str = str_replace(['', 'х', 'ҳ'], 'x', $str);
$str = str_replace(['', 'у', 'ý'], 'y', $str);
$str = str_replace(['', 'ʐ', 'ż'], 'z', $str);
$str = str_replace([''], ':', $str);
$str = str_replace([''], ';', $str);
$str = str_replace([''], '!', $str);
$str = str_replace([''], '?', $str);
$str = str_replace([''], '´', $str);
$str = str_replace([''], '^', $str);
$str = str_replace([''], '~', $str);
$str = str_replace([' ̄'], '¯', $str);
$str = str_replace(['_'], '_', $str);
$str = str_replace([''], '&', $str);
$str = str_replace([''], '@', $str);
$str = str_replace([''], '#', $str);
$str = str_replace([''], '%', $str);
$str = str_replace([''], '+', $str);
$str = str_replace([''], '-', $str);
$str = str_replace([''], '*', $str);
$str = str_replace([''], '=', $str);
$str = str_replace([''], '(', $str);
$str = str_replace([''], ')', $str);
$str = str_replace([''], '[', $str);
$str = str_replace([''], ']', $str);
$str = str_replace([''], '{', $str);
$str = str_replace([''], '}', $str);
$str = str_replace(['⦅'], '⦅', $str);
$str = str_replace(['⦆'], '⦆', $str);
$str = str_replace([''], '|', $str);
$str = str_replace(['¦'], '¦', $str);
$str = str_replace([''], '/', $str);
$str = str_replace(['¬'], '¬', $str);
$str = str_replace([''], '$', $str);
$str = str_replace(['£'], '£', $str);
$str = str_replace(['¢'], '¢', $str);
$str = str_replace(['₩'], '₩', $str);
$str = str_replace(['¥'], '¥', $str);
$str = str_replace([''], '\\', $str);
$str = str_replace(['', '、'], ',', $str);
$str = str_replace(['', '。'], '.', $str);
$str = str_replace(['', '”'], '"', $str);
$str = str_replace(['', ''], '`', $str);
$str = str_replace(['', '《'], '<', $str);
$str = str_replace(['', '》'], '>', $str);
$str = str_replace(['', ''], '\'', $str);
return $str;
}