Download Radix 64 Bits
Radix free download - Radix, Radix, Radix Anti-Rootkit, and many more programs. Radix free download - Radix, Radix, Radix Anti-Rootkit, and many more programs.
Radix 64 or base 64 is a binary-to-text encoding system that is designed to allow binary data to be represented in ASCII string format. This is an educational project accepts a string from a user and Radix 64 encodes it.
What is Radix 64 Encoding?
Radix 64 encoding allows binary data stored in octets (i.e. bytes) to be expressed as printable characters.
Radix-64 characters require the binary input to be split into blocks of 6. These numbers (which all range from 0 - 63) are then mapped onto a character set of printable characters.
The Radix 64 characterset includes:
- A-Z
- a-z
- 0-9
- The additional characters '+' and '/'
This amounts to a total of 64 symbols. To encode binary data into Radix 64, data is parsed in 6-bit blocks (i.e. such that each block has a maximum value of 64), and the number represented by each 6-bit block is used to look up a Radix 64 character.
Number of Output Bytes
Radix 32
Radix 64 encoding results in 33% more bytes - every 3 input bytes is converted to 4 output.
Given n
input bytes, the output will be:
4⌈n/3⌉
The ceiling brackets ⌈x⌉
mean round the number to the upper integer. In words, this expression would be: 'n divided by 3, rounded up to the next whole number and then multiplied by 4'.
Example: PGP Messages
A good example is the ascii-armor output from PGP:
The above example is the ciphertext (excluding cleartext message headers) that results from ASCII armored symmetric encryption of the string 'Hello World!' (additional metadata is added by PGP - including a salt and the cipher algorithm designator).
Note that the encrypted message consists of Radix 64 characters exclusively, with the '=' sign used as padding - so in the message above, data after the '=' is not part of the message. You wouldn't see this padding if the number of the plaintext bytes was an exact multiple of three (and therefore did not require padding).
By definition, each byte of the original ciphertext was a number from 0-255. Some of these numbers do not map to printable ASCII characters. Encoding the message as Radix 64 allows the message to be printed and/or sent as an email or text message - modes of communication which do not allow the transfer of binary data.
The Radix 64 Alphabet
Example Radix 64 Encoding
Radix 64 encoding can be difficult to get your head around. Before building a programme to do the encoding, it can help to step through the process manually.
This example will encode the string 'david' into Radix 64.
- The string is represented by 5 chars.
- The total size in bits (assuming that one char 1 byte) is given by 8 x 5 = 40 bits.
- Dividing the total number of bits by 6 leaves remainder 4 - therefore 7 sextuplets will be needed to represent the string in Radix 64
- The last sextuplet will have 2 bits of padding. When this is the case, '=' padding character is added.
Radix 64 Encoding in C
The encoding takes place in the function void base64Encode(unsigned char *inputBuffer, unsigned char *b64Buffer, size_t inputLength)
, in base64.c
.
The function receives:
64 Bit Download
- The input buffer
inputBuffer
- which is a pointer to a character array (a c-style string) that contains the user input - The output buffer
b64Buffer
- a pointer to a dynamically allocated section of memory, sufficient to contain the Radix 64 encoded output
For the first character, the function:
- Takes the first 6 bits, looks up the value against the Radix 64 encoding and assigns the correct ASCII character to
b64Buffer[0]
- A temporary byte is then created wich stores the data from the unused bits (i.e. the least significant 2 bits from the first char is stored as the most significant 2 bits in
tmpByte
) - A
size_t divider
variable is set - this will determine the number of bits to take from the next char - these will be combined with the bits intmpByte
to form the next Radix 64 6-bit group
Bitwise Operations
Bitwise operators allow for bit-by-bit manipulation of data stored in individual bytes.
In our case, we make use of bit-masking to collect bits from specific positions within a byte:
Originally I gathered the first 6 bits like this:
...which bit shifts the original char (i.e. inputBuffer[0]
) two places to the right before masking against 00111111
. This does collect the correct data for the Radix 64 lookup index - but it has the unwanted side-effect of mutating the original char - which meant that the function signature could not declare inputBuffer
as const
.
Next, the function loops through the characters. During each iteration:
- The correct bits are used to determine the next radix 64 character
- Excess bits are stored in
tmpByte
to be carried forward if necessary - The
divider
is set such that the correct number of bits are collected when advancing
The divider is set divider = (divider - 2) ? divider - 2 : 6;
:
- If the current divider is 2, set divider to 6 (because no data is carried forward from the current character)
- If the divider is not 2, set the divider to divider - 2:
- Current divider is 4, 4 bits carried forward, new divider is 2
Notes on Decoding
To decode radix 64 encoded text, typically four characters are converted to three bytes. If the string contains a single padding character (i.e. '=') the last four characters (including the padding character) will decode to only two bytes, while ' indicates that the four characters will decode to only a single byte. From RFC 1521:
Since all base64 input is an integral number of octets, only the following cases can arise:
- the final quantum of encoding input is an integral multiple of 24 bits; here, the final unit of encoded output will be an integral multiple of 4 characters with no '=' padding
- the final quantum of encoding input is exactly 8 bits; here, the final unit of encoded output will be two characters followed by two '=' padding characters
- the final quantum of encoding input is exactly 16 bits; here, the final unit of encoded output will be three characters followed by one '=' padding character.'
Manual example:
Resources
- RFC 1421: Privacy Enhancement for Internet Electronic Mail: Part I: Message Encryption and Authentication Procedures
- Very good video explanation on Base 64: mobilefish
- Download
Often downloaded with
- Smart SyncThis intuitive software helps you make the most of class time – you can guide...$359DOWNLOAD
- Smart ReNameThis is a free software. It lets you rename files in , based on a pattern you...DOWNLOAD
- SmartRecovery EDUSmartRecovery EDU is a program that provides you a set of command-line switches...DOWNLOAD
- LinQ SoftwareLinQ software connects a networked computer such as a wireless laptop, to a...DOWNLOAD
- Employee Training ManagerSimplify your employee training management by taking advantage of the...$299DOWNLOAD