Traducteur leet speak

Contenu du snippet

Bonjour !

Voici ma première source en Python. Je le bosse depuis seulement quelques jours.
Ce code rassemble :
-récupérer une chaîne de caractère
-traiter une chaîne de caractère
-utiliser les boucles While
-utiliser le traitement par condition : if - elif - else
-utiliser les nombres aléatoires
-afficher des caractères

Ce code permet, de récupérer une chaîne de caractère et de la tranformer en language leetspeak (leet speak --> elite speak --> wikipedia ^.^ ). En leet speak, chaque caractère peut correspondre à plusieurs caractères, pour cela, j'utilises les nobres aléatoires pour les définir.

Visionnez le code maintenant ;)
Vous pouvez aussi regarder la capture d'écran !

Bonne lecture, ou devrais-je dire : 80^//\/[- |3(7(_)|^&

Source / Exemple :


#!/usr/bin/python 

phrase = raw_input()
from random import randrange

x = ''
i = 0

while i < len(phrase):
	if (phrase[i] == 'A') or (phrase[i] == 'a'):
		r = randrange(1,7)
		if r == 1:
			x = x + '4'
		if r == 2:
			x = x + '/\\'
		if r == 3:
			x = x + '@'
		if r == 4:
			x = x + '^'
		if r == 5:
			x = x + 'aye'
		if r == 6:
			x = x + '/-\\'
		if r == 7:
			x = x + '|-\\'
	elif (phrase[i] == 'B') or (phrase[i] == 'b'):
		r = randrange(1,10)
		if r == 1:
			x = x + '8'
		if r == 2:
			x = x + '6'
		if r == 3:
			x = x + '13'
		if r == 4:
			x = x + 'P>'
		if r == 5:
			x = x + '|:'
		if r == 6:
			x = x + '!3'
		if r == 7:
			x = x + '(3'
		if r == 8:
			x = x + '/3'
		if r == 9:
			x = x + ')3'
		if r == 10:
			x = x + '|3'
	elif (phrase[i] == 'C') or (phrase[i] == 'c'):
		r = randrange(1,3)
		if r == 1:
			x = x + '['
		if r == 2:
			x = x + '('
		if r == 3:
			x = x + '<'
	elif (phrase[i] == 'D') or (phrase[i] == 'd'):
		r = randrange(1,8)
		if r == 1:
			x = x + ')'
		if r == 2:
			x = x + '[)'
		if r == 3:
			x = x + 'I>'
		if r == 4:
			x = x + '|>'
		if r == 5:
			x = x + '?'
		if r == 6:
			x = x + 'T)'
		if r == 7:
			x = x + '|)'
		if r == 8:
			x = x + '0'
	elif (phrase[i] == 'E') or (phrase[i] == 'e'):
		r = randrange(1,4)
		if r == 1:
			x = x + '3'
		if r == 2:
			x = x + '&'
		if r == 3:
			x = x + '[-'
		if r == 4:
			x = x + '|=-'
	elif (phrase[i] == 'F') or (phrase[i] == 'f'):
		r = randrange(1,4)
		if r == 1:
			x = x + '|='
		if r == 2:
			x = x + '|#'
		if r == 3:
			x = x + 'ph'
		if r == 4:
			x = x + '/='
	elif (phrase[i] == 'G') or (phrase[i] == 'g'):
		r = randrange(1,7)
		if r == 1:
			x = x + '6'
		if r == 2:
			x = x + '&'
		if r == 3:
			x = x + '(_+'
		if r == 4:
			x = x + '9'
		if r == 5:
			x = x + 'C-'
		if r == 6:
			x = x + 'gee'
		if r == 7:
			x = x + '(y,'
	elif (phrase[i] == 'H') or (phrase[i] == 'h'):
		r = randrange(1,12)
		if r == 1:
			x = x + '#'
		if r == 2:
			x = x + '/-/'
		if r == 3:
			x = x + '[-]'
		if r == 4:
			x = x + ']-['
		if r == 5:
			x = x + ')-('
		if r == 6:
			x = x + '(-)'
		if r == 7:
			x = x + ':-:'
		if r == 8:
			x = x + '|~|'
		if r == 9:
			x = x + '|-|'
		if r == 10:
			x = x + ']~['
		if r == 11:
			x = x + '}{'
		if r == 12:
			x = x + '}-{'
	elif (phrase[i] == 'I') or (phrase[i] == 'i'):
		r = randrange(1,6)
		if r == 1:
			x = x + '1'
		if r == 2:
			x = x + '!'
		if r == 3:
			x = x + '|'
		if r == 4:
			x = x + 'eye'
		if r == 5:
			x = x + '3y3'
		if r == 6:
			x = x + ']'
	elif (phrase[i] == 'J') or (phrase[i] == 'j'):
		r = randrange(1,4)
		if r == 1:
			x = x + '_|'
		if r == 2:
			x = x + '_/'
		if r == 3:
			x = x + '</'
		if r == 4:
			x = x + '(/'
	elif (phrase[i] == 'K') or (phrase[i] == 'k'):
		r = randrange(1,4)
		if r == 1:
			x = x + '|{'
		if r == 2:
			x = x + '|<'
	elif (phrase[i] == 'L') or (phrase[i] == 'l'):
		r = randrange(1,5)
		if r == 1:
			x = x + '1'
		if r == 2:
			x = x + '7'
		if r == 3:
			x = x + '1_'
		if r == 4:
			x = x + '|'
		if r == 5:
			x = x + '|_'
	elif (phrase[i] == 'M') or (phrase[i] == 'm'):
		r = randrange(1,14)
		if r == 1:
			x = x + '|v|'
		if r == 2:
			x = x + '[V]'
		if r == 3:
			x = x + '{V}'
		if r == 4:
			x = x + '|\\/]'
		if r == 5:
			x = x + '/\\/\\'
		if r == 6:
			x = x + '(u)'
		if r == 7:
			x = x + '(v)'
		if r == 8:
			x = x + '(\\/)'
		if r == 9:
			x = x + '/|\\'
		if r == 10:
			x = x + '^^'
		if r == 11:
			x = x + '/|/|'
		if r == 12:
			x = x + '//.'
		if r == 13:
			x = x + '.\\\\'
		if r == 14:
			x = x + '/^^\\'
	elif (phrase[i] == 'N') or (phrase[i] == 'n'):
		r = randrange(1,10)
		if r == 1:
			x = x + '^/'
		if r == 2:
			x = x + '|v'
		if r == 3:
			x = x + '|\\|'
		if r == 4:
			x = x + '/\\/'
		if r == 5:
			x = x + '[\\]'
		if r == 6:
			x = x + '<\\>'
		if r == 7:
			x = x + '{\\}'
		if r == 8:
			x = x + '[]\\'
		if r == 9:
			x = x + '// []'
		if r == 10:
			x = x + '/V'
	elif (phrase[i] == 'O') or (phrase[i] == 'o'):
		r = randrange(1,4)
		if r == 1:
			x = x + '0'
		if r == 2:
			x = x + '()'
		if r == 3:
			x = x + 'oh'
		if r == 4:
			x = x + '[]'
	elif (phrase[i] == 'P') or (phrase[i] == 'p'):
		r = randrange(1,8)
		if r == 1:
			x = x + '|*'
		if r == 2:
			x = x + '|o'
		if r == 3:
			x = x + '|^(o)'
		if r == 4:
			x = x + '|>'
		if r == 5:
			x = x + '|"'
		if r == 6:
			x = x + '9'
		if r == 7:
			x = x + '[]D'
		if r == 8:
			x = x + '|7'
	elif (phrase[i] == 'Q') or (phrase[i] == 'q'):
		r = randrange(1,4)
		if r == 1:
			x = x + '(_,)'
		if r == 2:
			x = x + '()_'
		if r == 3:
			x = x + '0_'
		if r == 4:
			x = x + '<|'
	elif (phrase[i] == 'R') or (phrase[i] == 'r'):
		r = randrange(1,8)
		if r == 1:
			x = x + '2'
		if r == 2:
			x = x + '|?'
		if r == 3:
			x = x + '/2'
		if r == 4:
			x = x + '|^'
		if r == 5:
			x = x + 'lz'
		if r == 6:
			x = x + '[z'
		if r == 7:
			x = x + '12'
		if r == 8:
			x = x + '|2'
	elif (phrase[i] == 'S') or (phrase[i] == 's'):
		r = randrange(1,5)
		if r == 1:
			x = x + '5'
		if r == 2:
			x = x + '$'
		if r == 3:
			x = x + 'z'
		if r == 4:
			x = x + 'ehs'
		if r == 5:
			x = x + 'es'
	elif (phrase[i] == 'T') or (phrase[i] == 't'):
		r = randrange(1,4)
		if r == 1:
			x = x + '7'
		if r == 2:
			x = x + '+'
		if r == 3:
			x = x + '-|-'
		if r == 4:
			x = x + '1'
	elif (phrase[i] == 'U') or (phrase[i] == 'u'):
		r = randrange(1,4)
		if r == 1:
			x = x + '(_)'
		if r == 1:
			x = x + '|_|'
		if r == 3:
			x = x + 'v'
		if r == 4:
			x = x + ']_|'
	elif (phrase[i] == 'V') or (phrase[i] == 'v'):
		r = randrange(1,3)
		if r == 1:
			x = x + '\\/'
		if r == 1:
			x = x + '1/'
		if r == 1:
			x = x + '|/'
	elif (phrase[i] == 'W') or (phrase[i] == 'w'):
		r = randrange(1,9)
		if r == 1:
			x = x + '\\/\\/'
		if r == 2:
			x = x + 'vv'
		if r == 3:
			x = x + '\\^/'
		if r == 4:
			x = x + '(n)'
		if r == 5:
			x = x + '\\V/'
		if r == 6:
			x = x + '\\X/'
		if r == 7:
			x = x + '\\|/'
		if r == 8:
			x = x + '\\_|_/'
		if r == 9:
			x = x + '\\_:_/'
	elif (phrase[i] == 'X') or (phrase[i] == 'x'):
		r = randrange(1,4)
		if r == 1:
			x = x + '><'
		if r == 2:
			x = x + '}{'
		if r == 3:
			x = x + 'ecks'
		if r == 4:
			x = x + ')('
	elif (phrase[i] == 'Y') or (phrase[i] == 'y'):
		r = randrange(1,2)
		if r == 1:
			x = x + '\'/'
		if r == 2:
			x = x + ''
	elif (phrase[i] == 'Z') or (phrase[i] == 'z'):
		r = randrange(1,7)
		if r == 1:
			x = x + '2'
		if r == 2:
			x = x + '7_'
		if r == 3:
			x = x + '~/_'
		if r == 4:
			x = x + '%'
		if r == 5:
			x = x + '>_'
		if r == 6:
			x = x + '-\\_'
		if r == 7:
			x = x + '\'/_'
	elif (phrase[i] == ' '):
		x = x + ' '
	else:
		x = x + phrase[i]
	i = i + 1

print x

Conclusion :


Voilà !

N'hésitez pas à poster des commentaires pour m'aider à améliorer cette source !

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.