-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjumble.py
More file actions
51 lines (48 loc) · 1.45 KB
/
jumble.py
File metadata and controls
51 lines (48 loc) · 1.45 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
# https://medium.com/swlh/how-to-create-better-ui-for-your-python-scripts-60c71924fae3
def jumble(message,rotate=13):
AtoZ = range(ord('A'), ord('Z')+1)
atoz = range(ord('a'), ord('z')+1)
output = []
for letter in message:
ascii_val = ord(letter)
start = None
if ascii_val in AtoZ:
start = AtoZ[0]
elif ascii_val in atoz:
start = atoz[0]
if start:
alpha = ord(letter)-start
rotated = (alpha+rotate)%26
output.append(chr(start+rotated))
else:
output.append(letter)
return "".join(output)
def main_tkinter():
import tkinter as tk
def dojumble():
res.configure(text=entry.get()+" -> "+jumble(entry.get()))
w = tk.Tk()
lbl = tk.Label(w, text="Enter your message for jumbling below…")
lbl.pack(pady=10)
entry = tk.Entry(w)
entry.pack(pady=10)
tk.Button(w, text="Jumble", command=dojumble).pack(pady=10)
res = tk.Label(w)
res.pack(pady=10)
w.mainloop()
def main_cherrypy():
import cherrypy
import os
class Jumbler(object):
@cherrypy.expose
def jumble(self, message):
return jumble(message)
cherrypy.config.update( {
"server.socket_host": "0.0.0.0",
"server.socket_port": 9090,
} )
cherrypy.quickstart(Jumbler())
#http://localhost:9090/jumble?message=hello
if __name__ == "__main__":
#main_tkinter()
main_cherrypy()