Created
April 18, 2017 15:09
-
-
Save JuniorPolegato/e953d3425c434bbd6910e7a55b7335e0 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# Para substituir caracteres com acentos e outros por equivalente ascii | |
from unicodedata import normalize | |
# Caracteres para ocultar em ASCII (minúsculos) e o caracter oculto | |
OCULTAR = 'aeiou' | |
C = '*' | |
# Tentar traduzir todos os caracteres para ASCII, se não conseguir colocar '?' | |
def ascii_minusculas(texto): | |
t = map(lambda c: normalize('NFKD', c).encode('ascii', 'ignore').decode(), | |
texto.lower()) | |
return ''.join(map(lambda c: c if c else '?', t)) | |
# Oculta os caracteres em ASCII solicitados | |
def cript(texto): | |
texto_ascii_minusculas = ascii_minusculas(texto) | |
print(texto_ascii_minusculas, '<--- texto_ascii_minusculas') # Debug | |
cript_map = map(lambda c: c in OCULTAR, texto_ascii_minusculas) | |
return ''.join(map(lambda x: [x[1], C][x[0]], zip(cript_map, texto))) | |
# Se rodando como principal (não módulo importado), executa o código abaixo | |
if __name__ == '__main__': | |
# texto = input("Digite um texto: ") | |
texto = 'A esperança é a última que morre! Æ 1º vem o desespero...' | |
print("Trocando `%s´ por `%s´..." % (OCULTAR, C)) | |
print(texto, '<--- texto') | |
print(cript(texto), '<--- cript') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment