Sorry, I didn't read the original question closely.
Here is a basic algorithm for converting between a binary array and a text array.
Code:
#include <stdio.h>
#include <assert.h>
// Convert a binary password to a text password.
// The output will take 2x bytes as the input.
bin2txt (size_t pass_size, unsigned char const * input, unsigned char * output) {
int i;
// For each element of the binary password, we're going to strip out the
// lower and upper 4 bits, and make each a character.
for (i = 0; i < pass_size; ++i) {
unsigned char low_nibble;
unsigned char high_nibble;
low_nibble = input[i] & 0x0F;
high_nibble = input[i] >> 4;
output[i * 2] = low_nibble + 'A';
output[i * 2 + 1] = high_nibble + 'A';
}
}
// Convert a text password to a binary password.
// The output will take 1/2 bytes as the input.
txt2bin (size_t pass_size, unsigned char const * input, unsigned char * output) {
int i;
// Form each element of the binary password by merging two characters
// from the input together.
for (i = 0; i < pass_size; ++i) {
unsigned char low_nibble;
unsigned char high_nibble;
low_nibble = input[i * 2] - 'A';
high_nibble = input[i * 2 + 1] - 'A';
output[i] = low_nibble | (high_nibble << 4);
}
}
#define PASS_SIZE 10
int main (void) {
// The password is an arbitrary array of characters.
unsigned char orig_pass[PASS_SIZE] = {176, 255, 0, 10, 73, 42, 5, 30, 0, 255};
unsigned char restored_pass[PASS_SIZE];
char txt_version[PASS_SIZE * 2];
int i;
// Convert the pass to txt.
bin2txt (PASS_SIZE, orig_pass, txt_version);
printf ("Txt version:\n");
for (i = 0; i < sizeof(txt_version); ++i)
putchar(txt_version[i]);
putchar('\n');
putchar('\n');
// Restore the pass from txt.
txt2bin (PASS_SIZE, txt_version, restored_pass);
printf ("Verification test. Columns should be equal.\n");
// Verify that the restored is equivalent to the original.
for (i = 0; i < PASS_SIZE; ++i) {
printf ("%d: %4u %4u\n", i, orig_pass[i], restored_pass[i]);
}
return 0;
}