-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathprompt_manipulation_tools.py
More file actions
268 lines (232 loc) · 6.15 KB
/
prompt_manipulation_tools.py
File metadata and controls
268 lines (232 loc) · 6.15 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
def prompt_encoder(prompt, encoding=""):
"""
Encode the prompt using the specified encoding.
If no encoding is specified, a random encoding method will be chosen.
"""
import random
# List of all available encoding methods
encoding_methods = [
"atbash",
"caesar",
"vigenere",
"braille",
"morse",
"pig_latin",
"leet",
"binary",
"hex",
"base64",
"rot13",
"reverse",
]
# If no encoding specified, randomly choose one
if encoding == "":
encoding = random.choice(encoding_methods)
print(f"Randomly selected encoding method: {encoding}")
if encoding == "atbash":
return atbash_encode(prompt)
elif encoding == "caesar":
return caesar_encode(prompt, 3) # Example shift value
elif encoding == "vigenere":
return vigenere_encode(prompt, "KEY") # Example key
elif encoding == "braille":
return braille_encode(prompt)
elif encoding == "morse":
return morse_encode(prompt)
elif encoding == "pig_latin":
return pig_latin_encode(prompt)
elif encoding == "leet":
return leet_encode(prompt)
elif encoding == "binary":
return binary_encode(prompt)
elif encoding == "hex":
return hex_encode(prompt)
elif encoding == "base64":
return base64_encode(prompt)
elif encoding == "rot13":
return rot13_encode(prompt)
elif encoding == "reverse":
return reverse_encode(prompt)
else:
raise ValueError("Unsupported encoding type.")
def atbash_encode(text):
"""
Encode the text using the Atbash cipher.
"""
alphabet = "abcdefghijklmnopqrstuvwxyz"
reversed_alphabet = alphabet[::-1]
translation_table = str.maketrans(alphabet, reversed_alphabet)
return text.translate(translation_table)
def caesar_encode(text, shift):
"""
Encode the text using the Caesar cipher.
"""
def shift_alphabet(alphabet, shift):
return alphabet[shift:] + alphabet[:shift]
alphabet = "abcdefghijklmnopqrstuvwxyz"
shifted_alphabet = shift_alphabet(alphabet, shift)
translation_table = str.maketrans(alphabet, shifted_alphabet)
return text.translate(translation_table)
def vigenere_encode(text, key):
"""
Encode the text using the Vigenère cipher.
"""
def generate_vigenere_table():
alphabet = "abcdefghijklmnopqrstuvwxyz"
table = []
for i in range(len(alphabet)):
row = alphabet[i:] + alphabet[:i]
table.append(row)
return table
def vigenere_encrypt(text, key):
table = generate_vigenere_table()
encrypted_text = []
key_length = len(key)
for i, char in enumerate(text):
if char.isalpha():
row = ord(key[i % key_length]) - ord("a")
col = ord(char) - ord("a")
encrypted_char = table[row][col]
encrypted_text.append(encrypted_char)
else:
encrypted_text.append(char)
return "".join(encrypted_text)
return vigenere_encrypt(text.lower(), key.lower())
def braille_encode(text):
"""
Encode the text using Braille.
"""
braille_dict = {
"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": "⠵",
}
return "".join(braille_dict.get(char, char) for char in text.lower())
def morse_encode(text):
"""
Encode the text using Morse code.
"""
morse_dict = {
"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": "--..",
}
return "".join(morse_dict.get(char, char) for char in text.lower())
def pig_latin_encode(text):
"""
Encode the text using Pig Latin.
"""
def pig_latin_word(word):
if word[0] in "aeiou":
return word + "yay"
else:
return word[1:] + word[0] + "ay"
words = text.split()
pig_latin_words = [pig_latin_word(word) for word in words]
return " ".join(pig_latin_words)
def leet_encode(text):
"""
Encode the text using Leet Speak.
"""
leet_dict = {
"a": "4",
"b": "8",
"c": "<",
"d": "|)",
"e": "3",
"f": "|=",
"g": "9",
"h": "#",
"i": "1",
"j": "_|",
"k": "|<",
"l": "|_",
"m": "/\\/\\",
"n": "^/",
"o": "0",
"p": "|*",
"q": "(,)",
"r": "|2",
"s": "5",
"t": "+",
"u": "|_|",
"v": "\\/",
"w": "\\^/",
"x": "%",
"y": "`/",
"z": "2",
}
return "".join(leet_dict.get(char, char) for char in text.lower())
def binary_encode(text):
"""
Encode the text using binary.
"""
return " ".join(format(ord(char), "08b") for char in text)
def hex_encode(text):
"""
Encode the text using hexadecimal.
"""
return " ".join(format(ord(char), "02x") for char in text)
def base64_encode(text):
"""
Encode the text using Base64.
"""
import base64
return base64.b64encode(text.encode()).decode()
def rot13_encode(text):
"""
Encode the text using ROT13.
"""
import codecs
return codecs.encode(text, "rot_13")
def reverse_encode(text):
"""
Encode the text by reversing it.
"""
return text[::-1]