<commit_before>"""
cryptography.py
Author: Jeff
Credit: None

Assignment:

Write and submit a program that encrypts and decrypts user data.

See the detailed requirements at https://github.com/HHS-IntroProgramming/Cryptography/blob/master/README.md
"""
action_ = "goahead"
while action_ != "q":
    associations = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .,:;'\"/\\<>(){}[]-=_+?!"
    n_num = []
    new_n = []
    action = input("Enter e to encrypt, d to decrypt, or q to quit: ")
    action_ = action
    if action == "e":
        message = input("Message: ")
        key = input("Key: ")
    
        messagE = list(message)   #message
        n = len(message)        #how many letters
        n_num = [associations.find(x) for x in messagE]  #transformed into numbers
    
        keY = list(key)     #key
        m = len(key)        #how many
        M = m               #a copy
        m_num = [associations.find(x) for x in keY]   #transformed into numbers
    
        while n > 0:
            new_num = n_num[-n] + m_num[-m]
            while new_num > 84:
                new_num -= 85
            new_n.append(new_num)
            m -= 1
            n -= 1
            if m == 0:
                m = M

        new_message = [associations[x] for x in new_n]
        print("".join(new_message))
 
    elif action == "d":
        message = input("Message: ")
        key = input("Key: ")
    
        messagE = list(message)   #message
        n = len(message)        #how many letters
        n_num = [associations.find(x) for x in messagE]  #transformed into numbers
    
        keY = list(key)     #key
        m = len(key)        #how many
        M = m               #a copy
        m_num = [associations.find(x) for x in keY]   #transformed into numbers
    
        while n > 0:
            new_num = n_num[-n] - m_num[-m]
            while new_num < 0:
                new_num = 85 + new_num
            new_n.append(new_num)
            m -= 1
            n -= 1
            if m == 0:
                m = M
             
        new_message = [associations[x] for x in new_n]
        print("".join(new_message))

    else:
        print("Did not understand command, try again.")
print("Goodbye!")


<commit_msg>Updated from Brython Server: 9/29/2015 3:14:23 PM<commit_after>"""
cryptography.py
Author: Jeff
Credit: None

Assignment:

Write and submit a program that encrypts and decrypts user data.

See the detailed requirements at https://github.com/HHS-IntroProgramming/Cryptography/blob/master/README.md
"""
action_ = "goahead"
while action_ != "q":
    associations = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .,:;'\"/\\<>(){}[]-=_+?!"
    n_num = []
    new_n = []
    action = input("Enter e to encrypt, d to decrypt, or q to quit: ")
    action_ = action
    if action == "e":
        message = input("Message: ")
        key = input("Key: ")
    
        messagE = list(message)   #message
        n = len(message)        #how many letters
        n_num = [associations.find(x) for x in messagE]  #transformed into numbers
    
        keY = list(key)     #key
        m = len(key)        #how many
        M = m               #a copy
        m_num = [associations.find(x) for x in keY]   #transformed into numbers
    
        while n > 0:
            new_num = n_num[-n] + m_num[-m]
            while new_num > 84:
                new_num -= 85
            new_n.append(new_num)
            m -= 1
            n -= 1
            if m == 0:
                m = M

        new_message = [associations[x] for x in new_n]
        print("".join(new_message))
 
    elif action == "d":
        message = input("Message: ")
        key = input("Key: ")
    
        messagE = list(message)   #message
        n = len(message)        #how many letters
        n_num = [associations.find(x) for x in messagE]  #transformed into numbers
    
        keY = list(key)     #key
        m = len(key)        #how many
        M = m               #a copy
        m_num = [associations.find(x) for x in keY]   #transformed into numbers
    
        while n > 0:
            new_num = n_num[-n] - m_num[-m]
            while new_num < 0:
                new_num = 85 + new_num
            new_n.append(new_num)
            m -= 1
            n -= 1
            if m == 0:
                m = M
             
        new_message = [associations[x] for x in new_n]
        print("".join(new_message))

    else:
        print("Did not understand command, try again.")
        action_ = "goagain")
print("Goodbye!")



{'fraction_non_alphanumeric': 0.11480428602667833, 'fraction_numerical': 0.013557839492674393, 'mean_word_length': 1.6257175660160734, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1016127', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1456, 'n_words': 408}