@malvoliothegood/

Encryption -using-a-dictionary

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9863096927481954","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyBwcmludHMgV2VsY29tZQpwcmludCgpCnByaW50KCdXZWxjb21lIHRvIHRoZSBlbmNyeXB0b3InKQpwcmludCgiPSIqMjQpCiMgbGV0dGVycyBhbmQgdGhlaXIgY29ycmVzcG9uZGluZyBjb3VudGVycGFydHMKIyBzdG9yZWQgaW4gYSBkaWN0aW9uYXJ5IyBSZWY6IGh0dHBzOi8vd3d3LmRpdmVpbnRvLm9yZy9weXRob24zL25hdGl2ZS1kYXRhdHlwZXMuaHRtbAplbmNvZGluZyA9IHsKICAiYSI6ICdLJywKICAiYiI6ICJEIiwKICAiYyI6ICJHIiwKICAiZCI6ICJGIiwKICAiZSI6ICJOIiwKICAiZiI6ICJTIiwKICAiZyI6ICJMIiwKICAiaCI6ICJWIiwKICAiaSI6ICJCIiwKICAiaiI6ICJXIiwKICAiayI6ICJBIiwKICAibCI6ICJIIiwKICAibSI6ICJFIiwKICAibiI6ICJYIiwKICAibyI6ICJKIiwKICAicCI6ICJNIiwKICAicSI6ICJRIiwKICAiciI6ICJDIiwKICAicyI6ICJQIiwKICAidCI6ICJaIiwKICAidSI6ICJSIiwKICAidiI6ICJUIiwKICAidyI6ICJZIiwKICAieCI6ICJJIiwKICAieSI6ICJVIiwKICAieiI6ICJPIiwKICAiICI6ICIhIiwKICAiMCI6ICI5IiwKICAiMSI6ICI4IiwKICAiMiI6ICI3IiwKICAiMyI6ICI2IiwKICAiNCI6ICI1IiwKICAiNSI6ICI0IiwKICAiNiI6ICIzIiwKICAiNyI6ICIyIiwKICAiOCI6ICIxIiwKICAiOSI6ICIwIiwKICAiLiI6ICJAIiwKICAiQCI6ICIuIiwKICAiPyI6ICIjIiwKICAiIyI6ICI/IiwKICAiJCI6ICciJywKICAnIic6ICIkIiw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2VwdCBWYWx1ZUVycm9yOgogICAgICBwcmludCgnTm9uLW51bWVyaWMgaW5wdXQhIFRyeSBhZ2FpbicpCiAgICAgICMgRW5zdXJlIHByb2dyYW0gZXhpdHMKICAgICAgY2hvaWNlID0gMwoKICAgIGlmIGNob2ljZSA9PSBFTkNPREU6CiAgICAgIG5vdGUgPSBpbnB1dCgnV2hhdCBub3RlIHdvdWxkIHlvdSBsaWtlIHRvIGVuY29kZT8gJykgIAogICAgICBlbmNvZGVkX25vdGUgPSBlbmNvZGUobm90ZS5sb3dlcigpKSAKICAgICAgcHJpbnQoIkVuY29kZWQgbm90ZToiLCBlbmNvZGVkX25vdGUpICAKICAgIGVsaWYgY2hvaWNlID09IERFQ09ERToKICAgICAgbm90ZSA9IGlucHV0KCdXaGF0IG5vdGUgd291bGQgeW91IGxpa2UgdG8gZGVjb2RlPyAnKSAKICAgICAgZGVjb2RlZF9ub3RlID0gZGVjb2RlKG5vdGUubG93ZXIoKSkKICAgICAgcHJpbnQoIkRlY29kZWQgbm90ZToiLCBkZWNvZGVkX25vdGUpICAgCiAgICBlbGlmIGNob2ljZSA9PSBFWElUOiAgICAgICAgCiAgICAgIHByaW50KCdFeGl0aW5nLi4uJykKICAgIGVsc2U6IAogICAgICBwcmludCgnSWNvcnJlY3QgY2hvaWNlLCBleGl0aW5nLi4uJykK"},"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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# prints Welcome
print()
print('Welcome to the encryptor')
print("="*24)
# letters and their corresponding counterparts
# stored in a dictionary# Ref: https://www.diveinto.org/python3/native-datatypes.html
encoding = {
  "a": 'K',
  "b": "D",
  "c": "G",
  "d": "F",
  "e": "N",
  "f": "S",
  "g": "L",
  "h": "V",
  "i": "B",
  "j": "W",
  "k": "A",
  "l": "H",
  "m": "E",
  "n": "X",
  "o": "J",
  "p": "M",
  "q": "Q",
  "r": "C",
  "s": "P",
  "t": "Z",
  "u": "R",
  "v": "T",
  "w": "Y",
  "x": "I",
  "y": "U",
  "z": "O",
  " ": "!",
  "0": "9",
  "1": "8",
  "2": "7",
  "3": "6",
  "4": "5",
  "5": "4",
  "6": "3",
  "7": "2",
  "8": "1",
  "9": "0",
  ".": "@",
  "@": ".",
  "?": "#",
  "#": "?",
  "$": '"',
  '"': "$",
  ":": ",",
  ",": ":"
  }

# defines encode
def encode(note):  
  encoded_note = ""
  for char in note:
    encoded_note += encoding[char];
  return encoded_note

# # defines decode
def decode(encoded_note):  
  decoded_note = ""
  for char in encoded_note:
    for key, value in encoding.items():     
      if value.lower() == char:
        decoded_note += key
        continue    
  return decoded_note


# menu
EXIT = 0
ENCODE = 1
DECODE = 2
# Initial choice to start loop
choice = ENCODE

while (choice == 1 or choice == 2):
    choice = input('Would you like to encode or decode a note? (Enter 1 to encode, 2 to decode and 0 to exit): ')
    # choice is a string so convert it to an integer
    # non-numeric input will throw an exception when
    # choice is cast to an integer
    try:
      choice = int(choice)
    except ValueError:
      print('Non-numeric input! Try again')
      # Ensure program exits
      choice = 3

    if choice == ENCODE:
      note = input('What note would you like to encode? ')  
      encoded_note = encode(note.lower()) 
      print("Encoded note:", encoded_note)  
    elif choice == DECODE:
      note = input('What note would you like to decode? ') 
      decoded_note = decode(note.lower())
      print("Decoded note:", decoded_note)   
    elif choice == EXIT:        
      print('Exiting...')
    else: 
      print('Icorrect choice, exiting...')