import random

# HW3-1

# Task 1 - Review
# There are 20 steps.
# 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, with 0 as its value, into this dictionary,
#   and print the value associated with '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 iterates over "alphabet", increasing the value of
#   "count" by 1 every iteration.



#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 the alphabet and does the following:
#   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, and in each iteration...
#   Adds the letter to the dictionary as a key, with the count as its value...
#   And increases count by 1.



#10.Iterate through the dictionary and 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), and in each iteration
#   Put a new key-value pair in the new dictionary (numberToLetter), but with
#   the relation reversed: the values in the old dictionary are the keys in the
#   new one, and the keys in the old dictionary are the corresponding values in
#   the new one.



#13.We will use these two dictionaries to encrypt a secret message.
#   First create a variable called SECRET_KEY, with an integer value
#   of your choice.



#14.Suppose we want to encrypt the letter 'e'.
#   First, find its value in letterToNumber, and store it as a
#   variable called "e_num".



#15.Next, add the value of your SECRET_KEY to "e_num",
#   and call the result "e_num2".



#16.Find the remainder of "e_num2" divided by 26 by using the % operator.
#   Call this value "wrapped_e_num2".



#17.Find the value of "wrapped_e_num2" in numberToLetter, call it "encoded_e".
#   This is the encryption of letter 'e' under your SECRET_KEY.
#   What would happen if SECRET_KEY were a multiple of 26?



#18.Finish the following encrypt() function. It takes a character and a
#   secret key, and it returns the letter's encryption (in the same way
#   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):
    if char in letterToNumber:
        pass # Remove this line and put your own code here instead.
        # You can use your letterToNumber and numberToLetter dictionaries in
        # the body of this function.
    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 define 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. Remember to use your encrypt function within encryptMsg!

def encryptMsg(msg, sk):
    
    #TODO

    return 'implement me...'


# Test your encryption function:
print encryptMsg('Attack Pearl Harbor at dawn of the Seventh of December', 353)


# Task 2 - Coinflipper
# Follow the instructions on the website.
def coinflipper():
    
    #TODO

    return 'implement me...'

