# HW3-2 Python Parade

# There are 20 tasks, most of them are really short, requiring one statement each.


#--------------------------------------------------------------#
#---------------------------- READY? --------------------------#
#----------------------------    3   --------------------------#
#----------------------------    2   --------------------------#
#----------------------------    1   --------------------------#
#----------------------------   GO!  --------------------------#
#--------------------------------------------------------------#


#1. Create an empty dictionary called letterToNumber



#2. Add 'a' as a key and 0 as its value into this dictionary
#   and print the value of 'a' in this dictionary.


# I've created a variable called alphabet that is a string of all English letters in order
alphabet = 'abcdefghijklmnopqrstuvwxyz'



#3. Create a variable called count with value 0


#4. Write a for loop that iterate over alphabet, every time increases the value
#   of count by 1


#5. Print count. You should see 26


#6. Now write a for loop that goes over all letters in alphabet one by one,
#   and print the letter every time.


#7. Reset count to 0


#8. Write a for loop that goes over alphabet, each time:
#   print the letter and the count on the same line, and increase count by 1
#   Here is how you print multiple things on one line:
print('a:', 0)
print('Letter a is the', 0, 'th letter in English')

#9. Now we want to add 'b':1, 'c':2, ..., 'z':25 to this dictionary.
#   First reset the count. Then
#   Write a for loop that goes over alphabet, each time:
#   Add the letter with the count to the dictionary and increase count by 1.


#10.Iterate through the dictionary,
#   print each key with its value on the same line each time


#11.Create a new empty dictionary called numberToLetter


#12.Iterate through the first dictionary(letterToNumber), each time
#   Put a key with its value in the new dictionary, but reverse the relation
#   That is, the value becomes a key and the key becomes the value


#13.We will use these two dictionaries to encrypt a secret message.
#   First create a variable calle SECRET_KEY, with an integer value of your choice


#14.Suppose we want to encrypt the letter 'e'.
#   First, find its value in letterToNumber, call it e_n


#15.Next, add your SECRET_KEY to e_n, and call the result e_n2


#16.Find the remainder of e_n2 divided by 26. And call it r_e_n(Remember what does % do?)


#17.Find the value of r_e_n in numberToLetter, call it encoded_e. This is the encryption
#   of letter 'e' under your SECRET_KEY.
#   Avoid any number that is a multiple of 26


#18.Finish the following function called encrypt, that takes a character and a secret key,
#   returns the letter's encryption in the same fashion as you encrypted the letter 'e'.
#   If the char is not a letter, i.e., not a key in
#   letterToNumber, just return it unmodified.

def encrypt(char, sk):
    global numberToLetter, letterToNumber # this lets you use thees two dictionaries defined outside of your function
    if char in letterToNumber:
        pass #TODO
    else:
        return char # if char is not a letter, do not modify it 

# Now let's encrypt the following message. I've made it lowercase for you
message = '''Moby-Dick; or, The Whale, written by American author Herman Melville
and first published in 1851, is widely considered to be a Great American Novel and
a treasure of world literature. The story tells the adventures of the wandering
sailor Ishmael, and his voyage on the whaleship Pequod, commanded by Captain Ahab.
Ishmael soon learns that on this voyage Ahab has one purpose,
to seek out a specific whale: Moby Dick, a ferocious, enigmatic white sperm whale.
In a previous encounter, the whale destroyed Ahab's boat and bit off his leg,
which now drives Ahab to take revenge.'''
message = message.lower()

#19. First defined an empty string called encryptedMessage.
#    Iterate through message, for each character, encrypt it using SECRET_KEY,
#    And append the encrypted character to encryptedMessage.
#    Finally, print your encrypted message and see what it's like!


#20. Write a function, called encryptMsg, that takes a string and a secret key,
#    and returns the encrypted message.

def encryptMsg(msg, sk):
    global numberToLetter, letterToNumber

    #TODO

    return 'implement me...'



# Test your encryption function:
print(encryptMsg('Attack Pearl Harbor on the dawn of the Seventh of December', 353))








