# 6. Bytes and Big Integers

## Challenge Description:

Cryptosystems like RSA works on numbers, but messages are made up of characters. How should we convert our messages into numbers so that mathematical operations can be applied?\
\
The most common way is to take the ordinal bytes of the message, convert them into hexadecimal, and concatenate. This can be interpreted as a base-16/hexadecimal number, and also represented in base-10/decimal.\
\
To illustrate:\
\
message: HELLO\
ascii bytes: \[72, 69, 76, 76, 79]\
hex bytes: \[0x48, 0x45, 0x4c, 0x4c, 0x4f]\
base-16: 0x48454c4c4f\
base-10: 310400273487\
\ <i class="fa-lightbulb">:lightbulb:</i> Python's PyCryptodome library implements this with the methods `bytes_to_long()` and `long_to_bytes()`. You will first have to install PyCryptodome and import it with `from Crypto.Util.number import *`. For more details check the [FAQ](https://cryptohack.org/faq/#install).\
\
Convert the following integer back into a message:\
\
11515195063862318899931685488813747395775516287289682636499965282714637259206269

## My Solution:

We can write a simply python script to replicate the results above of the hello string:

```python
message = "HELLO"
ascii_bytes = []
hex_bytes = []
base_16 = ""
base_10 = 0

for i in message:
    ascii_bytes.append(ord(i))

for i in ascii_bytes:
    hex_bytes.append(hex(i))

base_16 += "0x"
for i in hex_bytes:
    base_16 += i.replace('0x', '')

base_10 = int(base_16.replace('0x', ''), 16)

print(message)
print(ascii_bytes)
print(hex_bytes)
print(base_16)
print(base_10)
```

And using the pycryptodome library we can solve this challenge:

```python
from Crypto.Util.number import *

EncodedData = 11515195063862318899931685488813747395775516287289682636499965282714637259206269

print("Here is your flag:")
print(long_to_bytes(EncodedData).decode())
```

## The Flag:

```bash
crypto{3nc0d1n6_4ll_7h3_********}
```
