Difference between revisions of "Leet-speak Translator"

From WLCS
 
(9 intermediate revisions by the same user not shown)
Line 6: Line 6:
  
 
'''References:'''
 
'''References:'''
* [http://en.wikipedia.org/wiki/Leet Leet Speak Wikipedia]
+
* [http://en.wikipedia.org/wiki/Leet Leetspeak Wikipedia]
 +
* [[Leetspeak alphabet]]
 +
* [[Media:Strings_Python.pptx]]
 +
* [http://openbookproject.net/thinkcs/python/english2e/ch07.html Strings]
 
* [http://openbookproject.net/thinkcs/python/english2e/ch03.html Functions]
 
* [http://openbookproject.net/thinkcs/python/english2e/ch03.html Functions]
 
* [http://openbookproject.net/thinkcs/python/english2e/ch04.html Conditionals (if-statements)]
 
* [http://openbookproject.net/thinkcs/python/english2e/ch04.html Conditionals (if-statements)]
 
* [http://openbookproject.net/thinkcs/python/english2e/ch06.html Iteration (while loops)]
 
* [http://openbookproject.net/thinkcs/python/english2e/ch06.html Iteration (while loops)]
* [http://openbookproject.net/thinkcs/python/english2e/ch07.html Strings]
 
  
 
'''Directions:'''
 
'''Directions:'''
 
# Open a new python file and name is '''leetTranslator.py'''
 
# Open a new python file and name is '''leetTranslator.py'''
# In a separate textfile, bring up your leet alpha reference card
+
# Bring up the [[Leetspeak alphabet]]
 +
# Choose an leetspeak character for each letter of the alphabet
 
# Define a function named '''getLetter(ch)''' that takes one parameter.  Inside the definition of getLetter(), you will check to see what letter '''ch''' is, and then '''return''' the corresponding leet character.  See the example code below and complete it with the rest of the alphabet
 
# Define a function named '''getLetter(ch)''' that takes one parameter.  Inside the definition of getLetter(), you will check to see what letter '''ch''' is, and then '''return''' the corresponding leet character.  See the example code below and complete it with the rest of the alphabet
#* At the end of the '''getLetter(ch)''' function, as a fail-safe precaution, '''return ch'''
+
#* If you are returning anything that has a backslash "\", then you need to use '''two''' backslashes "\\" instead of just one
 +
#* At the end of the '''getLetter(ch)''' function, '''return ch''' in case none of the letters matched
  
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
Line 30: Line 34:
 
# Initialize a new variable named '''newWord''' to an empty string ""
 
# Initialize a new variable named '''newWord''' to an empty string ""
 
# Write a loop that traverses the '''word''' string
 
# Write a loop that traverses the '''word''' string
## Inside the loop, translate the current letter (word[x]) by using the '''getLetter(word[x])''' AND add it to '''newWord''' (HINT: use the warmup we did before)
+
## Inside the loop, translate the current letter (word[x]) by using the '''getLetter(word[x])''' AND add it to '''newWord''' (HINT: you are building the newWord string letter by letter)
 
# After the loop, '''newWord''' should contain a translation of every letter.  Print out '''newWord'''
 
# After the loop, '''newWord''' should contain a translation of every letter.  Print out '''newWord'''
  
 
'''Advanced Features:'''
 
'''Advanced Features:'''
# Update '''getLetter()''' so that it is able to handle spaces and punctuation
+
* Update '''getLetter()''' so that it is able to handle spaces and punctuation
# Can you create a reverse translator?
+
* Convert your program to use a dictionary instead of a function to translate letters
 +
* Prompt the user for an obfuscation level (0-10), and translate the plain text to leet-speak based on the obfuscation level (HINT: use random a number generator)
 +
* Can you create a reverse translator? (this is much trickier)

Latest revision as of 12:26, 26 January 2017

Objectives:

  • You will create a string translator that converts from regular characters to leetspeak characters
  • You will use while loops to traverse (walk-through) a string
  • You will use if-statements to check for particular letters
  • You will use functions to retrieve the corresponding leetspeak characters

References:

Directions:

  1. Open a new python file and name is leetTranslator.py
  2. Bring up the Leetspeak alphabet
  3. Choose an leetspeak character for each letter of the alphabet
  4. Define a function named getLetter(ch) that takes one parameter. Inside the definition of getLetter(), you will check to see what letter ch is, and then return the corresponding leet character. See the example code below and complete it with the rest of the alphabet
    • If you are returning anything that has a backslash "\", then you need to use two backslashes "\\" instead of just one
    • At the end of the getLetter(ch) function, return ch in case none of the letters matched
def getLetter(ch):
    if ch == "a":
        return "@"
    if ch == "b":
        return "l8"
    # add the rest of your alphabet here
  1. After the function definition, prompt the user to enter a word and store it in a variable named word
  2. Initialize a new variable named newWord to an empty string ""
  3. Write a loop that traverses the word string
    1. Inside the loop, translate the current letter (word[x]) by using the getLetter(word[x]) AND add it to newWord (HINT: you are building the newWord string letter by letter)
  4. After the loop, newWord should contain a translation of every letter. Print out newWord

Advanced Features:

  • Update getLetter() so that it is able to handle spaces and punctuation
  • Convert your program to use a dictionary instead of a function to translate letters
  • Prompt the user for an obfuscation level (0-10), and translate the plain text to leet-speak based on the obfuscation level (HINT: use random a number generator)
  • Can you create a reverse translator? (this is much trickier)