@MichaelFaulkner/

Encryption

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# prints Welcome
print('Welcome to the encryptor.')
# letters and symbols
letters = [
    "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
    "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ' ', '0', '1', '2',
    '3', '4', '5', '6', '7', '8', '9', '.', '@', '#', '?', '$', '"', ':', ',', '!'
]
# the cybertext counterpart for the letters and symbols
cyphertext = [
    'K', 'D', 'G', 'F', 'N', 'S', 'L', 'V', 'B', 'W', 'A', 'H', 'E', 'X', 'J',
    'M', 'Q', 'C', 'P', 'Z', 'R', 'T', 'Y', 'I', 'U', 'O', '!', '0'
    '9', '8', '7', '6', '5', '4', '3', '2', '1', '@', '.', '?', '#', '"', '$',
    ',', ':', '|', '*'
]
# defines encode
def encode(note):
    # new note is the list that has every letter from the note in it
    new_note = []
    # this note is the encoded note list
    encoded_note = []
    # this note is the encoded note that is put into a string
    last_note = ''
    # sets the value of count
    count = 0
    #iterates through the note and adds each letter to the list 'new_note'
    while count != len(note):
        new_note.append(note[count].lower())
        count += 1
    print('Encoding note...')
    # iterates through the new_note
    for i in new_note:
        # iterates through letters
        for letter in letters:
            # if i(the letter in new note) equals the letter in letters, it will add the equivilant cyphertext letter
            if i == letter:
                encoded_note.append(cyphertext[letters.index(letter)])
    # turns encoded_note into a string
    for i in encoded_note:
        last_note += i
    # returns the encoded note
    return note + ' = ' + last_note


# defines decode - which does the same thing as encode but the opposite - takes the cuphertext letter and then replaces it with the actual letter equivilant
def decode(note):
    new_note = []
    decoded_note = []
    last_note = ''
    count = 0
    while count != len(note):
        new_note.append(note[count].lower())
        count += 1
    print('Decoding note...')
    for i in new_note:
        for x in cyphertext:
            if i == x.lower():
                decoded_note.append(letters[cyphertext.index(x)])
    for i in decoded_note:
        last_note += i
    return note + ' = ' + last_note


# starts the menu
menu = ''
# while the input does not equal one of the 2 options it will ask you for an input - try inputing something other then encode or decode and see what happens
while (len(menu.lower()) != 'encode' or len(menu.lower()) != 'decode'):
    menu = input('Would you like to encode or decode a note? ')
    if menu.lower() == 'decode':
        note = input('What note would you like to decode? ')
        print(decode(note))
    elif menu.lower() == 'encode':
        note = input('What note would you like to encode? ')
        print(encode(note))
    else:
        if len(menu) > 0:
            print(menu + ' is not an acceptable action. Please try again.')
        else:
            print('You must enter a command')