Created
September 4, 2023 14:58
-
-
Save BongoKnight/818d5a40e58ea6fbde6f38620599e9fc to your computer and use it in GitHub Desktop.
Generate UTF8 NFKD text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import unicodedata | |
| import random | |
| unicode_max = 0x10ffff | |
| printable_glyphs = [ chr(x) for x in range(0, unicode_max+1) if chr(x).isprintable()] | |
| alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.' | |
| dict_alpha = {i:[] for i in alphabet} | |
| for i in printable_glyphs : | |
| normalized_char = unicodedata.normalize("NFKD", i) | |
| if len(normalized_char)==1 and normalized_char in alphabet: | |
| dict_alpha[normalized_char].append(i) | |
| def unormalize_string(string): | |
| unormalized = "" | |
| for letter in string: | |
| if dict_alpha.get(letter): | |
| unormalized += random.choice(dict_alpha.get(letter)) | |
| else: | |
| unormalized += letter | |
| return unormalized | |
| unormalize_string("google.com") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment