summaryrefslogtreecommitdiff
path: root/basecode.cpp
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2003-01-16 00:47:48 +0000
committerweidai <weidai11@users.noreply.github.com>2003-01-16 00:47:48 +0000
commit8da70ac4e0250bc473c493146cd9a82043cec7b0 (patch)
tree067c4bac637f7cd3c502997512b605084cd56e51 /basecode.cpp
parent59b93d575e00f67e039c4f8839ce2013c3e06343 (diff)
downloadcryptopp-git-8da70ac4e0250bc473c493146cd9a82043cec7b0.tar.gz
fix bug to allow base32 coding
Diffstat (limited to 'basecode.cpp')
-rw-r--r--basecode.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/basecode.cpp b/basecode.cpp
index 6a0bfada..7418a850 100644
--- a/basecode.cpp
+++ b/basecode.cpp
@@ -41,17 +41,32 @@ unsigned int BaseN_Encoder::Put2(const byte *begin, unsigned int length, int mes
if (m_bytePos == 0)
memset(m_outBuf, 0, m_outputBlockSize);
- m_outBuf[m_bytePos] |= begin[m_inputPosition] >> (8-m_bitsPerChar+m_bitPos);
- m_outBuf[m_bytePos+1] |= ((begin[m_inputPosition] << (m_bitsPerChar-m_bitPos)) & 0xff) >> (8-m_bitsPerChar);
- ++m_inputPosition;
-
- m_bitPos += 8;
- while (m_bitPos >= m_bitsPerChar)
{
- m_bitPos -= m_bitsPerChar;
- ++m_bytePos;
+ unsigned int b = begin[m_inputPosition++], bitsLeftInSource = 8;
+ while (true)
+ {
+ assert(m_bitPos < m_bitsPerChar);
+ unsigned int bitsLeftInTarget = m_bitsPerChar-m_bitPos;
+ m_outBuf[m_bytePos] |= b >> (8-bitsLeftInTarget);
+ if (bitsLeftInSource >= bitsLeftInTarget)
+ {
+ m_bitPos = 0;
+ ++m_bytePos;
+ bitsLeftInSource -= bitsLeftInTarget;
+ if (bitsLeftInSource == 0)
+ break;
+ b <<= bitsLeftInTarget;
+ b &= 0xff;
+ }
+ else
+ {
+ m_bitPos += bitsLeftInSource;
+ break;
+ }
+ }
}
+ assert(m_bytePos <= m_outputBlockSize);
if (m_bytePos == m_outputBlockSize)
{
int i;