I think you made a mistake in endianess. Guild Wars is not using the usual endian mode. This is why you will not be able to use standard methods to create base64 strings from binary data.
This is how I do it:
First, create an array of Bytes with a length of at least 282 (named Array in the code below). This is the maximum length of a Guild Wars template, which is 47 characters representing 6 bits each. Set all array entries to 0.
After that, create the following procedure (written in Pascal pseudo code) in your program:
(Position and Size are representing the number of bits, not bytes!)
Code:
PROCEDURE SaveValueToArray(Position, Size, Value: Integer);
VAR
Exponent: Int64;
i: Integer;
BEGIN
Exponent := 1;
FOR i := Position TO Position + Size - 1 DO
BEGIN
Array[i] := Value MOD (Exponent * 2) DIV Exponent;
Exponent := Exponent * 2;
END;
END;
With this function, you can simply put one value after each other.
Always sum up number of bits (Size) you wrote to your array. You will need them in the second procedure (this is the Size parameter) and you have to know where to write the next value in your array.
The second procedure is this:
Code:
FUNCTION ArrayToBase64String(Size: Integer): String;
CONST
Key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
VAR
i: Integer;
RealSize: Integer;
BEGIN
IF Size MOD 6 > 0 THEN
RealSize := Size + 6 - Size MOD 6
ELSE
RealSize := Size;
Result := '';
FOR i := 0 TO (RealSize div 6) - 1 DO
BEGIN
// NOTE: When extracting characters from strings in Pascal, the first character is number 1, it's NOT 0, so in most languages you have to remove the leading "1 +"
// ALSO NOTE: You don't return a function value in Pascal, you simply edit a variable named named Result which is automatically returned at the end of the procedure
Result := Result + Key[1 + Array[6 * i] + Array[6 * i + 1] * 2 + Array[6 * i + 2] * 4 + Array[6 * i + 3] * 8 + Array[6 * i + 4] * 16 + Array[6 * i + 5] * 32];
END;
END;
MOD is the modulo function, DIV is the the division rounded down.
I will
not answer any additional questions concerning this topic in this thread. If anyone wants to get a question answered, PM me. You will also have to
provide a reason why you need this.