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

📄 risto-des.shar

📁 多种环境下的实现方式
💻 SHAR
📖 第 1 页 / 共 2 页
字号:
#! /bin/sh# This is a shell archive.  Remove anything before this line, then unpack# it by saving it into a file and typing "sh file".  To overwrite existing# files, type "sh file -c".  You can also feed this as standard input via# unshar, or by typing "sh <file", e.g..  If this archive is complete, you# will see the following message at the end:#		"End of shell archive."# Contents:  README.mdes des_test_data destest.c mdes.c mdes.h# Wrapped by paasivir@tukki on Thu Aug 11 09:33:21 1994PATH=/bin:/usr/bin:/usr/ucb ; export PATHif test -f README.mdes -a "${1}" != "-c" ; then   echo shar: Will not over-write existing file \"README.mdes\"elseecho shar: Extracting \"README.mdes\" \(3025 characters\)sed "s/^X//" >README.mdes <<'END_OF_README.mdes'XXmdes.c, mdes.h, destest, des_test_dataXX        Public Domain, NO WARRANRY.XX        This is a trivial DES implementation I wrote to figure outX        the algorithm. It's very slow. There are many faster freeX        implementations around.XX        In USA this code may or may not be subject of export regulations,X        etc.XXVersionXX        1.0, first and probably last if des_cbc_encrypt (untested) works.XXAuthorX        Risto Paasivirta, paasivir@jyu.fiXX=============================================================================XXmdes.hXX                #define DES_ENCRYPT        1X                #define DES_DECRYPT        0XX        Des encryption flag. Encrypt if DES_ENCRYPT, decrypt if DES_DECRYPT.X        (Doesn't sound too complex, does it.)XX                typedef struct des_key_schedule {X                        unsigned char b[16][48];X                } des_key_schedule;XX        Key schedule type. Key bits are left unpacked for 'speed'.XXX                typedef struct des_cblock {X                        unsigned char _[8];X                } des_cblock;XX        Des character block type. Any 8 char block should work fine.XXmdes.cXX        Des functionsXX                void des_set_odd_parity(des_cblock *key);XX        Set parity of 56-bit (7bits x 8 bytes) key block. Parity bit isX        the least significant bit in each byte. This implementation worksX        with incorrect parity key blocks.XX                int des_set_key(des_cblock *k, des_key_schedule *key);XX        Initialize key schedule from key block k. If key checking would beX        implemented this probably should return some value.XX                int des_ecb_encrypt(des_cblock *input, des_cblock *output,X                        des_key_schedule *schedule, int encrypt);XX        Des encryption in des electronic code book mode. En/decrypt oneX        cblock from input to output using key shedule. Returns numberX        of bytes written to output (8.)XX                int des_cbc_encrypt(des_cblock *input, des_cblock *output,X                        int len, des_key_schedule *key,X                        des_cblock *ivec, int mode);XX        Des encryption in cipher block chaining mode. En/decrypt len bytesX        from input to output using scheduled key and initial ivec. If len isX        not multiple of 8, last block is padded with NULL bytes. Output isX        written always multiple of 8 bytes. Returns number of bytes writtenX        to output and final ivec in ivec.XXdestest.cXdes_test_dataXX        Destest reads file des_test_data, converts hex key/plain/cipherX        cblock to binary and checks that en/decryption works in elecrtoricX        code book mode. File des_test_data has been posted few times toX        sci.crypt, only thing I have done to it was that I corrected one X        key parity error from line 143:X        originalX        3107911598090140 0000000000000000 406A9A6AB43399AEX        changed to:X        3107911598080140 0000000000000000 406A9A6AB43399AEXX(eof)END_OF_README.mdesif test 3025 -ne `wc -c <README.mdes`; then    echo shar: \"README.mdes\" unpacked with wrong size!fi# end of overwriting checkfiif test -f des_test_data -a "${1}" != "-c" ; then   echo shar: Will not over-write existing file \"des_test_data\"elseecho shar: Extracting \"des_test_data\" \(8854 characters\)sed "s/^X//" >des_test_data <<'END_OF_des_test_data'XXKey              Plain            CipherX X/* IP and E Test */X X0101010101010101 95F8A5E5DD31D900 8000000000000000X0101010101010101 DD7F121CA5015619 4000000000000000X0101010101010101 2E8653104F3834EA 2000000000000000X0101010101010101 4BD388FF6CD81D4F 1000000000000000X0101010101010101 20B9E767B2FB1456 0800000000000000X0101010101010101 55579380D77138EF 0400000000000000X0101010101010101 6CC5DEFAAF04512F 0200000000000000X0101010101010101 0D9F279BA5D87260 0100000000000000X0101010101010101 D9031B0271BD5A0A 0080000000000000X0101010101010101 424250B37C3DD951 0040000000000000X0101010101010101 B8061B7ECD9A21E5 0020000000000000X0101010101010101 F15D0F286B65BD28 0010000000000000X0101010101010101 ADD0CC8D6E5DEBA1 0008000000000000X0101010101010101 E6D5F82752AD63D1 0004000000000000X0101010101010101 ECBFE3BD3F591A5E 0002000000000000X0101010101010101 F356834379D165CD 0001000000000000X0101010101010101 2B9F982F20037FA9 0000800000000000X0101010101010101 889DE068A16F0BE6 0000400000000000X0101010101010101 E19E275D846A1298 0000200000000000X0101010101010101 329A8ED523D71AEC 0000100000000000X0101010101010101 E7FCE22557D23C97 0000080000000000X0101010101010101 12A9F5817FF2D65D 0000040000000000X0101010101010101 A484C3AD38DC9C19 0000020000000000X0101010101010101 FBE00A8A1EF8AD72 0000010000000000X0101010101010101 750D079407521363 0000008000000000X0101010101010101 64FEED9C724C2FAF 0000004000000000X0101010101010101 F02B263B328E2B60 0000002000000000X0101010101010101 9D64555A9A10B852 0000001000000000X0101010101010101 D106FF0BED5255D7 0000000800000000X0101010101010101 E1652C6B138C64A5 0000000400000000X0101010101010101 E428581186EC8F46 0000000200000000X0101010101010101 AEB5F5EDE22D1A36 0000000100000000X0101010101010101 E943D7568AEC0C5C 0000000080000000X0101010101010101 DF98C8276F54B04B 0000000040000000X0101010101010101 B160E4680F6C696F 0000000020000000X0101010101010101 FA0752B07D9C4AB8 0000000010000000X0101010101010101 CA3A2B036DBC8502 0000000008000000X0101010101010101 5E0905517BB59BCF 0000000004000000X0101010101010101 814EEB3B91D90726 0000000002000000X0101010101010101 4D49DB1532919C9F 0000000001000000X0101010101010101 25EB5FC3F8CF0621 0000000000800000X0101010101010101 AB6A20C0620D1C6F 0000000000400000X0101010101010101 79E90DBC98F92CCA 0000000000200000X0101010101010101 866ECEDD8072BB0E 0000000000100000X0101010101010101 8B54536F2F3E64A8 0000000000080000X0101010101010101 EA51D3975595B86B 0000000000040000X0101010101010101 CAFFC6AC4542DE31 0000000000020000X0101010101010101 8DD45A2DDF90796C 0000000000010000X0101010101010101 1029D55E880EC2D0 0000000000008000X0101010101010101 5D86CB23639DBEA9 0000000000004000X0101010101010101 1D1CA853AE7C0C5F 0000000000002000X0101010101010101 CE332329248F3228 0000000000001000X0101010101010101 8405D1ABE24FB942 0000000000000800X0101010101010101 E643D78090CA4207 0000000000000400X0101010101010101 48221B9937748A23 0000000000000200X0101010101010101 DD7C0BBD61FAFD54 0000000000000100X0101010101010101 2FBC291A570DB5C4 0000000000000080X0101010101010101 E07C30D7E4E26E12 0000000000000040X0101010101010101 0953E2258E8E90A1 0000000000000020X0101010101010101 5B711BC4CEEBF2EE 0000000000000010X0101010101010101 CC083F1E6D9E85F6 0000000000000008X0101010101010101 D2FD8867D50D2DFE 0000000000000004X0101010101010101 06E7EA22CE92708F 0000000000000002X0101010101010101 166B40B44ABA4BD6 0000000000000001X X/* PC1 and PC2 test */X X8001010101010101 0000000000000000 95A8D72813DAA94DX4001010101010101 0000000000000000 0EEC1487DD8C26D5X2001010101010101 0000000000000000 7AD16FFB79C45926X1001010101010101 0000000000000000 D3746294CA6A6CF3X0801010101010101 0000000000000000 809F5F873C1FD761X0401010101010101 0000000000000000 C02FAFFEC989D1FCX0201010101010101 0000000000000000 4615AA1D33E72F10X0180010101010101 0000000000000000 2055123350C00858X0140010101010101 0000000000000000 DF3B99D6577397C8X0120010101010101 0000000000000000 31FE17369B5288C9X0110010101010101 0000000000000000 DFDD3CC64DAE1642X0108010101010101 0000000000000000 178C83CE2B399D94X0104010101010101 0000000000000000 50F636324A9B7F80X0102010101010101 0000000000000000 A8468EE3BC18F06DX0101800101010101 0000000000000000 A2DC9E92FD3CDE92X0101400101010101 0000000000000000 CAC09F797D031287X0101200101010101 0000000000000000 90BA680B22AEB525X0101100101010101 0000000000000000 CE7A24F350E280B6X0101080101010101 0000000000000000 882BFF0AA01A0B87X0101040101010101 0000000000000000 25610288924511C2X0101020101010101 0000000000000000 C71516C29C75D170X0101018001010101 0000000000000000 5199C29A52C9F059X0101014001010101 0000000000000000 C22F0A294A71F29FX0101012001010101 0000000000000000 EE371483714C02EAX0101011001010101 0000000000000000 A81FBD448F9E522FX0101010801010101 0000000000000000 4F644C92E192DFEDX0101010401010101 0000000000000000 1AFA9A66A6DF92AEX0101010201010101 0000000000000000 B3C1CC715CB879D8X0101010180010101 0000000000000000 19D032E64AB0BD8BX0101010140010101 0000000000000000 3CFAA7A7DC8720DCX0101010120010101 0000000000000000 B7265F7F447AC6F3X0101010110010101 0000000000000000 9DB73B3C0D163F54X0101010108010101 0000000000000000 8181B65BABF4A975X0101010104010101 0000000000000000 93C9B64042EAA240X0101010102010101 0000000000000000 5570530829705592X0101010101800101 0000000000000000 8638809E878787A0X0101010101400101 0000000000000000 41B9A79AF79AC208X0101010101200101 0000000000000000 7A9BE42F2009A892X0101010101100101 0000000000000000 29038D56BA6D2745X0101010101080101 0000000000000000 5495C6ABF1E5DF51X0101010101040101 0000000000000000 AE13DBD561488933X0101010101020101 0000000000000000 024D1FFA8904E389X0101010101018001 0000000000000000 D1399712F99BF02EX0101010101014001 0000000000000000 14C1D7C1CFFEC79EX0101010101012001 0000000000000000 1DE5279DAE3BED6FX0101010101011001 0000000000000000 E941A33F85501303X0101010101010801 0000000000000000 DA99DBBC9A03F379X0101010101010401 0000000000000000 B7FC92F91D8E92E9X0101010101010201 0000000000000000 AE8E5CAA3CA04E85X0101010101010180 0000000000000000 9CC62DF43B6EED74X0101010101010140 0000000000000000 D863DBB5C59A91A0X0101010101010120 0000000000000000 A1AB2190545B91D7X0101010101010110 0000000000000000 0875041E64C570F7X0101010101010108 0000000000000000 5A594528BEBEF1CCX0101010101010104 0000000000000000 FCDB3291DE21F0C0X0101010101010102 0000000000000000 869EFD7F9F265A09X X/* P Test */X X1046913489980131 0000000000000000 88D55E54F54C97B4X1007103489988020 0000000000000000 0C0CC00C83EA48FDX10071034C8980120 0000000000000000 83BC8EF3A6570183X1046103489988020 0000000000000000 DF725DCAD94EA2E9X1086911519190101 0000000000000000 E652B53B550BE8B0X1086911519580101 0000000000000000 AF527120C485CBB0X5107B01519580101 0000000000000000 0F04CE393DB926D5X1007B01519190101 0000000000000000 C9F00FFC74079067X3107915498080101 0000000000000000 7CFD82A593252B4EX3107919498080101 0000000000000000 CB49A2F9E91363E3X10079115B9080140 0000000000000000 00B588BE70D23F56X3107911598090140 0000000000000000 406A9A6AB43399AEX1007D01589980101 0000000000000000 6CB773611DCA9ADAX9107911589980101 0000000000000000 67FD21C17DBB5D70X9107D01589190101 0000000000000000 9592CB4110430787X1007D01598980120 0000000000000000 A6B7FF68A318DDD3X1007940498190101 0000000000000000 4D102196C914CA16X0107910491190401 0000000000000000 2DFA9F4573594965X0107910491190101 0000000000000000 B46604816C0E0774X0107940491190401 0000000000000000 6E7E6221A4F34E87X19079210981A0101 0000000000000000 AA85E74643233199X1007911998190801 0000000000000000 2E5A19DB4D1962D6X10079119981A0801 0000000000000000 23A866A809D30894X1007921098190101 0000000000000000 D812D961F017D320X100791159819010B 0000000000000000 055605816E58608FX1004801598190101 0000000000000000 ABD88E8B1B7716F1X1004801598190102 0000000000000000 537AC95BE69DA1E1X1004801598190108 0000000000000000 AED0F6AE3C25CDD8X1002911598100104 0000000000000000 B3E35A5EE53E7B8DX1002911598190104 0000000000000000 61C79C71921A2EF8X1002911598100201 0000000000000000 E2F5728F0995013CX1002911698100101 0000000000000000 1AEAC39A61F0A464X X/* S-box test */X X7CA110454A1A6E57 01A1D6D039776742 690F5B0D9A26939BX0131D9619DC1376E 5CD54CA83DEF57DA 7A389D10354BD271X07A1133E4A0B2686 0248D43806F67172 868EBB51CAB4599AX3849674C2602319E 51454B582DDF440A 7178876E01F19B2AX04B915BA43FEB5B6 42FD443059577FA2 AF37FB421F8C4095X0113B970FD34F2CE 059B5E0851CF143A 86A560F10EC6D85BX0170F175468FB5E6 0756D8E0774761D2 0CD3DA020021DC09X43297FAD38E373FE 762514B829BF486A EA676B2CB7DB2B7AX07A7137045DA2A16 3BDD119049372802 DFD64A815CAF1A0FX04689104C2FD3B2F 26955F6835AF609A 5C513C9C4886C088X37D06BB516CB7546 164D5E404F275232 0A2AEEAE3FF4AB77X1F08260D1AC2465E 6B056E18759F5CCA EF1BF03E5DFA575AX584023641ABA6176 004BD6EF09176062 88BF0DB6D70DEE56X025816164629B007 480D39006EE762F2 A1F9915541020B56X49793EBC79B3258F 437540C8698F3CFA 6FBF1CAFCFFD0556X4FB05E1515AB73A7 072D43A077075292 2F22E49BAB7CA1ACX49E95D6D4CA229BF 02FE55778117F12A 5A6B612CC26CCE4AX018310DC409B26D6 1D9D5C5018F728C2 5F4C038ED12B2E41X1C587F1C13924FEF 305532286D6F295A 63FAC0D034D9F793X END_OF_des_test_dataif test 8854 -ne `wc -c <des_test_data`; then    echo shar: \"des_test_data\" unpacked with wrong size!fi# end of overwriting checkfiif test -f destest.c -a "${1}" != "-c" ; then   echo shar: Will not over-write existing file \"destest.c\"elseecho shar: Extracting \"destest.c\" \(2103 characters\)sed "s/^X//" >destest.c <<'END_OF_destest.c'X/*---------------------------------------------------------------------------X * destest.cX *X *X * 27-Feb-92 RPX * 06-Jan-93 RP (for libdes)X */XX#include <stdio.h>X#include <stdlib.h>X#include <string.h>XX#include "mdes.h"XX#define ctod(d) ((d) <= '9' ? (d) - '0' : (d) <= 'Z' ? (d) - ('A'-10):\X  (d) - ('a' - 10))XXint des_hex_to_cblock(des_cblock *b, char *c)X{X  int i,n,m;X  for(i = 0; i < 8; i++) {X    if((n=ctod(c[i*2])) < 0 || n > 15) return 0;X    if((m=ctod(c[i*2+1])) < 0 || m > 15) return 0;X    ((char *)b)[i] = (n<<4)|m;X  }X  return 1;X}XXvoid des_print_cblock(des_cblock *b)X{X  int i;X  for(i = 0; i < 8; i++) printf("%02X",((unsigned char *)b)[i]);X}XXchar linebuf[512];XXstruct Library *ACryptBase=0;XXXvoid main(int argc,char **argv)X{X  FILE *testdata;X  des_cblock  k,p,c,er,dr;X  des_key_schedule ks;X  int line=0,test=0,ok=1;X  char *fname;XX  if(argc<2) fname = "des_test_data";X    else fname = argv[1];XX  if(!(testdata = fopen(fname,"r"))) {X    printf("destest: can't open file %s\n",fname);X    exit(5);X  }XX  while(fgets(linebuf,512,testdata))X  {X    line++;X    if(des_hex_to_cblock(&k,linebuf) &&X      des_hex_to_cblock(&p,linebuf+17) &&X      des_hex_to_cblock(&c,linebuf+34)) {X      test++;X      des_set_key(&k,&ks);X      des_ecb_encrypt(&p,&er,&ks,DES_ENCRYPT);X      des_ecb_encrypt(&c,&dr,&ks,DES_DECRYPT);X      if(memcmp(&er,&c,sizeof(des_cblock))||X        memcmp(&dr,&p,sizeof(des_cblock))) {X        printf("destest failed '%s' line %d, test %d\n",X          fname,line,test);X        printf("key= ");X        des_print_cblock(&k);X        printf("\n plain= ");X        des_print_cblock(&p);X        printf("\n chipher= ");X        des_print_cblock(&c);X        printf("\nenc= ");X        des_print_cblock(&er);X        printf("\ndec= ");X        des_print_cblock(&er);X        printf("\n");X        ok = 0;X        break;X      } X    } else { X      fputs(linebuf, stdout);X      fflush(stdout);X    }X  }X  printf("%s test with file %s\n", test?(ok?"successful":"failed"):X        "nothing to",fname);X  exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);X}X

⌨️ 快捷键说明

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