-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsele.py
104 lines (89 loc) · 3.77 KB
/
sele.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
92
93
94
95
96
97
98
99
100
101
102
103
104
#Automated morse code sender through morse chat interface
from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
MORSE_CODE_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':'--..',
'1':'.----', '2':'..---', '3':'...--',
'4':'....-', '5':'.....', '6':'-....',
'7':'--...', '8':'---..', '9':'----.',
'0':'-----', ',':'--..--', '.':'.-.-.-',
'?':'..--..', '/':'-..-.', '-':'-....-',
'(':'-.--.', ')':'-.--.-','!' : '---.',
':': '---...',"'" : '.----.','@' : '.--.-.',
'=' : '-...-'
}
browser = webdriver.Firefox()
browser.get('https://morsecode.me/?room=2#/rooms/3')
WebDriverWait(browser, 2).until(EC.presence_of_element_located((By.XPATH, "/html/body/div/div/div/div[3]/div")))
def encrypt(message):
cipher = ''
for letter in message :
if letter != ' ' and letter in MORSE_CODE_DICT:
cipher += MORSE_CODE_DICT[letter] + ' '
else:
cipher += ' '
return cipher
def decrypt(message):
message += ' '
decipher = ''
citext = ''
for letter in message:
if (letter != ' '):
i = 0 # counter to keep track of space
citext += letter # storing morse code of a single character
else: # in case of space
i += 1 # if i = 1 that indicates a new character
if i == 2 : # if i = 2 that indicates a new word
decipher += ' ' # adding space to separate words
else:
decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT # accessing the keys using their values (reverse of encryption)
.values()).index(citext)]
citext = ''
return decipher
shortT = 0.06
longT = 0.18
def send_morse(complete_message):
for message in complete_message:
for char in message:
if message == "." :
ActionChains(browser).key_down(Keys.SPACE).key_up(Keys.SPACE).perform()
time.sleep(0.01)
elif message == "-" : # LONG PRESS
ActionChains(browser).key_down(Keys.SPACE).perform()
time.sleep(longT)
ActionChains(browser).key_up(Keys.SPACE).perform()
time.sleep(0.01)
elif message == "*":
time.sleep(longT+0.1)
def main():
try:
message = "he llo world"
result = encrypt(message.upper())
message = result.replace(" ", "*")
testMessage = message.split()
while True:
for msg in testMessage:
send_morse(msg)
time.sleep(longT+0.12)
ActionChains(browser).key_down(Keys.RETURN).key_up(Keys.RETURN).perform()
message = input("enter your message: ")
result = encrypt(message.upper())
message = result.replace(" ", "*")
testMessage = message.split()
except KeyboardInterrupt :
print('Interrupted')
browser.quit()
if __name__ == "__main__":
main()