@MichaelFaulkner/

Encryption

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.15851859846844119","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyBwcmludHMgV2VsY29tZQpwcmludCgnV2VsY29tZSB0byB0aGUgZW5jcnlwdG9yLicpCiMgbGV0dGVycyBhbmQgc3ltYm9scwpsZXR0ZXJzID0gWwogICAgImEiLCAiYiIsICJjIiwgImQiLCAiZSIsICJmIiwgImciLCAiaCIsICJpIiwgImoiLCAiayIsICJsIiwgIm0iLCAibiIsICJvIiwKICAgICJwIiwgInEiLCAiciIsICJzIiwgInQiLCAidSIsICJ2IiwgInciLCAieCIsICJ5IiwgInoiLCAnICcsICcwJywgJzEnLCAnMicsCiAgICAnMycsICc0JywgJzUnLCAnNicsICc3JywgJzgnLCAnOScsICcuJywgJ0AnLCAnIycsICc/JywgJyQnLCAnIicsICc6JywgJywnLCAnIScKXQojIHRoZSBjeWJlcnRleHQgY291bnRlcnBhcnQgZm9yIHRoZSBsZXR0ZXJzIGFuZCBzeW1ib2xzCmN5cGhlcnRleHQgPSBbCiAgICAnSycsICdEJywgJ0cnLCAnRicsICdOJywgJ1MnLCAnTCcsICdWJywgJ0InLCAnVycsICdBJywgJ0gnLCAnRScsICdYJywgJ0onLAogICAgJ00nLCAnUScsICdDJywgJ1AnLCAnWicsICdSJywgJ1QnLCAnWScsICdJJywgJ1UnLCAnTycsICchJywgJzAnCiAgICAnOScsICc4JywgJzcnLCAnNicsICc1JywgJzQnLCAnMycsICcyJywgJzEnLCAnQCcsICcuJywgJz8nLCAnIycsICciJywgJyQnLAogICAgJywnLCAnOicsICd8JywgJyonCl0KIyBkZWZpbmVzIGVuY29kZQpkZWYgZW5jb2RlKG5vdGUpOgogICAgIyBuZXcgbm90ZSBpcyB0aGUgbGlzdCB0aGF0IGhhcyBldmVyeSBsZXR0ZXIgZnJvbSB0aGUgbm90ZSBpbiBpdAogICAgb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GVuY29kZSBvciBkZWNvZGUgYW5kIHNlZSB3aGF0IGhhcHBlbnMKd2hpbGUgKGxlbihtZW51Lmxvd2VyKCkpICE9ICdlbmNvZGUnIG9yIGxlbihtZW51Lmxvd2VyKCkpICE9ICdkZWNvZGUnKToKICAgIG1lbnUgPSBpbnB1dCgnV291bGQgeW91IGxpa2UgdG8gZW5jb2RlIG9yIGRlY29kZSBhIG5vdGU/ICcpCiAgICBpZiBtZW51Lmxvd2VyKCkgPT0gJ2RlY29kZSc6CiAgICAgICAgbm90ZSA9IGlucHV0KCdXaGF0IG5vdGUgd291bGQgeW91IGxpa2UgdG8gZGVjb2RlPyAnKQogICAgICAgIHByaW50KGRlY29kZShub3RlKSkKICAgIGVsaWYgbWVudS5sb3dlcigpID09ICdlbmNvZGUnOgogICAgICAgIG5vdGUgPSBpbnB1dCgnV2hhdCBub3RlIHdvdWxkIHlvdSBsaWtlIHRvIGVuY29kZT8gJykKICAgICAgICBwcmludChlbmNvZGUobm90ZSkpCiAgICBlbHNlOgogICAgICAgIGlmIGxlbihtZW51KSA+IDA6CiAgICAgICAgICAgIHByaW50KG1lbnUgKyAnIGlzIG5vdCBhbiBhY2NlcHRhYmxlIGFjdGlvbi4gUGxlYXNlIHRyeSBhZ2Fpbi4nKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHByaW50KCdZb3UgbXVzdCBlbnRlciBhIGNvbW1hbmQnKQoK"},"asBuffer":null},"loaded":true}}
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')