Pay attention to this post Print this page Save page This topic Access number: 479
Topic: DES algorithm! Author: lanjingquan expert points: 500
Member information Short message email
Published: 2003-9-21 12:47:10 [Reply]
Landlord
Now there is a problem with the DES encryption algorithm on the online, fortunately, I found one on the BBS, but the interface is not good enough. The following is the use of MFC's CString packaged once. Below, these are the key ------------------------------------- CString Sencrypt (CString) CSTRING SDECRYPT (CSTRING); --------------------------------------- int main () {CSTRING AA, BB, CC; AA = "KingWind"; Unsigned long S1, S2; S1 = 30; S2 = 100; cPackage_Encoder CODER1, CODER2; Const Char K1 [256] = "DSA3425HELLO"; CODER1.SetKey (K1) CODER2.SETKEY (K1); COUT << "plain text:" << AA << endl; bb = CODER1. SENCRYPT (AA); cout << "ciphertext: << bb << endl; cc = CODER2. SDECrypt (bb); cout << "plain text:" << cc << Endl; return 0;}; 逸 兴 兴 飞 飞 上 青 青 青 明 明
Author: lanjingquan expert points: 500
Member information Short message email
Published: 2003-9-21 12:41:34 [Reply]
First floor
// DesCode.h:! Interface for the CDesCode class.////#if defined (AFX_DESCODE_H__C03E92C7_2754_4B05_B19D_59D86587C26D__INCLUDED _) # define AFX_DESCODE_H__C03E92C7_2754_4B05_B19D_59D86587C26D__INCLUDED_ # if _MSC_VER> 1000 # pragma once # endif // _MSC_VER> 1000 # include "AFX.h" typedef union {unsigned char byte [8]; struct {unsigned long low; unsigned long high;} dword;} SBitBlock; // static extern void deskey (unsigned char const * key, int decryptf, unsigned long * outbuf); // static extern Void deSDes (unsigned char setblock [8], unsigned long const * keys); class cdes_encoder {private: // data: 16 48-bit K [i], Calculated from "key", USE low 6-bit in each byte SBitBlock encrypt_k [16], decrypt_k [16]; public: // Functions: SetKey, Encrypt, Decrypt inline void SetKey (const SBitBlock & key); // calculate k [i] inline void Encrypt (SBitBlock & Destination, Const Sbitblock & Source) Const; Inli ne void Decrypt (SBitBlock & destination, const SBitBlock & source) const;}; inline void CDES_Encoder :: SetKey (const SBitBlock & key) {deskey ((unsigned char const *) (& key), 0, (unsigned long *) encrypt_k); deskey ((unsigned char const *) (& key), 1, (unsigned long *) decrypt_k);}; inline void CDES_Encoder :: Encrypt (SBitBlock & destination, const SBitBlock & source) const {desDES ((unsigned char const *) (& source) , (unsigned char *) (& destination), (unsigned long const *) encrypt_k);}; inline void CDES_Encoder :: Decrypt (SBitBlock & destination, const SBitBlock & source) const {desDES ((unsigned char const *) (& source), ( Unsigned char *) (&)
destination), (unsigned long const *) decrypt_k);}; // Below defines the package encryption and decryption class class CPackage_Encoder {private: // Data: a DES coder and package seed CDES_Encoder theDEScoder; SBitBlock seed; public: // Functions : SetKey, SetSeed, GetSeed, Encrypt, Decrypt void SetKey (const char * password); inline void SetSeed (unsigned long lo, unsigned long hi); inline void GetSeed (unsigned long & lo, unsigned long & hi) const; CString SEncrypt (CString ); CString SDecrypt (CString); int Encrypt (unsigned char destination [], const unsigned char source [], unsigned sourcesize) const; int Decrypt (unsigned char destination [], const unsigned char source [], unsigned sourcesize);} ; inline void CPackage_Encoder :: SetSeed (unsigned long lo, unsigned long hi) {seed.dword.low = lo; seed.dword.high = hi;}; inline void CPackage_Encoder :: GetSeed (unsigned long & lo, unsigned long & hi) Const {LO = Seed.dword.low; hi = seed.dword .high;}; #ENDIGH;}; defined (AFX_DESCODE_H__C03E92C7_2754_4B05_B19D_59D86587C26D__included_) 怀 逸 兴 飞 上 上 青 天 天 明 明 明 飞 此 上 上 上 上 上 上 上
Author: lanjingquan expert points: 500
Member information Short message email
Published: 2003-9-21 12:42:56 [Reply]
Second floor
// descode.cpp: importation of the cdescode class.////include "stdafx.h" #include "hotel.h" #include "descode.h" #ifdef _debug # undef this_filestatic char this_file [] = __ file__; #define new DEBUG_NEW # endif # define word32 unsigned long #define byte unsigned char extern void deskey (unsigned char const * key, int decryptf, unsigned long * outbuf); extern void desDES (unsigned char const inblock [8], unsigned char outblock [8], unsigned long const * keys); / * The size of a scheduled DES key * / #define DES_KEYWORDS 32 #define DES_KEYBYTES (sizeof (word32) * DES_KEYWORDS) static word32 const bigbyte [24] = {0x800000L, 0x400000L, 0x200000L, 0x100000L, 0x80000L, 0X40000L, 0x20000L, 0x10000L, 0x8000L, 0x4000L, 0x2000L, 0x1000L, 0x800L, 0x400L, 0x200L, 0x100L, 0x80L, 0x40L, 0x20L, 0x10L, 0x8L, 0x4L, 0x2L, 0x1L}; / * use the key schedule specified in the standard (ANSI X3.92-1981). * / Static byte const pc1 [56] = {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}; static Byte Const Totrot [16] = {1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28 }
Static Byte Const PC2 [48] = {13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26 , 19, 12, 1, 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35 , 28, 31}; / * this is a less-this-brilliant key scheofuling routine. * IT COULD OPTIMIZATION SOME. * * COOKEY "Cooks" The Key Into The Desired Form, from the Basic One That * Has THE keys for S-boxes 1 through 8 in adjacent words of the * "raw" array Ie the bits start out like this:. * xxxxxxxx111111222222333333444444 * xxxxxxxx555555666666777777888888 * We actually want the keys to look like this: * 111111xx333333xx555555xx777777xx * 222222xx444444xx666666xx888888xx * Where the " XX "patterns are set to 01020300 for use by the s-box * lookup code in the main encrypt loop. * / static void cookey (word32 * raw, word32 * cooked) {INT i; for (i = 0; i <16 ; i , RAW = 2, cooked = 2) {COOKED [0] = (RAW [0] & 0x00FC0000L) << 8; cooked [0] | = (RAW [0] & 0x00000FC0L) << 12; cooked [0] | = (RAW [1 ] & 0x00FC0000L) >> 8; COOKED [0] | = (Raw [1] & 0x00000FC0L) >> 4; Cooked [0] | = 0x01020300; Cooked [1] = (Raw [0] & 0x0003F000L) << 14 Cooked [1] | = (RAW [0] & 0x0000003FL) << 18; cooked [1] | = (RAW [1] & 0x0003F000L) >> 2;
COOKED [1] | = (Raw [1] & 0x0000003FL) << 2; cooked [1] | = 0x01020300;} return;} void deskey (byte const * key, int decryptf, word32 * outbuf) {INT i, J , L, M, N; BYTE PC1M [56], PCR [56]; Word32 KN [32]; for (j = 0; j <56; j ) {l = pc1 [j]; m = l & 07; PC1M [J] = (Key [L >> 3] >> (~ L & 7)) & 1;} for (i = 0; i <16; i ) {m = (Decryptf? 15-i: i) << 1; n = m 1; KN [m] = kN [n] = 0L; for (j = 0; j <28; j ) {l = j Totrot [i]; if (l> = 28 ) L - = 28; PCR [J] = PC1M [L];} for (j = 28; j <56; j ) {L = J Totrot [I]; if (l> = 56) L - = 28; PCR [J] = PC1M [L];} for (j = 0; j <24; J
) {IF (PCR [PC2 [J]]) KN [M] | = Bigbyte [J]; PCR [PC2 [J 24]]) KN [N] | = Bigbyte [J];}} cookey KN, Outbuf; Return;} / * s-Boxes 1, 3, 5, 7, Plus P Permutation, Rotated * / Static Word32 Const SP0 [512] =
{0x00404100, 0x00000000, 0x00004000, 0x00404101, 0x00404001, 0x00004101, 0x00000001, 0x00004000, 0x00000100, 0x00404100, 0x00404101, 0x00000100, 0x00400101, 0x00404001, 0x00400000, 0x00000001, 0x00000101, 0x00400100, 0x00400100, 0x00004100, 0x00004100, 0x00404000, 0x00404000, 0x00400101, 0x00004001 , 0x00400001, 0x00400001, 0x00004001, 0x00000000, 0x00000101, 0x00004101, 0x00400000, 0x00004000, 0x00404101, 0x00000001, 0x00404000, 0x00404100, 0x00400000, 0x00400000, 0x00000100, 0x00404001, 0x00004000, 0x00004100, 0x00400001, 0x00000100, 0x00000001, 0x00400101, 0x00004101, 0x00404101, 0x00004001 0x00404000, 0x00400101, 0x00400001, 0x00000101, 0x00004101, 0x00404100, 0x0000010101, 0x00400100, 0x00400400, 0x0000000000, 0x00004001, 0x00004100 , 0x00000000, 0x00404001, 0x00000082, 0x02008080, 0x00000000, 0x02008002, 0x02000080, 0x00000000, 0x00008082, 0x02000080, 0x00008002, 0x02000002, 0x02000002, 0x00008000, 0x02008082, 0x00008002, 0x02008000, 0x00000082, 0x02000000, 0x00000002, 0x02008080, 0x00000080, 0x00008080, 0x02008000, 0x02008002 , 0x00008082, 0x02000082, 0x00008080, 0x00008000, 0x02000082, 0x00000002, 0x02008082, 0x00000080, 0x02000000, 0x02008080, 0x02000000, 0x00008002, 0x00000082, 0x00008000, 0x02008080, 0x02000080, 0x00000000, 0x00000080, 0x00008002, 0x02008082, 0x02000080,
0x02000002, 0x00000080, 0x00000000, 0x02008002, 0x02000082, 0x00008000, 0x02000000, 0x02008082, 0x00000002, 0x00008082, 0x00008080, 0x02000002, 0x02008000, 0x02000082, 0x00000082, 0x02008000, 0x00008082, 0x00000002, 0x02008002, 0x00008080, 0x00000040, 0x00820040, 0x00820000, 0x10800040, 0x00020000, 0x00000040, 0x10000000, 0x00820000, 0x10020040, 0x00020000, 0x00800040, 0x10020040, 0x10800040, 0x10820000, 0x00020040, 0x10000000, 0x00800000, 0x10020000, 0x10020000, 0x00000000, 0x10000040, 0x10820040, 0x10820040, 0x00800040, 0x10820000, 0x10000040, 0x00000000, 0x10800000, 0x00820040, 0x00800000, 0x10800000, 0x00020040, 0x00020000, 0x108000, 0x00800000, 0x10000000, 0x00820000, 0x108000, 0x10020000, 0x00800040, 0x10000000, 0x10820000, 0x00 820040, 0x10020040, 0x00000040, 0x00800000, 0x10820000, 0x10820040, 0x00020040, 0x10800000, 0x10820040, 0x00820000, 0x00000000, 0x10020000, 0x10800000, 0x00020040, 0x00800040, 0x10000040, 0x00020000, 0x00000000, 0x10020000, 0x00820040, 0x10000040, 0x00080000, 0x81080000, 0x81000200, 0x00000000, 0x00000200, 0x81000200, 0x80080200, 0x01080200, 0x81080200, 0x00080000, 0x00000000, 0x81000000, 0x80000000, 0x01000000, 0x81080000, 0x80000200, 0x01000200, 0x80080200, 0x80080000, 0x01000200, 0x81000000, 0x01080000, 0x01080200, 0x80080000,
0x01080000, 0x00000200, 0x80000200, 0x81080200, 0x00080200, 0x80000000, 0x01000000, 0x00080200, 0x01000000, 0x00080200, 0x00080000, 0x81000200, 0x81000200, 0x81080000, 0x81080000, 0x80000000, 0x80080000, 0x01000000, 0x01000200, 0x00080000, 0x01080200, 0x80000200, 0x80080200, 0x01080200, 0x80000200, 0x81000000, 0x81080200, 0x01080000, 0x00080200, 0x00000000, 0x80000000, 0x81080200, 0x00000000, 0x80080200, 0x01080000, 0x00000200, 0x81000000, 0x01000200, 0x00000200, 0x80080000}; / * S-boxes 2, 4, 6, 8, plus P permutation, rotated * / static word32 const SP1 [512] = {0x20042008, 0x20002000, 0x00002000, 0x00042008, 0x00040000, 0x00000008, 0x20040008, 0x20002008, 0x20000008, 0x20042008, 0x20042000, 0x20000000, 0x20002000, 0x00040000, 0x00000008, 0x20040008, 0x00042000, 0x0 0040008, 0x20002008, 0x00000000, 0x20000000, 0x00002000, 0x00042008, 0x20040000, 0x00040008, 0x20000008, 0x00000000, 0x00042000, 0x00002008, 0x20042000, 0x20040000, 0x00002008, 0x00000000, 0x00042008, 0x20040008, 0x00040000, 0x20002008, 0x20040000, 0x20042000, 0x00002000, 0x20040000, 0x20002000, 0x00000008, 0x20042008, 0x00042008, 0x00000008, 0x00002000, 0x20000000, 0x00002008, 0x20042000, 0x00040000, 0x20000008, 0x00040008, 0x20002008, 0x20000008, 0x00040008, 0x00042000, 0x00000000, 0x20002000, 0x00002008, 0x20000000, 0x20040008, 0x20042008,
0x00042000, 0x40200800, 0x40000820, 0x40000820, 0x00000020, 0x00200820, 0x40200020, 0x40200000, 0x40000800, 0x00000000, 0x00200800, 0x00200800, 0x40200820, 0x40000020, 0x00000000, 0x00200020, 0x40200000, 0x40000000, 0x00000800, 0x00200000, 0x40200800, 0x00000020, 0x00200000, 0x40000800, 0x00000820, 0x40200020, 0x40000000, 0x00000820, 0x00200020, 0x00000800, 0x00200820, 0x40200820, 0x40000020, 0x00200020, 0x40200000, 0x00200800, 0x40200820, 0x40000020, 0x00000000, 0x00000000, 0x00200800, 0x00000820, 0x00200020, 0x40200020, 0x40000000, 0x40200800, 0x40000820, 0x40000820, 0x00000020, 0x40200820, 0x400000, 0x00000800, 0x40200000, 0x40000800, 0x00200820, 0x402000, 0x40000800, 0x00000820, 0x00200000, 0x40200800, 0x00000020, 0x00200000, 0x00000800, 0x00200820, 0x08000004, 0x08100000, 0x00001000, 0x08101004, 0x08100000, 0x00000004, 0x08101004, 0x00100000, 0x08001000, 0x00101004, 0x00100000, 0x08000004, 0x00100004, 0x08001000, 0x08000000, 0x00001004, 0x00000000, 0x00100004, 0x08001004, 0x00001000, 0x00101000, 0x08001004, 0x00000004, 0x08100004, 0x00000000, 0x00101004, 0x08101000, 0x000000004, 0x00101000, 0x08101000, 0x0800004, 0x08001000, 0x00000004, 0x08100004, 0x00101000, 0x08101004, 0x00100000, 0x00001004,
0x08000004, 0x00100000, 0x08001000, 0x08000000, 0x00001004, 0x08000004, 0x08101004, 0x00101000, 0x08100000, 0x00101004, 0x08101000, 0x00000000, 0x08100004, 0x00000004, 0x00001000, 0x08100000, 0x00101004, 0x00001000, 0x00100004, 0x08001004, 0x00000000, 0x08101000, 0x08000000, 0x00100004, 0x08001004, 0x04000410, 0x00000400, 0x00010000, 0x04010410, 0x04000000, 0x04000410, 0x00000010, 0x04000000, 0x00010010, 0x04010000, 0x04010410, 0x00010400, 0x04010400, 0x00010410, 0x00000400, 0x00000010, 0x04010000, 0x04000010, 0x04000400, 0x00000410, 0x00010400, 0x00010010, 0x04010010, 0x04010400, 0x00000410, 0x00000000, 0x00000000, 0x04010010, 0x04000010, 0x04000400, 0x00 010410, 0x00010000, 0x00010410, 0x00010000, 0x04010400, 0x00000400, 0x00000010, 0x04010010, 0x00000400, 0x00010410, 0x04000400, 0x00000010, 0x04000010, 0x04010000, 0x04010010, 0x04000000, 0x00010000, 0x04000410, 0x00000000, 0x04010410, 0x00010010, 0x04000010, 0x04010000, 0x04000400, 0x04000410, 0x00000000, 0x04010410, 0x00010400, 0x00010400, 0x00000410, 0x00000410, 0x00010010, 0x04000000, 0x04010400}; / * * This encryption function is fairly clever in the way it does its * s-box lookup The S-boxes are indexed by bytes, rather. Than * Words,
because that's faster on many machines, and shifting * everything two bits to do the multiply by 4 is trivial. * Then, the indexing into the various S boxes is done by * adding the appropriate offset bits into the key array, so the * addition IS DONE BY THE WITH THE Rather Than Having to * / Void DESDES (Byte Const Inblock [8], Byte Outblock [8], Word32 Const * Keys) {Word32 S, T, Right,
Leftt; int ROCK [(Word32) Inblock [0] << 24) | ((Word32) Inblock [1] << 16) | ((Word32) Inblock [2] << 8) | (Word32) Inblock [3]; Right = ((Word32) Inblock [4] << 24) | (Word32) Inblock [5] << 16) | (Word32) Inblock [6] << 8) | (Word32) Inblock [ 7]; / * Initial Permutation ip * / t = ((Leftt >> 4) ^ Right) & 0x0f0f0f0fl; Right ^ = T; LEFTT ^ = (t << 4); t = ((Leftt >> 16) ^ Right) & 0x0000FFFFFL; Right ^ = T; Leftt ^ = (t << 16); t = ((Right >> 2) ^ leftt) & 0x333333331l; Leftt ^ = T; Right ^ = (t << 2); T = ((Right >> 8) ^ leftt) & 0x00FF00FFL; Leftt ^ = T; Right ^ = (t << 8); leftt = ((Leftt >> 1) | (Leftt << 31)); t = (leftt ^ Right) & 0x55555555L; LEFTT ^ = T; Right ^ = T; Right = ((Right >> 1) | (Right << 31)); for (Round = 0; Round <8; Round ) {s = (Right & 0xFCFCFCFC) ^ KEYS [0]; (((Right >> 28) | (Right << 4)) & 0xFCFCFCFC) ^ Keys [1]; Leftt ^ = * (Word32 *) ((char *) SP0 (S & 0x3FC) ) ^ * (Word32 *) ((CH)
Ar *) SP0 ((S >> 8) & 0x3FC)) ^ * (Word32 *) ((char *) SP0 ((S >> 16) & 0x3FC)) ^ * (Word32 *) ((char *) SP0 ((S >> 24) & 0x0FC)) ^ * (Word32 *) ((CHAR *) SP1 (T & 0x3FC)) ^ * (Word32 *) ((CHAR *) SP1 ((T >> 8) & 0x3FC )) ^ * (Word32 *) ((CHAR *) SP1 ((T >> 16) & 0x3FC) ^ * (Word32 *) ((CHAR *) SP1 ((T >> 24) & 0x0FC); s = (Leftt & 0xFCFCFCFC) ^ Keys [2]; T = (((Leftt >> 28) | (Leftt << 4)) & 0xFCFCFCFC) ^ Keys [3]; Right ^ = * (Word32 *) ((char *) SP0 (S & 0x3FC)) ^ * (Word32 *) ((CHAR *) SP0 ((S >> 8) & 0x3FC) ^ * (Word32 *) ((char *) SP0 ((S >> 16 ) & 0x3fc)) ^ * (Word32 *) ((char *) SP0 ((S >> 24) & 0x0fc)) ^ * (Word3 2 *) ((char *) SP1 (T & 0x3FC)) ^ * (Word32 *) ((char *) SP1 ((T >> 8) & 0x3FC) ^ * (Word32 *) ((char *) SP1 ((T >> 16) & 0x3FC)) ^ * (Word32 *) ((CHAR *) SP1 ((T >> 24) & 0x0FC); Keys = 4;}; / * inverse ip * / limited = ((LEFTT << 1) | (Leftt >> 31)); T = (Leftt ^ Right) & 0x55555555L; Leftt ^ = T; Right ^ = T; Right = ((R
IGHT << 1) | (Right >> 31)); T = ((Leftt >> 8) ^ Right) & 0x00FF00FFL; Right ^ = T; Leftt ^ = (t << 8); t = ((Leftt> > 2) ^ Right) & 0x33333333L; Right ^ = t; leftt ^ = (t << 2); t = ((Right >> 16) ^ leftt) & 0x0000FFFFL; Leftt ^ = T; Right ^ = (t < <16); t = ((Right >> 4) ^ leftt) & 0x0f0f0f0fl; leftt ^ = T; Right ^ = (t << 4); Outblock [0] = (byte) (Right >> 24); Outblock [1] = (byte) (Right >> 16); Outblock [2] = (Byte) (Right >> 8); Outblock [3] = (Byte) (Right); Outblock [4] = (Byte) LEFTT >> 24); Outblock [5] = (byte) (LEFTT >> 16); Outblock [6] = (Byte) (LEFTT >> 8); Outblock [7] = (Byte) (Leftt); Return; }; #undef Word32 #undef byte / **************************************************** ************* THE BELOW CODE (Package CODER) IS WRITEN IN "C " ************************ **************************************** / VOID CPAC Kage_Encoder :: setKey (const char * password) {unsigned i = 0; sbitblock key; key.dword.low = 0x4762226e8; key.dword.high = 0x87f5f4ad; while (password [i]) {key.byte [i% 8 ] ^ = (Password [i] (I >> 3) 37); i ;}; itDescoder.setkey (key); setseed (0x31a68e0d, 0x6508cb93);}; int cpackage_encoder :: Encrypt (unsigned char Destination " Const unsigned char source [], unsigned source, please, {unsigned i, j; sbitblock
A, B; theDescoder.encrypt (a, seed); for (i = 0; i <8; i ) destination [i] = a.byte [i]; a.dword.low = seed.dword.low; a .dword.high = seed.dword.high; for (i = 0, j = 8; i String sdet; unsigned char * src = new unsigned char [z 8]; for (int i = 0; i Author: meteor135 expert points: 4210 Member information Short message email Published: 2003-9-21 14:39:18 [Reply] On the 3rd floor The files given above the landlord are not a complete project, so I can't make a simple compilation. I spent a little more, I'm re-posing below, please do it as required, please ask. This post has not been scored Author: meteor135 expert points: 4210 Member information Short message email Published: 2003-9-21 14:44:50 [Reply] On the 4th floor / * This project consists of three source files (three files below), first need to open the des.cpp file with VC6.0, then directly compile the connection, there will be two errors, only need to be in VC6 Setting Using MFC as Static / Shared Library in Setting .0. Then add another two files to the project (this step is not required). Compile the connection again. * /// des.cpp: defines the entry point for the console application.//include This post has not been scored Author: meteor135 expert points: 4210 Member information Short message email Published: 2003-9-21 14:45:35 [Reply] On the 5th floor // Descode.h: interface for the cdescode class.///_pragma overce # include source) const {desDES ((unsigned char const *) (& source), (unsigned char *) (& destination), (unsigned long const *) encrypt_k);} inline void CDES_Encoder :: Decrypt (SBitBlock & destination, const SBitBlock & source) const {desDES ((unsigned char const *) (& source), (unsigned char *) (& destination), (unsigned long const *) decrypt_k);} inline void CPackage_Encoder :: SetSeed (unsigned long lo, unsigned long hi) {seed. DWord.low = LO; SEED.DWORD.HIGH = Hi;} inline void cpackage_encoder :: getseed (unsigned long (unsigned long "const {lo = seed.dword.low; hi = seed.dword.high;} Has not scored Author: meteor135 expert points: 4210 Member information Short message email Published: 2003-9-21 14:47:44 [Reply] On the 6th floor // DesCode.cpp: implementation of the CDesCode class.////#include "DesCode.h" #define word32 unsigned long #define byte unsigned char extern void deskey (unsigned char const * key, int decryptf, unsigned long * outbuf ); extern void desDES (unsigned char const inblock [8], unsigned char outblock [8], unsigned long const * keys); / * The size of a scheduled DES key * / #define DES_KEYWORDS 32 #define DES_KEYBYTES (sizeof (word32 ) * DES_KEYWORDS) static word32 const bigbyte [24] = {0x800000L, 0x400000L, 0x200000L, 0x100000L, 0x80000L, 0x40000L, 0x20000L, 0x10000L, 0x8000L, 0x4000L, 0x2000L, 0x1000L, 0x800L, 0x400L, 0x200L, 0x100L, 0x80L, 0x40L, 0x20L 0x10L, 0x8L, 0x4L, 0x2L, 0x1L}; / * Use the key Schedule Specified In The Standard (ANSI X3.92-1981). * / static byte const pc1 [56] = {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}; static Byte Const Totrot [16] = {1, 2 , 4, 6, 8, 10, 12, 14, 15, 17, 28}; static Byte Const PC2 [48] = {13, 16, 10, 23, 0, 4 , 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1, 40, 51, 30, 36, 46, 54, 29 , 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31}; / * * This is a less-this-brilliant key scheduation routine. * * * Cookey "Cooks" The key 通 "COOKS" The key inte "f" through 8 in adjacent words of the * "raw" array Ie the bits start out like this:. * xxxxxxxx111111222222333333444444 * xxxxxxxx555555666666777777888888 * We actually want the keys to look like this: * 111111xx333333xx555555xx777777xx * 222222xx444444xx666666xx888888xx * Where the "xx" patterns are set to 01020300 for use by the S-Box * Lookup code in the main encrypt loop. * / Static void cookey (word32 * raw, word32 * cooked) {for (int i = 0; i <16; i , raw = 2, COOKED = 2) {COOKED [0] = (RAW [0] & 0x00FC0000L) << 8; cooked [0] | = (Raw [0] & 0x00000FC0L) << 12; cooked [0] | = (RAW [ 1] & 0x00FC0000L) >> 8; COOKED [0] | = (RAW [1] & 0x00000FC0L) >> 4; COOKED [0] | = 0x01020300; Cooked [1] = (Raw [0] & 0x0003F000L) << Cooked [ 1] | = (Raw [0] & 0x0000003FL) << 18; cooked [1] | = (RAW [1] & 0x0003F000L) >> 2; Cooked [1] | = (RAW [1] & 0x0000003FL) << 2; cooked [1] | = 0x01020300;}} void deskey (byte const * key, int decryptf, word32 * outbuf) {INT I, J, L, M, N; Byte PC1M [56], PCR [56]; Word32 KN [32]; for (j = 0; j <56; j ) {L = PC1 [J]; M = L & 07; PC1M [J] = (Key [L >> 3] >> (~ L & 7)) & 1;} for (i = 0; i <16; i ) {m = (DECRYPTF? 15-i: I) << 1; n = m 1; KN [m] = kN [n] = 0L; for (j = 0; j <28; j ) {l = j Totrot [ I]; if (l> = 28) L - = 28; PCR [J] = PC1M [L];} for (j = 28; j <56; j ) {l = j Totrot [I]; IF ( L> = 56) L - = 28; PCR [J] = PC1M [L];} for (j = 0; j <24; j ) {ix (PCR [PC2 [J]]) KN [M] | = Bigbyte [J]; IF (PCR [PC2 [J 24]) KN [N] | = Bigbyte [J];}} Cookey (KN, Outbuf);} / * s-Boxes 1, 3, 5, 7 , Plus P Permutation, Rotated * / Static Word32 Const SP0 [512] = {0x00404100, 0x00000000, 0x00004000, 0x00404101, 0x00404001, 0x00004101, 0x00000001, 0x00004000, 0x00000100, 0x00404100, 0x00404101, 0x00000100, 0x00400101, 0x00404001, 0x00400000, 0x00000001, 0x00000101, 0x00400100, 0x00400100, 0x00004100, 0x00004100, 0x00404000, 0x00404000, 0x00400101, 0x00004001 , 0x00400001, 0x00400001, 0x00004001, 0x00000000, 0x00000101, 0x00004101, 0x00400000, 0x00004000, 0x00404101, 0x00000001, 0x00404000, 0x00404100, 0x00400000, 0x00400000, 0x00000100, 0x00404001, 0x00004000, 0x00004100, 0x00400001, 0x00000100, 0x00000001, 0x00400101, 0x00004101, 0x00404101, 0x00004001 , 0x00404000, 0x00400101, 0x00400001, 0x00000101, 0x00004101, 0x00404100, 0x00000101, 0x00400100, 0x00400100, 0x00000000, 0x00004001, 0x00004100, 0x00000000, 0x00404001, 0x00000082, 0x02008080, 0x00000000, 0x02008002, 0x02000080, 0x00000000, 0x00008082, 0x02000080, 0x00008002, 0x02000002, 0x02000002 , 0x00008000, 0x0200 8082, 0x00008002, 0x02008000, 0x00000082, 0x02000000, 0x00000002, 0x02008080, 0x00000080, 0x00008080, 0x02008000, 0x02008002, 0x00008082, 0x02000082, 0x00008080, 0x00008000, 0x02000082, 0x00000002, 0x02008082, 0x00000080, 0x02000000, 0x02008080, 0x02000000, 0x00008002, 0x00000082, 0x00008000, 0x02008080, 0x02000080, 0x00000000, 0x00000080, 0x00008002, 0x02008082, 0x02000080, 0x02000002, 0x00000080, 0x00000000, 0x02008002, 0x02000082, 0x00008000, 0x02000000, 0x02008082, 0x00000002, 0x00008082, 0x00008080, 0x02000002, 0x02008000, 0x02000082, 0x00000082, 0x02008000, 0x00008082, 0x00000002, 0x02008002, 0x00008080, 0x0000000040, 0x00820040, 0x00820000, 0x10800040, 0x00020000, 0x00000040, 0x10000000, 0x00820000, 0x10020040, 0x00020000, 0x00800040, 0x10020040, 0x10800040, 0x10820000, 0x00020040, 0x10000000, 0x00800000, 0x10020000, 0x10020000, 0x00000000, 0x10000040, 0x10820040, 0x10820040, 0x00800040, 0x10820000, 0x10000040, 0x00000000, 0x10800000, 0x00820040, 0x00800000, 0x10800000, 0x00020040, 0x00020000, 0x10800040, 0x00000040, 0x00800000, 0x10000000, 0x00820000, 0x10800040, 0x10020040, 0x00800040, 0x10000000, 0x10820000, 0x00820040, 0x10020040, 0x00000040, 0x00800000, 0x10820000, 0x10820040, 0x00020040, 0x10800000, 0x10820040, 0x00820000, 0x00000000, 0x10020000, 0x10800000, 0x00020040, 0x00800040, 0x10000040, 0x00020000, 0x00000000, 0x10020000, 0x00820040, 0x10000040, 0x00080000, 0x81080000, 0x81000200, 0x00000000, 0x00000200, 0x81000200, 0x80080200, 0x01080200, 0x81080200, 0x00080000, 0x00000000, 0x81000000, 0x80000000, 0x01000000, 0x81080000, 0x80000200, 0x01000200, 0x80080200, 0x80080000, 0x01000200, 0x81000000, 0x01080000, 0x01080200, 0x80080000, 0x01080000, 0x00000200, 0x80000200, 0x81080200, 0x00080200, 0x80000000, 0x01000000, 0x00080200, 0x01000000, 0x00080200, 0x00080000, 0x81000200, 0x81000200, 0x81080000, 0x81080000, 0x80000000, 0x80080000, 0x01000000, 0x01000200, 0x00080000, 0x01080200, 0x80000200, 0x80080200, 0x01080200, 0x80000200, 0x81000000, 0x81080200, 0x01080000, 0x00080200, 0x00000000, 0x80000000, 0x81080200, 0x00000000, 0x80080200, 0x01080000, 0x00000200, 0x81000000, 0x01000200, 0x00000200, 0x80080000}; / * S-boxes 2, 4, 6, 8, Plus P Permutation, Rotated * / Static Word32 Const SP1 [512] = {0x20042008, 0x20002000, 0x00002000, 0x00042008, 0x00040000, 0x00000008, 0x20040008, 0x20002008, 0x20000008, 0x20042008, 0x20042000, 0x20000000, 0x20002000, 0x00040000, 0x00000008, 0x20040008, 0x00042000, 0x00040008, 0x20002008, 0x00000000, 0x20000000, 0x00002000, 0x00042008, 0x20040000, 0x00040008, 0x20000008, 0x00000000, 0x00042000, 0x00002008, 0x20042000, 0x20040000, 0x00002008, 0x00000000, 0x00042008, 0x20040008, 0x00040000, 0x20002008, 0x20040000, 0x20042000, 0x00002000, 0x20040000, 0x20002000, 0x00000008, 0x20042008, 0x00042008, 0x00000008, 0x00002000, 0x20000000, 0x00002008, 0x20042000, 0x00040000, 0x20000008, 0x00040008, 0x20002008, 0x20000008, 0x00040008, 0x00042000, 0x00000000, 0x20002000, 0x00002008, 0x20000000, 0x20040008, 0x20042008, 0x00042000, 0x40200800, 0x40000820, 0x40000820, 0x00000020, 0x00200820, 0x40200020, 0x40200000, 0x40000800, 0x00000000, 0x00200800, 0x00200800, 0x40200820, 0x40000020, 0x00000000, 0x00200020, 0x40200000, 0x40000000, 0x00000800, 0x00200000, 0x40200800, 0x00000020, 0x00200000, 0x40000800, 0x00000820, 0x40200020, 0x40000000, 0x00000820, 0x00200020, 0x00000800, 0x00200820, 0x40200820, 0x40000020, 0x00200020, 0x40200000, 0x00200800, 0x40200820, 0x40000020, 0x00000000, 0x00000000, 0x00200800, 0x00000820, 0x00200020, 0x40200020, 0x40000000, 0x40200800, 0x40000820, 0x40000820, 0x00000020, 0x40200820, 0x40000020, 0x40000000, 0x00000800, 0x40200000, 0x40000800, 0x00200820, 0x40200020, 0x40000800, 0x00000820, 0x00200000, 0x40200800, 0x00000020, 0x00200000, 0x00000800, 0x00200820, 0x08000004, 0x08100000, 0x00001000, 0x08101004, 0x08100000, 0x00000004, 0x08101004, 0x00100000, 0x08001000, 0x00101004, 0x00100000, 0x08000004, 0x00100004, 0x08001000, 0x08000000, 0x00001004, 0x00000000, 0x00100004, 0x08001004, 0x00001000, 0x00101000, 0x08001004, 0x00000004, 0x08100004, 0x08100004, 0x00000000, 0x00101004, 0x08101000, 0x00001004, 0x00101000, 0x08101000, 0x08000000, 0x08001000, 0x00000004, 0x08100004, 0x00101000, 0x08101004, 0x00100000, 0x00001004, 0x08000004, 0x00100000, 0x08001000, 0x08000000, 0x00001004, 0x08000004, 0x08101004, 0x00101000, 0x08100000, 0x00101004, 0x08101000, 0x00000000, 0x08100004, 0x00000004, 0x00001000, 0x08100000, 0x00101004, 0x00001000, 0x00100004, 0x08001004, 0x00000000, 0x08101000, 0x08000000, 0x00100004, 0x08001004, 0x04000410, 0x00000400, 0x00010000, 0x04010410, 0x04000000, 0x04000410, 0x00000010, 0x04000000, 0x00010010, 0x04010000, 0x04010410, 0x00010400, 0x04010400, 0x00010410, 0x00000400, 0x00000010, 0x04010000, 0x04000010, 0x04000400, 0x00000410, 0x00010400, 0x00010010, 0x04010010, 0x04010400, 0x00000410, 0x00000000, 0x00000000, 0x04010010, 0x04000010, 0x04000400, 0x00010410, 0x00010000, 0x00010410, 0x00010000, 0x04010400, 0x00000400, 0x00000010, 0x04010010, 0x00000400, 0x00010410, 0x04000400, 0x00000010, 0x04000010, 0x04010000, 0x04010010, 0x04000000, 0x00010000, 0x04000410, 0x00000000, 0x04010410, 0x00010010, 0x04000010, 0x04010000, 0x04000400, 0x04000410, 0x00000000, 0x04010410, 0x00010400, 0x00010400, 0x00000410, 0x00000410, 0x00010010, 0x04000000, 0x04010400}; / * * This encryption function is fairly clever in the way it does its * s-box Lookup. The s-boxes area indexed by bytes, rather tran * word, Because That's Faster ON MACHINES, and shifting * everything two bits to do the multiply by 4 is trivial. * Then, the indexing into the various S boxes is done by * adding the appropriate offset bits into the key array, so the * addition is done by the XOR with the Key Rather Than Having to * Be Done Explicitly Here. * / Void Des (Byte Const Inblock [8], Byte Outblock [8], Word32 Const * Keys) {Word32 S, T, Right, Leftt; int ROCK [(Word32) Inblock [0] << 24) | ((Word32) Inblock [1] << 16) | ((Word32) Inblock [2] << 8) | (Word32) Inblock [3]; Right = ((Word32) Inblock [4] << 24) | (Word32) Inblock [5] << 16) | (Word32) Inblock [6] << 8) | (Word32) Inblock [ 7]; / * Initial Permutation ip * / t = ((Leftt >> 4) ^ Right) & 0x0f0f0f0fl; Right ^ = T; LEFTT ^ = (t << 4); t = ((Leftt >> 16) ^ Right) & 0x0000FFFFFL; Right ^ = T; Leftt ^ = (t << 16); t = ((Right >> 2) ^ leftt) & 0x333333331l; Leftt ^ = T; Right ^ = (t << 2); T = ((Right >> 8) ^ leftt) & 0x00FF00FFL; Leftt ^ = T; Right ^ = (t << 8); leftt = ((Leftt >> 1) | (Leftt << 31)); t = (Leftt ^ Right) & 0x55555555L; LEFTT ^ = T; Right ^ = T; Right = ((Right >> 1) | for (Round = 0; Round <8; Round ) {s = (Right & 0xFCFCFCFC) ^ Keys [0]; T = (((Right >> 28) | (Right << 4)) & 0xFCFCFCFC) ^ Keys [1]; LEFTT ^ = * (Word32 *) ((CHAR *) SP0 (S & 0x3FC)) ^ * (Word32 * ((char *) SP0 ((S >> 8) & 0x3FC)) ^ * (Word32 *) ((CHAR *) SP0 ((S >> 16) & 0x3FC)) ^ * (Word32 *) ((charr) *) SP0 ((S >> 24) & 0x0FC)) ^ * (Word32 *) ((char *) SP1 (T & 0x3FC)) ^ * (Word32 *) ((char *) SP1 ((T >> 8 ) & 0x3fc)) ^ * (Word32 *) (Word32 *) (CHAR *) SP1 ((T >> 16) & 0x3FC)) ^ * (Word32 *) ((CHAR *) SP1 ((T >> 24) & 0x0FC); s = (Leftt & 0xFCFCFCFC) ^ Keys [ 2]; T = ((Leftt >> 28) | (Leftt << 4)) & 0xFCFCFCFC) ^ Keys [3]; Right ^ = * (Word32 *) ((char *) SP0 (S & 0x3FC)) ^ * (Word32 *) ((CHAR *) SP0 (S >> 8) & 0x3FC)) ^ * (Word32 *) ((char *) SP0 ((S >> 16) & 0x3FC) ^ * (Word32 *) (CHAR *) SP0 ((S >> 24) & 0x0FC) ^ * (Word32 *) ((char *) SP1 (T & 0x3FC)) ^ * (Word32 *) ((char *) SP1 ( (T >> 8) & 0x3FC)) ^ * (Word32 *) ((CHAR *) SP1 ((T >> 16) & 0x3FC) ^ * (Word32 *) ((char *) SP1 ((T >> 24) & 0x0FC); Keys = 4;} / * inverse ip * / leftt = ((Leftt << 1) | (Leftt >> 31)); T = (Leftt ^ Right) & 0x55555555l; Leftt ^ = T; Right ^ = T; Right = ((Right << 1) | (Right >> 31)); T = ((Leftt >> 8) ^ Right) & 0x00FF00FFL; Right ^ = T; LEFTT = (T << 8); T = ((Leftt >> 2) ^ Right) & 0x33333333 L; Right ^ = T; LEFTT ^ = (t << 2); t = ((Right >> 16) ^ leftt) & 0x0000FFFFL; leftt ^ = T; Right ^ = (t << 16); t = (Right >> 4) ^ leftt) & 0x0f0f0f0fl; leftt ^ = T; Right ^ = (t << 4); Outblock [0] = (byte) (Right >> 24); Outblock [1] = (Byte) (Right >> 16); Outblock [2] = (Byte) (Right >> 8); Outblock [3] = (Byte) (Right); Outblock [4] = (B YTE) (Leftt >> 24); Outblock [5] = (byte) (LEFTT >> 16); Outblock [6] = (Byte) (LEFTT >> 8); Outblock [7] = (Byte) (Leftt) } #undef Word32 #undef byte / ************************************************************ ************* THE BELOW CODE (Package CODER) IS WRITEN IN "C " ************************ **************************************** / VOID CPACKAGE_ENCODER :: SetKey (const char * password) {unsigned i = 0; sbitblock Key; key.dword.low = 0x476226e8; key.dword.high = 0x87f5f4ad; while (password [i]) {key.byte [i% 8] ^ = (Password [i] (i >> 3) 37 ); i ;} theDEScoder.SetKey (key); SetSeed (0x31A68E0D, 0x6508CB93);} int CPackage_Encoder :: Encrypt (unsigned char destination [], const unsigned char source [], unsigned sourcesize) const {unsigned i, j; SBitBlock A, B; theDescoder.encrypt (a, seed); for (i = 0; i <8; i ) destination [i] = a.byte [i]; a.dword.low = seed.dword.low; a .dword.high = seed.dword.high; for (i = 0, j = 8; i ; 8; J Author: autuy123 expert points: 0 Member information Short message email Published: 2003-9-21 18:04:46 [Reply] Granter Can you talk about it? What is the details of explanation? We can understand! This post has not been scored Author: Moon Shadow expert points: 80 Member information Short message email Published: 2003-9-22 18:44:32 [Reply] On the 8th floor Uh hm cough ... DES's full name seems to be Data Encrytion Standard ... is also [Data Encryption Standard] ... Since this, the DES encryption algorithm is roughly a set of replacement in accordance with the DES standard.加文 加算 算算 加 ... ... 文 文 文 加 文 常 文 文 文 文 文 文 文 文 文 文 文 文 文 文 文 文 文 密 密 文 密 文 文 文 文 文 文 文 文 文 文 文 文 文 文 文 文It can simplify it into a linear constant causal system ... set the express text as X, ciphertext is Y, the key is M, H is a specific standard clear text to M encryption output Cipher (M encrypted) Cipher (M encrypted) = X (m) * h (m) system can be considered a DES linear encryption system ... This post has not been scored Author: lanjingquan expert points: 500 Member information Short message email Published: 2003-9-23 11:00:47 [Reply] Grace Your present position: Hutongkou> Computer and Network> Programming Technology> C Builder Forum http://d23181823.xici.net DES Encryption Algorithm Introduction This post copyright belongs to the original author, other media or website reprint, please contact E Dragon West Alley [http://www.xici.net] or the original author contacts and indicates the source. Author: Han Shan Yu Issue Date: 2003-01-16 09:39:53 return to "C Builder Forum" quick return of: Shura called the Data Encryption Standard DES data encryption algorithm, which is IBM's successful research and public Published. There are three entrance parameters of the DES algorithm: Key, Data, Mode. Where KEY is 8 bytes a total of 64 bits, which is the working key of the DES algorithm; DATA is also 8 bytes of 64 bits, is the data to be encrypted or decrypted; Mode is desperate, there are two types: Encryption or decryption. The DES algorithm is working like this: If Mode is encrypted, use Key to encrypt data DATA, generate DATA's password (64-bit) as the output result of DES; if Mode is decrypted, use Key to put the password form Data DATA decryption, restoring the image of the DATA (64-bit) as the output result of the DES. On both ends of the communication network, the two parties agree to en encrypt the core data in the source of communication with Key, and then transmitted to the communication network in the public communication network (such as the telephone network) in the form of a password. After the destination, the cryptographic data is decrypted with the same Key, and the core data of the coded form is reproduced. In this way, the security and reliability of the core data (such as PIN, MAC, etc.) is transmitted in the public communication network. The confidentiality of data can be further improved by simultaneously using new Key from the source and destination of the communication network. Detail DES Algorithm Detail The 64-bit express input block becomes 64-bit ciphertext block, which is also 64 bits, the mainstream diagram of the entire algorithm is as follows: The function is to input the input 64-bit data The block is re-combined, and the output is divided into L0, R0, each of which is 32 points, and its replacement rules are shown below: 58, 50, 12, 34, 26, 18, 10, 2, 60, 52 44, 36, 28, 20, 12, 4, 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, 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, the 58th of the input is changed to the first bit, and the 50th is changed to the second bit, ..., according to this type, the last bit is the original 7th bit. L0, R0 is the two parts after the transposition output, and the L0 is the left 32 bits of the output, and R0 is the right 32 bits, an example: set the input value of D1D2D2D3 ... D64, after initial replacement The result is: L0 = D58D50 ... D8; R0 = D57D49 ... D7. After 26 iterative operations. L16, R16 gets this as input, and the reverse replacement is performed, that is, the ciphertext output is obtained. The inverse replacement is exactly the initial counterputation, for example, after the initial replacement, in the 40th, by reverse replacement, the inverse replacement rules are shown in the table below. : 40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31, 38, 6, 46, 14, 54, 22, 62, 30, 37 5, 45, 13, 53, 21, 61, 29, 36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, 34, 2 42, 10, 50, 18, 58 26, 33, 1, 41, 9, 49, 17, 57, 25, amplifying Tables 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13, 17, 12, 19, 20, 21, 20, 21, 22, 23, 24, 25, 24, 25, 26, 27, 28, 29, 28, 29, 30, 31, 32, 1, simple transposition table 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 2, 5, 18, 31, 10, 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25, in F (Ri , Ki) In the diagram, S1, S2 ... S8 is the selection function, which is functional to turn the 6bit data to 4 bit data. The menu of the selection function Si (i = 1, 2 ... 8) is given: Select the function sis1: 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13, s2: 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9, s3: 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, 13, 6, 4, 9, 8, 15, 3, 10, 11, 1, 2, 12, 5, 10, 14, 7, 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12, s4: 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14, S5: 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3, s6: 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13, s7: 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12, s8: 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11, here to see the function as an example, we can see: In S1, there are 4 lines of data, named 0, 1, 2, 3 lines; 16 columns per line, named 0, 1, 2, 3, ..., 14, 15 columns. The input is: D = D1D2D3D4D5D6 order: column = D2D3D4D5 line = D1D6 then enables the corresponding number in the S1 table, indicated in a 4-bit binary, that is, the output of the selection function S1. The generation algorithm for the child key Ki (48bit) is given from the generated algorithm of the sub-key Ki. We can see: the initial key value is 64 bits, but the DES algorithm is set, of which 8th, 16, ... ... 64 bits are parity blocks and do not participate in the DES operation. Therefore, KEY is only 56. That is, after the change of the change in the selection of the transmissions Table 1, the number of keys turned from 64 bits to 56 bits. This 56 bit is divided into C0, D0 two parts, each 28 bits, then perform the first cycle left shift , Obtain C1, D1, combined with C1 (28), D1 (28) to obtain 56 bits, and then reducing the selection of transposition 2, thereby obtaining a key K0 (48 bits). If you push it, you can get K1, K2, ..., K15, but it should be noted that the left shift bit number of 16 cyclic left shifts should be performed according to the following rules: cyclic left shift number 1 The encryption process of the DES algorithm is described above 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, and 1. The DES algorithm decryption process is the same, and the difference is only to use sub-key K15, the second K14, ..., the last time I use K0, and the algorithm itself does not change. Fighting first programming second game third view of the fourth here is not connected ------------------------------- ---------------------------- Since humility, I am a strong manager. I have learned the full loss of the four cars, standing on a strong position, seriously studying a generation of atrivolous style, insisting that I am vertical, finally become a research. As a person who loves people, sometimes it will be lonely men. I shouted to the sky, I want to inflammation: Laozi is a brother, and Laozi rely on life. Finally created my geographical life ... Level Egg Festival is here, congratulations to everyone. Xiaoxiang Night Rain River in Snow, Its Mountain Shilong Mountain Jade ----------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------- Article topic: No subject return "C Builder Forum" quickly returns to the passenger can't post a speech, please log in or register new username community home page | Hutong simple history | West Temple station regulations | Use Guide | Network regulations | Privacy protection | Advertising services | User registration advertisement: 025-4511487: Webmaster@xici.net Station Hotline: 025-4511787-205, 010-65886448-550 Copyright: Elong.com Jing ICP Certificate 010011 White Sweet Swords Has not scored Website Profile - Site Navigation - Advertising Service - invites to join - Contact webmaster - friendship link - sponsoring this site CopyRight © 1999-2004 Programfan.com. All Rights Reserved Forum Production & Maintenance: Hannibal QQ: 15987743