def audio_enc(message): #Sound part sound1 = AudioSegment.from_ogg("audio_files/E.ogg") sound2 = AudioSegment.from_ogg("audio_files/T.ogg") text_in_morse = m(message.text).stringToMorse() silence = AudioSegment.silent(duration=500) silence_letter = AudioSegment.silent(duration=70) final_sound = AudioSegment.empty() for i in text_in_morse: if i == '.': final_sound += sound1 final_sound += silence_letter if i == '-': final_sound += sound2 final_sound += silence_letter if i == ' ': final_sound += silence final_sound.export("audio_files/joinedFile.ogg", format="ogg")
def handle_menu(message): #User check list #ID DB db_pref = open("user_pref.db", 'r+') db_lines = db_pref.read() db_pref.close() user_id = message.from_user.id try: db_lines.index(str(user_id)) print("Found ID: " + str(user_id)) except ValueError: print('New ID: ' + str(user_id)) db_pref_new = open("user_pref.db", 'a+') new_user = {"user_id": user_id, "qr": "1", "voice": '1', 'text': '1'} db_pref_new.write(str(new_user) + '\n') db_pref_new.close() #SETTINGS #QR try: if message.text == 'set_qr_code_send_false': db = open("user_pref.db", 'r+') db_lines = db.readlines() db.close() for user in db_lines: if user.find(str(user_id)) != -1: user_dict = ast.literal_eval(user) user_dict['qr'] = "0" db_lines[db_lines.index(user)] = str(user_dict) + '\n' open("user_pref.db", 'w').writelines(db_lines) bot.send_message(message.from_user.id, "Settings have been changed.") message = '' if message.text == 'set_qr_code_send_true': db = open("user_pref.db", 'r+') db_lines = db.readlines() db.close() for user in db_lines: if user.find(str(user_id)) != -1: user_dict = ast.literal_eval(user) user_dict['qr'] = "1" db_lines[db_lines.index(user)] = str(user_dict) + '\n' open("user_pref.db", 'w').writelines(db_lines) bot.send_message(message.from_user.id, "Settings have been changed.") message = '' #Voice if message.text == 'set_voice_send_false': db = open("user_pref.db", 'r+') db_lines = db.readlines() db.close() for user in db_lines: if user.find(str(user_id)) != -1: user_dict = ast.literal_eval(user) user_dict['voice'] = "0" db_lines[db_lines.index(user)] = str(user_dict) + '\n' open("user_pref.db", 'w').writelines(db_lines) bot.send_message(message.from_user.id, "Settings have been changed.") message = '' if message.text == 'set_voice_send_true': db = open("user_pref.db", 'r+') db_lines = db.readlines() db.close() for user in db_lines: if user.find(str(user_id)) != -1: user_dict = ast.literal_eval(user) user_dict['voice'] = "1" db_lines[db_lines.index(user)] = str(user_dict) + '\n' open("user_pref.db", 'w').writelines(db_lines) bot.send_message(message.from_user.id, "Settings have been changed.") message = '' #Text if message.text == 'set_text_send_false': db = open("user_pref.db", 'r+') db_lines = db.readlines() db.close() for user in db_lines: if user.find(str(user_id)) != -1: user_dict = ast.literal_eval(user) user_dict['text'] = "0" db_lines[db_lines.index(user)] = str(user_dict) + '\n' open("user_pref.db", 'w').writelines(db_lines) bot.send_message(message.from_user.id, "Settings have been changed.") message = '' if message.text == 'set_text_send_true': db = open("user_pref.db", 'r+') db_lines = db.readlines() db.close() for user in db_lines: if user.find(str(user_id)) != -1: user_dict = ast.literal_eval(user) user_dict['text'] = "1" db_lines[db_lines.index(user)] = str(user_dict) + '\n' open("user_pref.db", 'w').writelines(db_lines) bot.send_message(message.from_user.id, "Settings have been changed.") message = '' #Encoding encoded = m(message.text).stringToMorse() #Audio def audio_part(message): audio_enc(message) audio = open('audio_files/joinedFile.ogg', 'rb') return audio #QR part def qr_part(message): qr.add_data(encoded) qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") img_byte_arr = io.BytesIO() img.save(img_byte_arr, format='PNG') img_byte_arr = img_byte_arr.getvalue() return img_byte_arr #Text part def text_part(message): text_morse = encoded return text_morse #Bot send db = open("user_pref.db", 'r+') db_lines = db.readlines() db.close() for user in db_lines: if user.find(str(user_id)) != -1: user_dict = ast.literal_eval(user) if user_dict['text'] == '1': bot.send_message(message.chat.id, text_part(message)) if user_dict['voice'] == '1': bot.send_audio(message.chat.id, audio_part(message)) if user_dict['qr'] == '1': bot.send_photo(message.chat.id, qr_part(message)) print('Text message: ' + str(message.text)) except AttributeError: print('Error key')
from morse3 import Morse as m MORSE_CODE = { '.-':'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', '--..--':', ', '.-.-.-':'.', '..--..':'?', '-..-.':'/', '-....-':'-', '-.--.':'(', '-.--.-':')', '...---...':'SOS', } def decodeMorse(morse_code): #words=morse_code.strip().split(" ") words=[word.split(' ') for word in morse_code.strip().split(" ")] result ="" for word in words: for letter in word: result+=MORSE_CODE[letter] result+=" " return result.strip() print(m("MORSE HAS BEEN DECODED").stringToMorse())
from faker import Faker from morse3 import Morse as m fake = Faker() for x in range(5): print(m(fake.name()).stringToMorse())
while option == 'base64' or option == 'morse' or option == 'hex' or option == 'caesar cipher': if option == 'base64': if choice == 'e': message_bytes = message.encode('ascii') base64_bytes = base64.b64encode(message_bytes) base64_message = base64_bytes.decode('ascii') print("Encrypted Message: " + base64_message) if choice == 'd': base64_bytes = message.encode('ascii') message_bytes = base64.b64decode(base64_bytes) message = message_bytes.decode('ascii') print("Decrypted Message: " + message) if option == 'morse': if choice == 'e': print(m(message).stringToMorse()) if choice == 'd': print(m(message).morseToString()) if option == 'hex': if choice == 'e': print(message.encode("utf-8").hex()) if choice == 'd': print(bytes.fromhex(message).decode('utf-8')) if option == 'caesar cipher': def encrypt(message): message = message.lower() newString = '' validLetters = "abcdefghijklmnopqrstuvwxyz " #adding whitespace to valid chars... space = []