Problems with a leet speak converter

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Problems with a leet speak converter

 
0
  #1
Oct 30th, 2009
I tried to make a leet speak converter, but it outputs characters that I don't even tell it to..

This is what I mean:

(Test run)
Enter something to convert to L337 5P34K: Hi, how are you?
L337 5P34K equivilent: hi,@H0w 4R3 Y0u?

I don't know why it's got the '@' there.

This is the code:

  1. #L33TSP34K Converter.
  2.  
  3. import random as rnd
  4.  
  5. def toUpper(string):
  6. string_upper = ""
  7. for char in string :
  8. if ord(char) < 97 :
  9. string_upper += char
  10. elif ord(char) >= 97 :
  11. string_upper += chr(ord(char) - 32)
  12. return string_upper
  13.  
  14. def toLower(string):
  15. string_lower = ""
  16. for char in string :
  17. if ord(char) > 97 :
  18. string_lower += char
  19. elif ord(char) <= 97:
  20. string_lower += chr(ord(char) + 32 )
  21. return string_lower
  22.  
  23. def convertToLeetSpeak(src):
  24. string = src
  25. for c in src:
  26. if c == 'e' or c == 'E':
  27. string += '3'
  28. elif c == 'a' or c == 'A':
  29. string += '4'
  30. elif c == 't' or c == 'T':
  31. string += '7'
  32. elif c == 's' or c == 'S':
  33. string += '5'
  34. elif c == 'o' or c == 'O':
  35. string += '0'
  36. else:
  37. i = rnd.randrange(1,3)
  38. if i == 1:
  39. string += toUpper(c)
  40. elif i == 2:
  41. string += toLower(c)
  42. return string
  43.  
  44. def main():
  45. choice = raw_input("Enter something to convert to L337 5P34K: ")
  46. choice = convertToLeetSpeak(choice).replace(choice, '')
  47. print 'L337 5P34K equivilent:',choice
  48.  
  49. if __name__ == '__main__':
  50. main()
...
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 56
Reputation: willygstyle is an unknown quantity at this point 
Solved Threads: 6
willygstyle willygstyle is offline Offline
Junior Poster in Training
 
0
  #2
Oct 30th, 2009
I think it is because you have to be leet to run that code . J/K...
  1. while count < 256:
  2. print(chr(count), count)
  3. count += 1
If you run that then look at line 10 of your script you will see where it came from.
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Python Forum


Views: 206 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC