-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
91 lines (91 loc) · 3.25 KB
/
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
82
83
84
85
86
87
88
89
90
91
# How it works:
# space ( ) shows a new character.
# Every new character has a value.
# duck (🦆) is worth 1
# corn (🌽) is worth 10
# lettuce (🥬) is worth 100
# The following are new and have not been added to the examples below yet.
# broccoli (🥦) is worth 5000
# strawberry (🍓) is worth 1000
# It checks how many strawberry it can subtract.
# Then, how many lettuce.
# Then, how many broccoli.
# Then, how many corn.
# Last, how many duck.
# Example:
# Duckify 'a'
# ord('a') = 97
# Duckified: '🌽🌽🌽🌽🌽🌽🌽🌽🌽🦆🦆🦆🦆🦆🦆🦆' 9 corn * 10 per corn = 90 + 7 duck * 1 per duck = 97
# -----
# Example:
# Duckify 'abc'
# ord('a') = 97
# ord('b') = 98
# ord('c') = 99
# Duckified: '🌽🌽🌽🌽🌽🌽🌽🌽🌽🦆🦆🦆🦆🦆🦆🦆 🌽🌽🌽🌽🌽🌽🌽🌽🌽🦆🦆🦆🦆🦆🦆🦆🦆 🌽🌽🌽🌽🌽🌽🌽🌽🌽🦆🦆🦆🦆🦆🦆🦆🦆🦆' # space ( ) is used to show a new character
def can_subtract(minuend, subtrahend):
return minuend - subtrahend >= 0
print("Please note that duckify_output.txt will be used for outputting both encode and decode. If you decode and use duckify_output.txt as input, it will be replaced with new contents.")
mode = input("Encode, EncodeFile, or Decode? ").lower()
if mode in ['encode', 'en', 'e', 'enco', 'encoded']:
toEncode = input("Enter string to encode: ")
output = ""
for char in toEncode:
charInt = ord(char)
while can_subtract(charInt, 1000):
output += '🍓'
charInt -= 1000
while can_subtract(charInt, 100):
output += '🥬'
charInt -= 100
while can_subtract(charInt, 50):
output += '🥦'
charInt -= 50
while can_subtract(charInt, 10):
output += '🌽'
charInt -= 10
while can_subtract(charInt, 1):
output += '🦆'
charInt -= 1
output += ' '
open("duckify_output.txt", "w").write(output)
print("Written to duckify_output.txt.")
elif mode in ['decode', 'de', 'd', 'deco', 'decoded']:
toDecode = input("Enter file name of string to decode (defualt is duckify_output.txt): ")
if toDecode == '': toDecode = 'duckify_output.txt'
chars = open(toDecode, "r").read().split()
output = ""
for char in chars:
value = 0
for emoji in char:
if emoji == "🥦": value += 5000
elif emoji == "🍓": value += 1000
elif emoji == "🥬": value += 100
elif emoji == "🌽": value += 10
elif emoji == "🦆": value += 1
output += chr(value)
open("duckify_output.txt", "w").write(output)
print("Written to duckify_output.txt.")
elif mode in ['encodefile', 'enfi', 'ef', 'encofile', 'encodedfile']:
toEncode = open(input("Enter file name of string to encode: "), "r").read()
output = ""
for char in toEncode:
charInt = ord(char)
while can_subtract(charInt, 5000):
output += '🥦'
charInt -= 5000
while can_subtract(charInt, 1000):
output += '🍓'
charInt -= 1000
while can_subtract(charInt, 100):
output += '🥬'
charInt -= 100
while can_subtract(charInt, 10):
output += '🌽'
charInt -= 10
while can_subtract(charInt, 1):
output += '🦆'
charInt -= 1
output += ' '
open("duckify_output.txt", "w").write(output)
print("Written to duckify_output.txt.")