Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge: BRAP encoder/decoder

Name: Anonymous 2018-07-23 23:12

/prog/ challenge time!
Write a program that converts ASCII text into hex and then into BRAAAAAAP text using the language of your choice. It should also be able to convert BRAP messages into ASCII. It can either accept command line arguments, do file IO, or have text prompts, such as something like read or getline(), depending on the language you're using.

The number of As corresponds to a hex value, 0-F. But you can't have 0 As, so BRAP is 0. So the number of As in the BRAP is the hex value + 1.
BRAP is 0
BRAAP is 1
BRAAAP is 2
etc.
BRAAAAAAAAAAAAAAP is e
BRAAAAAAAAAAAAAAAP is f


To start you off, here is the ASCII message "hello world" in hexadecimal:
68 65 6c 6c 6f 20 77 6f 72 6c 64

Here is the BRAP-encoded message of "hello world":
BRAAAAAAAP BRAAAAAAAAAP BRAAAAAAAP BRAAAAAAAAAAAAAP BRAAAAAAAP BRAAAAAAAAAAAAAP BRAAAAAAAP BRAAAAAAAAAAAAAAAAP BRAAAP BRAP BRAAAAAAAAP BRAAAAAAAAP BRAAAAAAAP BRAAAAAAAAAAAAAAAAP BRAAAAAAAAP BRAAAP BRAAAAAAAP BRAAAAAAAAAAAAAP BRAAAAAAAP BRAAAAAP

In addition to your code, you should post an encoded BRAP message for others to decode. Be sure to make your program perform input validation so that it doesn't fuck up when it gets invalid BRAPs (or other invalid string). Don't trust user input, especially from /prog/. Secure code means never trusting input.

Name: Anonymous 2018-07-23 23:15

By the way: please note the way I am treating the digits. In decimal, 12 means one ten and 2 ones. It is not just a "1" and a "2".

In hexadecimal, 68 means 6x 16s and 8x 1s, because it's base 16 (hex = 6, dec = 10, hexadecimal = 16). But notice how in >>1 I made it treat is as if they are a 6 and an 8, not 6x16 and 8x1. This is less about math and more about dealing with separate digits. Just an easy way to do it.

I guess, if you want, you could try to do it another way. But this is how I'm doing it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List