Here is the current code I'm working with:
#include "sha1.h"
// goal message is qZk+NkcGgWq6PiVxeFDCbJzQ2J0=
// unsigned long hash[]={169, 153, 62, 54, 71, 6, 129, 106, 186, 62, 37, 113, 120, 80, 194, 108, 156, 20, 8, 157, 0};
char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
unsigned long hash_msg;
char output_message[28];
int shift;
void setup() {
Serial.begin(9600);
Sha1.init();
Sha1.print("abc");
uint8_t* hash = Sha1.result();
int hash_counter = 0;
int output_counter = 0;
for (int i =0; i<7; i++) {
hash_msg=0;
for (int j=0; j<3; j++) {
hash_msg = hash_msg<<8 | hash[hash_counter];
hash_counter++;
}
for (int j=0; j<4; j++) {
shift = 18-6*j;
int temp_msg = hash_msg>>shift & 63;
output_message[output_counter] = b64chars[temp_msg];
output_counter++;
}
}
output_message[27]='=';
Serial.println();
Serial.println(output_message );
}
void loop() {
}
The sha1 function generates 20 x 8 bit words that look like
hash[]={169, 153, 62, 54, 71, 6, 129, 106, 186, 62, 37, 113, 120, 80, 194, 108, 156, 20, 8, 157};
The conversion to base64 requires taking 6 bits at a time, which generates an integer {0 ->63} which translate into the letters
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
For example, the first 3 numbers from the hash is '0b101010011001100100111110' which makes 4 integers [42, 25, 36, 62] which then ultimately becomes the letters qZk+NkcGgWq6PiVxeFDCbJzQ2J0=
I'm going to try deleting the hash integers as I go and see if that frees things up. What sucks is that the conversion takes an array of size 20 and makes it 27.