     else if(base == Octal)
        {
        BigInt copy = n;
-@@ -97,6 +102,7 @@
+@@ -44,7 +49,15 @@
+          divide(copy, 10, copy, remainder);
+          output[output_size - 1 - j] = digit2char(remainder.word_at(0));
+          if(copy.is_zero())
++            {
++            if(j < output_size - 1)
++               {
++               int extra = output_size - 1 - j;
++               memmove(output, output + extra, output_size - extra);
++               memset(output + output_size - extra, 0, extra);
++               }
+             break;
++            }
+          }
+       }
+    else
+@@ -97,6 +110,7 @@
     BigInt r;
     if(base == Binary)
        r.binary_decode(buf, length);

 }
diff -ur a/src/big_code.cpp b/src/big_code.cpp
--- a/src/big_code.cpp	2004-10-10 12:33:53.000000000 -0700
+++ b/src/big_code.cpp	2004-10-17 14:17:19.000000000 -0700
@@ -5,7 +5,10 @@
 
 #include <botan/bigint.h>

    else if(base == Hexadecimal)
       {
       SecureVector<byte> hex;
@@ -117,6 +131,7 @@
          binary[j] = Hex_Decoder::decode(hex+2*j-offset);
       r.binary_decode(binary, binary.size());
       }
