Esempio n. 1
0
def encode_ascii_to_hex(update: Update, context: CallbackContext):
    query: CallbackQuery = update.callback_query
    msg: Message = query.message

    msg_text: str = msg.text

    rows = re.split(r":\n", msg_text)
    res = []
    for row in rows:
        m = re.match(r"([0-1]+\s?)+", row)
        if m is not None:
            res.append(m.group(0).replace("\n", ""))

    converter = ns.get_converter(ns.ASCII, ns.HEX)

    if len(res) == 2:
        pairing = converter(res[0])
        unpaired = converter(res[1])

        text = "ASCII парность(16):\n{}\n\nASCII непарность(16):\n{}".format(
            pairing, unpaired)
    else:
        if "парность" in msg_text.lower():
            text = "ASCII парность(16):\n{}".format(converter(res[0]))
        else:
            text = "ASCII непарность(16):\n{}".format(converter(res[0]))

    msg.reply_text(text, quote=True)
    msg.edit_reply_markup(reply_markup=InlineKeyboardMarkup([]))
Esempio n. 2
0
 def test_binary_to_ascii_unpaired(self):
     converter = np.get_converter(np.BINARY, np.ASCII)
     input_data = "1001011 1100001 1110100 1100101"
     res = "1100 1011 0110 0001 1111 0100 1110 0101"
     assert converter(input_data,
                      mode=np.BY_UNPAIRED).replace(" ", "") == res.replace(
                          " ", "")
Esempio n. 3
0
def encode_ascii_by(update: Update, context: CallbackContext):
    query: CallbackQuery = update.callback_query
    msg: Message = query.message
    reply_to: Message = msg.reply_to_message

    converter = ns.get_converter(ns.TEXT, ns.ASCII)

    user_txt: str = reply_to.text
    user_txt = user_txt.replace(" ", "")
    if query.data == ACTION_ENCODE_ASCII_BY_PAIRED:
        txt = "ASCII парность:\n{}".format(
            converter(user_txt, mode=ns.BY_PAIRED))
    elif query.data == ACTION_ENCODE_ASCII_BY_UNPAIRED:
        txt = "ASCII непарность:\n{}".format(
            converter(user_txt, mode=ns.BY_UNPAIRED))
    else:
        txt = "ASCII парность:\n{}\n\nASCII непарность:\n{}".format(
            converter(user_txt, mode=ns.BY_PAIRED),
            converter(user_txt, mode=ns.BY_UNPAIRED))

    keyboard = [
        [
            InlineKeyboardButton("Перевести в 16-ричную систему",
                                 callback_data=ACTION_ENCODE_ASCII_TO_HEX),
        ],
    ]

    msg.edit_text(txt)
    query.edit_message_reply_markup(InlineKeyboardMarkup(keyboard))
Esempio n. 4
0
def encode_text_to_hex(update: Update, context: CallbackContext):
    query: CallbackQuery = update.callback_query
    msg: Message = query.message

    msg_text: str = msg.text
    text = ns.get_converter(ns.TEXT, ns.HEX)(msg_text)

    msg.reply_text(text, quote=True)
    query.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup([]))
Esempio n. 5
0
def decode_ascii(update: Update, context: CallbackContext):
    query: CallbackQuery = update.callback_query
    msg: Message = query.message

    user_txt: str = msg.text
    user_txt = user_txt.replace(" ", "")
    user_txt = user_txt.replace("\n", "")
    user_txt = user_txt[user_txt.index(":") + 1:]

    query.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup([]))
    msg.reply_text(ns.get_converter(ns.ASCII, ns.TEXT)(user_txt), quote=True)
Esempio n. 6
0
def decode_binary_encoded_by(update: Update, context: CallbackContext):
    query: CallbackQuery = update.callback_query
    msg: Message = query.message
    reply_to: Message = msg.reply_to_message

    user_txt: str = reply_to.text
    user_txt = user_txt.replace(" ", "")

    text = ""
    if query.data == ACTION_DECODE_EASY_BINARY:
        text = ns.get_converter(ns.BINARY, ns.TEXT)(user_txt)
    elif query.data == ACTION_DECODE_ASCII:
        text = ns.get_converter(ns.ASCII, ns.TEXT)(user_txt)

    keyboard = [
        [
            InlineKeyboardButton("Перевести в 16-ричную систему",
                                 callback_data=ACTION_ENCODE_TEXT_TO_HEX),
        ],
    ]

    msg.edit_text(text)
    query.edit_message_reply_markup(InlineKeyboardMarkup(keyboard))
Esempio n. 7
0
def decode_hex(update: Update, context: CallbackContext):
    query: CallbackQuery = update.callback_query
    msg: Message = query.message
    reply_to: Message = msg.reply_to_message

    user_txt: str = reply_to.text
    user_txt = user_txt.replace(" ", "")

    keyboard = [
        [
            InlineKeyboardButton("Перевести в текст",
                                 callback_data=ACTION_DECODE_ASCII),
        ],
    ]

    msg.edit_text("2-ичная:\n{}".format(
        ns.get_converter(ns.HEX, ns.BINARY)(user_txt)))
    query.edit_message_reply_markup(InlineKeyboardMarkup(keyboard))
Esempio n. 8
0
 def test_text_to_ascii_paired(self):
     converter = np.get_converter(np.TEXT, np.ASCII)
     res = "01001011 11100001 01110100 01100101"
     assert converter("Kate", mode=np.BY_PAIRED).replace(" ",
                                                         "") == res.replace(
                                                             " ", "")
Esempio n. 9
0
 def test_binary_to_text(self):
     converter = np.get_converter(np.BINARY, np.TEXT)
     input_data = "1001011 1100001 1110100 1100101"
     res = "Kate"
     assert converter(input_data).replace(" ", "") == res.replace(" ", "")
Esempio n. 10
0
 def test_hex_to_binary(self):
     converter = np.get_converter(np.HEX, np.BINARY)
     input_data = "cb 61 f4 e5"
     res = "1100 1011 0110 0001 1111 0100 1110 0101"
     assert converter(input_data).replace(" ", "") == res.replace(" ", "")
Esempio n. 11
0
 def test_ascii_to_text(self):
     converter = np.get_converter(np.ASCII, np.TEXT)
     input_data = "1100 1011 0110 0001 1111 0100 1110 0101"
     assert converter(input_data).replace(" ",
                                          "") == "Kate".replace(" ", "")
Esempio n. 12
0
 def test_ascii_to_hex(self):
     converter = np.get_converter(np.ASCII, np.HEX)
     input_data = "1100 1011 0110 0001 1111 0100 1110 0101"
     res = "cb 61 f4 e5"
     assert converter(input_data).replace(" ", "") == res.replace(" ", "")