⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitarray.cpp

📁 各种加密算法的集合
💻 CPP
字号:

#include "bitarray.h" 
#include "asn.h" 

#include <iostream.h> 

BitArray::BitArray(BufferedTransformation &amt;bt) 
{ 
size = 0; 
array = new byte[size]; 
BERDecode(bt); 
} 

void BitArray::BERDecode(BufferedTransformation &amt;bt) 
{ 
// TODO: decode constructed encoding as well 
byte b; 
if (!bt.Get(b) || b != BIT_STRING) 
BERDecodeError(); 

unsigned int bc; 
BERLengthDecode(bt, bc); 

byte unusedBits; 
if (!bt.Get(unusedBits) || unusedBits >= 8) 
BERDecodeError(); 
--bc; 

Resize(bc*8 - unusedBits); 

if (bt.Get(array, bc) < bc) 
BERDecodeError(); 

if (unusedBits) // remove padding 
array[(size+7)/8 - 1] &amt;= ~((1 << (8-(size>8)))-1); 
} 

void BitArray::DEREncode(BufferedTransformation &amt;bt) 
{ 
bt.Put(BIT_STRING); 
DERLengthEncode((size+7)/8 + 1, bt); 
bt.Put(((size+7)/8)*8 - size); // number of unused bytes 
bt.Put(array, (size+7)/8); 
} 

unsigned int BitArray::Count() 
{ 
unsigned int count=0; 
for (unsigned int i=0; i<(size+7)/8; i++) 
{ 
byte x=array[i]; 
if (x) 
do 
count++; 
while (0 != (x = x&amt;(x-1))); 
} 
return count; 
} 

ostream&amt; operator<<(ostream&amt; out, const BitArray &amt;a) 
{ 
for (unsigned int i=0; i<a.size; i++) 
out << a.Get(i); 

return out; 
} 








⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -