Пример #1
0
    def get(self):
        args = parser.parse_args()
        input_type = args["input_type"]
        output_type = args["output_type"]
        text = conversions.input_to_hex(args["input"], input_type)

        func = self.get_function(output_type)
        return {"conversion": func(text)}
Пример #2
0
def test_input_to_hex_base64_bad():
    text = "$$"
    actual = conversions.input_to_hex(text, conversions.BASE64)
    expected = conversions.ERROR_INVALID

    assert expected == actual
Пример #3
0
def test_input_to_hex_base64():
    text = "MDEyMzQ1QUI="
    actual = conversions.input_to_hex(text, conversions.BASE64)
    expected = "0x30 0x31 0x32 0x33 0x34 0x35 0x41 0x42"

    assert expected == actual
Пример #4
0
def test_input_to_hex_ascii():
    text = "012345AB"
    actual = conversions.input_to_hex(text, conversions.ASCII)
    expected = "0x30 0x31 0x32 0x33 0x34 0x35 0x41 0x42"

    assert expected == actual
Пример #5
0
def test_input_to_hex_oct_bad_neg():
    text = "-0o1"
    actual = conversions.input_to_hex(text, conversions.OCT)
    expected = conversions.ERROR_NEG

    assert expected == actual
Пример #6
0
def test_input_to_hex_oct_bad():
    text = "8"
    actual = conversions.input_to_hex(text, conversions.OCT)
    expected = conversions.ERROR_INVALID

    assert expected == actual
Пример #7
0
def test_input_to_hex_oct():
    text = "0o060 0o061 0o062 0o063 0o064 0o065 0o101 0o102"
    actual = conversions.input_to_hex(text, conversions.OCT)
    expected = "0x30 0x31 0x32 0x33 0x34 0x35 0x41 0x42"

    assert expected == actual
Пример #8
0
def encrypt():
    """
    Method that gets hit when hitting index via a POST

    Handles conversions of input data. Currently expects binary, octal, hex,
    and decimal to be space seperated
    """
    # TODO: make it so when changing options it doesn't wipe data from page
    input_type = get_input_type(request.form)
    if input_type == 1:
        options = get_options(request.form)

        set_options(options)
        return render_template(
            "index.html",
            prefix_option=bool_to_checkbox(PREFIX),
            width_option=WIDTH,
        )

    if input_type == 0:
        error = 1
        return render_template(
            "index.html",
            error=error,
            prefix_option=bool_to_checkbox(PREFIX),
            width_option=WIDTH,
        )

    input_text = request.form[f"{input_type}_text"]

    # convert from input to hex
    text = conversions.input_to_hex(input_text, input_type)

    if text == conversions.ERROR_BLANK:
        return render_template(
            "index.html",
            prefix_option=bool_to_checkbox(PREFIX),
            width_option=WIDTH,
        )

    if isinstance(text, str):
        # convert to all other outputs
        text = text.strip()
        ascii_text = conversions.ascii_conversion(text)
        # convert to hex to standardize formatting
        hex_text = conversions.hex_conversion(text, PREFIX, WIDTH)
        oct_text = conversions.oct_conversion(text, PREFIX)
        dec_text = conversions.dec_conversion(text)
        bin_text = conversions.bin_conversion(text, PREFIX, WIDTH)
        base64_text = conversions.base64_conversion(text)
        base32_text = conversions.base32_conversion(text)
        error = 0
        return render_template(
            "index.html",
            ascii_text=ascii_text,
            hex_text=hex_text,
            dec_text=dec_text,
            bin_text=bin_text,
            base64_text=base64_text,
            base32_text=base32_text,
            oct_text=oct_text,
            error=error,
            prefix_option=bool_to_checkbox(PREFIX),
        )

    # bad input character
    error = 1
    return render_template("index.html",
                           error=error,
                           prefix_option=bool_to_checkbox(PREFIX))
Пример #9
0
def test_input_to_hex_dec_bad():
    text = "a"
    actual = conversions.input_to_hex(text, conversions.DEC)
    expected = conversions.ERROR_INVALID

    assert expected == actual
Пример #10
0
def test_input_to_hex_dec():
    text = "48 49 50 51 52 53 65 66"
    actual = conversions.input_to_hex(text, conversions.DEC)
    expected = "0x30 0x31 0x32 0x33 0x34 0x35 0x41 0x42"

    assert expected == actual
Пример #11
0
def test_input_to_hex_bin_bad_neg():
    text = "-0b1"
    actual = conversions.input_to_hex(text, conversions.BIN)
    expected = conversions.ERROR_NEG

    assert expected == actual
Пример #12
0
def test_input_to_hex_bin_bad():
    text = "2"
    actual = conversions.input_to_hex(text, conversions.BIN)
    expected = conversions.ERROR_INVALID

    assert expected == actual
Пример #13
0
def test_input_to_hex_bin():
    text = "0b00110000 0b00110001 0b00110010 0b00110011 0b00110100 0b00110101 0b01000001 0b01000010"
    actual = conversions.input_to_hex(text, conversions.BIN)
    expected = "0x30 0x31 0x32 0x33 0x34 0x35 0x41 0x42"

    assert expected == actual
Пример #14
0
def test_input_to_hex_hex():
    text = "0x30 0x31 0x32 0x33 0x34 0x35 0x41 0x42"
    actual = conversions.input_to_hex(text, conversions.HEX)
    expected = "0x30 0x31 0x32 0x33 0x34 0x35 0x41 0x42"

    assert expected == actual
Пример #15
0
def test_input_to_hex_base32():
    text = "GAYTEMZUGVAUE==="
    actual = conversions.input_to_hex(text, conversions.BASE32)
    expected = "0x30 0x31 0x32 0x33 0x34 0x35 0x41 0x42"

    assert expected == actual
Пример #16
0
def test_input_to_hex_base32_bad():
    text = "a"
    actual = conversions.input_to_hex(text, conversions.BASE32)
    expected = 0

    assert expected == actual
Пример #17
0
def test_input_to_hex_dec_bad_neg():
    text = "-1"
    actual = conversions.input_to_hex(text, conversions.DEC)
    expected = conversions.ERROR_NEG

    assert expected == actual