老外写的3DES不错

  • p7_122349
    了解作者
  • 45.7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-27 01:56
    上传日期
老外写的3DES不错老外写的3DES不错老外写的3DES不错
McbDES.zip
  • McbDES.dsp
    4.2KB
  • McbDES.exe
    44KB
  • McbDES2.h
    16.2KB
  • McbMain.cpp
    7.5KB
  • McbDES2.hpp
    59KB
  • McbDES2.c
    45.5KB
内容介绍
/** **************************************************************************** * <P> McbDES2.c - implementation file for implementing DES and Triple DES * (without use of external libs). * The DES mode of operation is Electronic Code Book (ECB) or Chain Block * Coding (CBC) - Cipher Feedback (CFB) are not supported. * * I have attempted to write this source to the ANSI standard so that it can * be easily ported to other environments (such as C370). Note that this * implementation of DES is not particularly efficient - the Baltimore stuff * on NT is at least 10 times as fast, however as this has been written * mainly for portability, I do not have the luxury of adding a lot of * optimisations. This code could however be optimised, even portably, * although not with my grasp of maths. * * For an detailed description on how DES works, please see the following * document: http://www.aci.net/kalliste/des.htm. * All of the code within this module is based on this document.</P> * * @version V1.0 * * @author Martyn C Brown * * @changeHistory * 8th June 2000 - (V1.0) Creation (MCB) * 21st January 2003 - (V2.0) Modification (MCB). * Added Chain Block Coding (CBC) for better * encryption. **************************************************************************** */ /* **************************************************************************** * Include all necessary include files **************************************************************************** */ #include "McbDES2.h" #include <string.h> #include <stdlib.h> #include <time.h> /* **************************************************************************** * Macros for manipulating bits **************************************************************************** */ #define McbGETBIT(lpBytes, nBitzb) \ ((lpBytes)[(nBitzb)/8] & (1 << (7 - ((nBitzb) % 8)))) #define McbSETBIT(lpBytes, nBitzb) \ ((lpBytes)[(nBitzb)/8] |= (1 << (7 - ((nBitzb) % 8)))) #define McbCLEARBIT(lpBytes, nBitzb) \ ((lpBytes)[(nBitzb)/8] &= ~(1 << (7 - ((nBitzb) % 8)))) #define McbRotate26BitsLeft2(lIn, lOut) \ (lOut) = ((lIn) << 2) | (((lIn) & 0x0C000000) >> 26); #define McbRotate26BitsLeft1(lIn, lOut) \ (lOut) = ((lIn) << 1) | (((lIn) & 0x08000000) >> 27); #define McbGetKeyPair(lpBytes, lC, lD) \ lpBytes[0] = ((lC) & 0xFF00000) >> 20; \ lpBytes[1] = ((lC) & 0x00FF000) >> 12; \ lpBytes[2] = ((lC) & 0x0000FF0) >> 4; \ lpBytes[3] = (((lC) & 0x000000F) << 4) | (((lD) & 0xF000000) >> 24); \ lpBytes[4] = ((lD) & 0x0FF0000) >> 16; \ lpBytes[5] = ((lD) & 0x000FF00) >> 8; \ lpBytes[6] = ((lD) & 0x00000FF); /* **************************************************************************** * define to trace bits of operations **************************************************************************** */ #ifdef McbDEBUGBITS /** **************************************************************************** * <P> Output the bits </P> * * @methodName McbTraceBits * * @param char * lpBytes * @param cbBytes * * @return void * * @exception none * * @author Martyn C Brown * * @changeHistory * 24th May 2000 - (V1.0) Creation (MCB) **************************************************************************** */ void McbTraceBits(const char * lpBytes, int cbBits) { int n; for (n = 0; n<cbBits; n++) { if (McbGETBIT(lpBytes, n)) { printf("1"); } else { printf("0"); } } }/* McbTraceBits */ #endif /*McbDEBUGBITS*/ /** **************************************************************************** * <P> For a given in buffer, out buffer and table this function maps bits * which are true given that the entries in the table show the new * arrangement of the bits from their initial order.</P> * * @methodName McbMapTrueBits * * @param unsigned char * lpMap * @param int cbMap * @param unsigned char * lpIn * @param unsigned char * const lpOut * * @return void * * @exception none * * @author Martyn C Brown * * @changeHistory * 24th May 2000 - (V1.0) Creation (MCB) **************************************************************************** */ void McbMapTrueBits(const unsigned char * lpMap, unsigned int cbMap, const unsigned char * lpIn, unsigned char * const lpOut) { unsigned char chBitIndex; /* ************************************************************************* * translate bits according to table ************************************************************************* */ for (chBitIndex=0; chBitIndex<cbMap; chBitIndex++) { if (McbGETBIT(lpIn, lpMap[chBitIndex])) { McbSETBIT(lpOut, chBitIndex); } } }/* McbMapTrueBits */ /** **************************************************************************** * <P> For a given key, create the permuted K+ based on table PC1. </P> * * @methodName McbCreateKeyPlus * * @param unsigned char Key[8] * @param char KeyPlus[7] * * @return void * * @exception none * * @author Martyn C Brown * * @changeHistory * 24th May 2000 - (V1.0) Creation (MCB) **************************************************************************** */ void McbCreateKeyPlus(const unsigned char Key[8], unsigned char KeyPlus[7]) { static unsigned char tblPC1[] = { 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 }; memset(KeyPlus, 0, 7); McbMapTrueBits(tblPC1, sizeof(tblPC1), Key, KeyPlus); }/* McbCreateKeyPlus */ /** **************************************************************************** * <P> Create the Initial permuation from the message. </P> * * @methodName McbCreateInitialPermutation * * @param unsigned char Message[8] * @param char IP[8] * * @return void * * @exception none * * @author Martyn C Brown * * @changeHistory * 7th June 2000 - (V1.0) Creation (MCB) **************************************************************************** */ void McbCreateInitialPermutation(const unsigned char Message[8], unsigned char IP[8]) { static unsigned char tblIP[] = { 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7, 56, 48, 40, 32, 24, 16, 8, 0, 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, 62, 54, 46, 38, 30, 22, 14, 6 }; memset(IP, 0, 8); McbMapTrueBits(tblIP, sizeof(tblIP), Message, IP); }/* McbCreateInitialPermutation */ /** **************************************************************************** * <P> Create array of 16 subkeys from the key.</P> * * @methodName McbCreateSubKeys
评论
    相关推荐
    • iPIC3D
      iPIC3D 大规模并行执行隐式粒子模拟方法在等离子体模拟中的应用 编译 创建一个构建目录(例如,构建)并调用CMake。 完成后,应在构建文件夹中生成可执行的iPIC3D *和库libiPIC3Dlib.a。 mkdir build cd build ...
    • cub3d
      cub3d
    • cub3d
      cub3d
    • 3D重建
      3D重建 在这个项目中,为了进行3D重建和对象化,我遵循了3个步骤: 1-对极整流:为了减少计算成本。 2点匹配3-3D点三角测量 点检测和匹配,三角测量部分将很快添加。
    • Milkshape3D
      Milkshape3D.zipMilkshape3D.zipMilkshape3D.zipMilkshape3D.zipMilkshape3D.zipMilkshape3D.zipMilkshape3D.zipMilkshape3D.zipMilkshape3D.zipMilkshape3D.zipMilkshape3D.zipMilkshape3D.zip
    • spindle3d
      一个斐济插件,用于自动测量有丝分裂纺锤体体积图像的3D形态学参数。 安装 安装 启动斐济并: 主轴3D 3D ImageJ套件 重新启动斐济
    • cub3d
      cub3d
    • PerspectiveMatrix3D
      开发Stage3D时所用到的两个adobe工具包中的两个类PerspectiveMatrix3D 和 AGALMiniAssembler。
    • 3d
      3D
    • viztool3d
      Viztool 3D 3D可视化以解释3D图形和数学