Skip to content

Instantly share code, notes, and snippets.

@nick3499
Last active June 5, 2023 15:25
Show Gist options
  • Save nick3499/1015248c0d082485e5e45323be04cd11 to your computer and use it in GitHub Desktop.
Save nick3499/1015248c0d082485e5e45323be04cd11 to your computer and use it in GitHub Desktop.
Convert letters: Python3: input(), for loop, dictionary
#!/usr/bin/env python3
'''Convert characters to similar, random UTF-8 characters.'''
from random import randrange
def substitute():
'''Given text string, `substitute()` method substitutes characters.'''
char_dict = {
'a': ['à', 'á', 'â', 'ã', 'ä', 'å', 'ā', 'ă', 'ȃ', 'ą', 'ǎ', 'ȁ', 'ȧ',
'ɑ', 'ά'],
'A': ['À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ā', 'Ă', 'Ȃ', 'Ą', 'Ǎ', 'Ȁ', 'Ȧ',
'Ά', 'Α'],
'b': ['ƀ', 'Ƅ', 'ɓ'],
'B': ['Ɓ', 'ƅ', 'Ƀ', 'Β', 'β'],
'c': ['ç', 'ć', 'ĉ', 'ċ', 'č', 'ƈ', 'ϲ', 'ͼ', 'ʗ'],
'C': ['Ç', 'Ć', 'Ĉ', 'Ċ', 'Č', 'Ƈ', 'Ϲ', 'Ͼ'],
'd': ['đ', 'ď', 'ȡ', 'ɗ'],
'D': ['Ð', 'Ď', 'Ɗ'],
'e': ['è', 'é', 'ê', 'ë', 'ē', 'ĕ', 'ė', 'ę', 'ȩ', 'ě', 'ȅ', 'ȇ', 'ɇ'],
'E': ['È', 'É', 'Ê', 'Ë', 'Ē', 'Ĕ', 'Ė', 'Ę', 'Ȩ', 'Ě', 'Ȅ', 'Ȇ', 'Ɇ',
'Έ', 'Ε'],
'f': ['ƒ', 'ϝ'],
'F': ['Ƒ', 'Ϝ'],
'g': ['ĝ', 'ğ', 'ġ', 'ģ', 'ǥ', 'ǵ', 'ɠ', 'ɡ'],
'G': ['Ĝ', 'Ğ', 'Ġ', 'Ģ', 'Ǥ', 'Ǵ', 'Ɠ'],
'h': ['ĥ', 'Ȟ', 'ħ',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'q': ['ǫ', 'ǭ', 'ɋ'],
'Q': ['Ǫ', 'Ǭ', 'Ɋ'],
'r': ['ŕ', 'ŗ', 'ř', 'ȑ', 'ȓ', 'ɼ'],
'R': ['Ŕ', 'Ŗ', 'Ř', 'Ȑ', 'Ȓ', 'Ʀ', 'Ɍ'],
's': ['ś', 'ŝ', 'ş', 'š', 'ș', 'ȿ'],
'S': ['Ś', 'Ŝ', 'Ş', 'Š', 'Ș'],
't': ['ţ', 'ŧ', 'ț', 'ƫ', 'ť', 'ȶ', 'ʈ'],
'T': ['Ţ', 'Ŧ', 'Ț', 'Ƭ', 'Ʈ', 'Ť', 'ͳ', 'Ͳ', 'Τ'],
'u': ['ù', 'ú', 'û', 'ü', 'ũ', 'ū', 'ŭ', 'ȗ', 'ů', 'ű', 'ȕ', 'ų', 'ư',
'ʉ'],
'U': ['Ù', 'Ú', 'Û', 'Ü', 'Ũ', 'Ū', 'Ŭ', 'Ȗ', 'Ů', 'Ű', 'Ȕ', 'Ų', 'Ư',
'Ʉ'],
'v': ['v'],
'V': ['V'],
'w': ['ŵ', 'ω', 'ώ'],
'W': ['Ŵ'],
'x': ['×'],
'X': ['χ'],
'y': ['ý', 'ŷ', 'ÿ', 'ƴ', 'ȳ', 'ʏ', 'γ'],
'Y': ['Ý', 'Ŷ', 'Ÿ', 'Ƴ', 'Ȳ', 'Ύ', 'Υ', 'ϓ', 'ϔ'],
'z': ['ź', 'ż', 'ž', 'ƶ', 'ȥ', 'ʐ', 'ʑ'],
'Z': ['Ź', 'Ż', 'Ž', 'Ƶ', 'Ȥ'],
'?': ['¿']}
char_list = list(input('Enter text string: ')) # listed char input
converted = [] # list of converted characters
for i in char_list:
if i not in char_dict:
converted.append(i) # append non-match to `converted`
else:
char_list_len = len(char_dict[i]) # length of key value's list
converted.append(char_dict[i][randrange(0, char_list_len, 1)]) # append random char
print(''.join(converted)) # join list of substitued characters
if __name__ == '__main__':
substitute()
@nick3499
Copy link
Author

nick3499 commented Sep 7, 2020

Copyright 2020 nick3499

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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 OR COPYRIGHT HOLDERS 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.

@nick3499
Copy link
Author

nick3499 commented Sep 7, 2020

curl -s https://gist.githubusercontent.com/nick3499/1015248c0d082485e5e45323be04cd11/raw/b3f7339f0635f259c0316d6aeb21e6fac75cda3b/letter_subs.py | python3

That is basically how to run the script in the command line, but, in this case, the string passed to input() would probably need to be passed to the function as sys.argv[1], but have not set that up yet. If someone needs that fuctionality, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment