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

📄 arc4.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** ARC4 Source File                               ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/arc4.h>namespace Botan {/************************************************** Generate ARC4 Cipher Stream                    **************************************************/void ARC4::cipher(const byte in[], byte out[], u32bit length)   {   while(length >= buffer.size() - position)      {      xor_buf(out, in, buffer + position, buffer.size() - position);      length -= (buffer.size() - position);      in += (buffer.size() - position);      out += (buffer.size() - position);      generate();      }   xor_buf(out, in, buffer + position, length);   position += length;   }/************************************************** Generate the internal state                    **************************************************/void ARC4::generate()   {   for(u32bit j = 0; j != buffer.size(); j++)      {      X++;      Y += state[X % 256];      std::swap(state[X % 256], state[Y % 256]);      buffer[j] = (byte)state[(state[X % 256] + state[Y % 256]) % 256];      }   position = 0;   }/************************************************** ARC4 Key Schedule                              **************************************************/void ARC4::key(const byte key[], u32bit length)   {   clear();   for(u32bit j = 0; j != 256; j++)      state[j] = j;   for(u32bit j = 0, state_index = 0; j != 256; j++)      {      state_index = (state_index + key[j % length] + state[j]) % 256;      std::swap(state[j], state[state_index]);      }   X = Y = 0;   for(u32bit j = 0; j <= SKIP; j += buffer.size())      generate();   position += (SKIP % buffer.size());   }/************************************************** Return the name of this type                   **************************************************/std::string ARC4::name() const   {   if(SKIP == 256)      return "MARK-4";   return "ARC4";   }/************************************************** Clear memory of sensitive data                 **************************************************/void ARC4::clear() throw()   {   state.clear();   buffer.clear();   position = X = Y = 0;   }/************************************************** ARC4 Constructor                               **************************************************/ARC4::ARC4(u32bit s) : StreamCipher(1, 32), SKIP(s)   {   clear();   }}

⌨️ 快捷键说明

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