misc.cpp

来自「含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种Chec」· C++ 代码 · 共 59 行

CPP
59
字号
/* public domain */#include <iostream>#include <vector>#include <string>#include <botan/bigint.h>#include <botan/pipe.h>#include <botan/hex.h>using namespace Botan;/* Strip comments, whitespace, etc */void strip(std::string& line)   {   if(line.find('#') != std::string::npos)      line = line.erase(line.find('#'), std::string::npos);   while(line.find(' ') != std::string::npos)      line = line.erase(line.find(' '), 1);   while(line.find('\t') != std::string::npos)      line = line.erase(line.find('\t'), 1);   }SecureVector<byte> decode_hex(const std::string& in)   {   if(in.size() % 2)      throw Exception("decode_hex: Odd input length (bad!): " + in);   Botan::Pipe pipe(new Botan::Hex_Decoder);   pipe.start_msg();   pipe.write(in);   pipe.end_msg();   return pipe.read_all();   }std::vector<std::string> parse(const std::string& line)   {   const char DELIMITER = ':';   std::vector<std::string> substr;   std::string::size_type start = 0, end = line.find(DELIMITER);   while(end != std::string::npos)      {      substr.push_back(line.substr(start, end-start));      start = end+1;      end = line.find(DELIMITER, start);      }   if(line.size() > start)      substr.push_back(line.substr(start));   while(substr.size() <= 4) // at least 5 substr, some possibly empty      substr.push_back("");   return substr;   }BigInt to_bigint(const std::string& h)   {   return decode((const byte*)h.data(), h.length(), Hexadecimal);   }

⌨️ 快捷键说明

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