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

📄 btoa.c

📁 des算法实现源码
💻 C
字号:
/* btoa: version 4.0 * stream filter to change 8 bit bytes into printable ascii * computes the number of bytes, and three kinds of simple checksums * incoming bytes are collected into 32-bit words, then printed in base 85 *  exp(85,5) > exp(2,32) * the ASCII characters used are between '!' and 'u' * 'z' encodes 32-bit zero; 'x' is used to mark the end of encoded data. * *  Paul Rutter		Joe Orost *  philabs!per		petsd!joe * *  WARNING: this version is not compatible with the original as sent out *  on the net.  The original encoded from ' ' to 't'; which cause problems *  with some mailers (stripping off trailing blanks). */#include <stdlib.h>#include <unistd.h>#include <stdio.h>#if defined(__msdos) || defined(__MSDOS__)#include <fcntl.h>	/* for setmode O_BINARY */#endif#define reg register#define MAXPERLINE 78#if defined(__msdos) || defined(__MSDOS__)typedef  long s32;#elsetypedef  int s32;#endifs32 Ceor = 0;s32 Csum = 0;s32 Crot = 0;s32 ccount = 0;s32 bcount = 0;s32 word;#define EN(c)	(int) ((c) + '!')void charout(c)   int c;{  putchar(c);  ccount += 1;  if (ccount == MAXPERLINE) {    putchar('\n');    ccount = 0;  }}void wordout(word)   reg s32 word;{  if (word == 0) {    charout('z');  } else {    reg int tmp = 0;        if(word < 0) {	/* Because some don't support unsigned long */      tmp = 32;      word = word - ((s32)85 * 85 * 85 * 85 * 32);    }    if(word < 0) {      tmp = 64;      word = word - ((s32)85 * 85 * 85 * 85 * 32);    }    charout(EN((word / ((long)85 * 85 * 85 * 85)) + tmp));    word %= ((s32)85 * 85 * 85 * 85);    charout(EN(word / ((long)85 * 85 * 85)));    word %= ((s32)85 * 85 * 85);    charout(EN(word / (85 * 85)));    word %= (85 * 85);    charout(EN(word / 85));    word %= 85;    charout(EN(word));  }}void encode(c)   reg c;{  Ceor ^= c;  Csum += c;  Csum += 1;  if ((Crot & 0x80000000)) {    Crot <<= 1;    Crot += 1;  } else {    Crot <<= 1;  }  Crot += c;  word <<= 8;  word |= c;  if (bcount == 3) {    wordout(word);    bcount = 0;  } else {    bcount += 1;  }}int main(argc,argv)   int argc;  char **argv;{  reg c;  reg s32 n;  if (argc != 1) {    fprintf(stderr,"bad args to %s\n", argv[0]);    exit(2);  }#if defined(__msdos) || defined(__MSDOS__)  setmode(0, O_BINARY);#endif  printf("xbtoa Begin\n");  n = 0;  while ((c = getchar()) != EOF) {    encode(c);    n += 1;  }  while (bcount != 0) {    encode(0);  }  /* n is written twice as crude cross check*/  printf("\nxbtoa End N %ld %lx E %lx S %lx R %lx\n", n, n, Ceor, Csum, Crot);  exit(0);}

⌨️ 快捷键说明

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