home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume37 / syfre / part01 < prev    next >
Encoding:
Internet Message Format  |  1993-06-19  |  62.5 KB

  1. From: wallace@math.berkeley.edu (Marc 'Merle' Wallace)
  2. Newsgroups: comp.sources.misc
  3. Subject: v37i129: syfre - Syfre 1.1: data encryption utility, Part01/01
  4. Date: 3 Jun 1993 10:47:40 +0100
  5. Sender: aem@aber.ac.uk
  6. Approved: aem@aber.ac.uk
  7. Message-ID: <1ukhbs$3g9@uk-usenet.UK.Sun.COM>
  8. X-Md4-Signature: 43b2ae810abf2965a4095890667b3cbd
  9.  
  10. Submitted-by: wallace@math.berkeley.edu (Marc 'Merle' Wallace)
  11. Posting-number: Volume 37, Issue 129
  12. Archive-name: syfre/part01
  13. Environment: UNIX, C++
  14.  
  15. Syfre is an encryption/decryption utility.  The user inputs two eight
  16. character passwords which are used to determine a sequence of 32 cyphers
  17. through which the data is passed.
  18.  
  19. Encoding is the default action.  It can also be selected with the "-e"
  20. option.  Decoding requires the "-d" option.
  21.  
  22. Input is read from stdin, or from a file specified by the "-i filename"
  23. option.  Output goes to stdout, or the file specified by "-o filename".
  24. When using the latter option, already existing files are never overwritten;
  25. use the "-O filename" option to force overwriting.
  26.  
  27. Extra options:
  28.     baby:
  29.         Only 16 cyphers are used.  This makes the output smaller, but
  30.         less secure.  By default this option is off; the command line
  31.         option "-b" turns it on.
  32.     text:
  33.         Output is text, instead of binary (suitable for email or posting).
  34.         By default this option is off (since it makes for larger output
  35.         files); the command line option "-t" turns it on.
  36.  
  37. -----------------------
  38.  
  39. #! /bin/sh
  40. # This is a shell archive.  Remove anything before this line, then unpack
  41. # it by saving it into a file and typing "sh file".  To overwrite existing
  42. # files, type "sh file -c".  You can also feed this as standard input via
  43. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  44. # will see the following message at the end:
  45. #        "End of shell archive."
  46. # Contents:  syfre syfre/Makefile syfre/README syfre/config.h
  47. #   syfre/cypher.c syfre/cypher.h syfre/cyphers syfre/data.c
  48. #   syfre/data.h syfre/docs syfre/include.h syfre/random.c
  49. #   syfre/syfre.c syfre/syfre.man syfre/test.c syfre/text.c
  50. #   syfre/version.c syfre/cyphers/blockxor.c
  51. #   syfre/cyphers/blockxor.doc syfre/cyphers/cubicxor.c
  52. #   syfre/cyphers/cubicxor.doc syfre/cyphers/dualxor.c
  53. #   syfre/cyphers/dualxor.doc syfre/cyphers/quadadd.c
  54. #   syfre/cyphers/quadadd.doc syfre/cyphers/recurxor.c
  55. #   syfre/cyphers/recurxor.doc syfre/cyphers/rotate.c
  56. #   syfre/cyphers/rotate.doc syfre/cyphers/sixteen.c
  57. #   syfre/cyphers/sixteen.doc syfre/cyphers/square.c
  58. #   syfre/cyphers/square.doc
  59. # Wrapped by wallace@durban.berkeley.edu on Fri May 28 12:00:57 1993
  60. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  61. if test ! -d 'syfre' ; then
  62.     echo shar: Creating directory \"'syfre'\"
  63.     mkdir 'syfre'
  64. fi
  65. if test -f 'syfre/Makefile' -a "${1}" != "-c" ; then 
  66.   echo shar: Will not clobber existing file \"'syfre/Makefile'\"
  67. else
  68. echo shar: Extracting \"'syfre/Makefile'\" \(2505 characters\)
  69. sed "s/^X//" >'syfre/Makefile' <<'END_OF_FILE'
  70. XBINDIR    = /usr/local/bin
  71. XMANDIR    = /usr/man
  72. XMANSECT    = l
  73. XVERSION    = 1.1
  74. X
  75. XCC    = g++
  76. XCFLAGS    = -O2
  77. XSHELL    = /bin/sh
  78. X
  79. XAR    = /usr/bin/ar
  80. XCHMOD    = /usr/bin/chmod
  81. XCP    = /usr/bin/cp
  82. XRANLIB    = /usr/bin/ranlib
  83. XRM    = /bin/rm
  84. XSTRIP    = /usr/bin/strip
  85. X
  86. X.SUFFIXES : .os
  87. X
  88. X
  89. X# SSRCS   : source code files for "syfre".
  90. X# TSRCS   : source code files for "test" (for debugging).
  91. X# LSRCS   : source code files for cypher library (class definitions).
  92. X# LCYPS   : source code files for cyphers.
  93. X
  94. XSSRCS    = syfre.c text.c version.c
  95. XTSRCS    = test.c version.c
  96. XLSRCS    = cypher.c data.c random.c
  97. XLCYPS    = cyphers/recurxor.c  cyphers/quadadd.c  cyphers/cubicxor.c \
  98. X      cyphers/blockxor.c  cyphers/square.c   cyphers/sixteen.c  \
  99. X      cyphers/rotate.c    cyphers/dualxor.c
  100. X
  101. X
  102. X# NOTE:     the following rules may not work with you version of make.
  103. X#           if not simply expand the rules out manually.  $(A:.b=.c)
  104. X#           means "take every entry in A, and replace '.b' suffixes
  105. X#           with '.c'".
  106. X#
  107. X# SOBJS   : object files for "syfre".
  108. X# TOBJS   : object files for "test" (for debugging).
  109. X# LOBJS   : object files for cypher library (class definitions).
  110. X# LCYPS_S : object files for cyphers (-DSECURE).
  111. X# LCYPS_D : object files for cyphers (with debug info).
  112. X
  113. XSOBJS    = $(SSRCS:.c=.o)
  114. XTOBJS    = $(TSRCS:.c=.o)
  115. XLOBJS    = $(LSRCS:.c=.o)
  116. XLCYPS_S    = $(LCYPS:.c=.os)
  117. XLCYPS_D    = $(LCYPS:.c=.o)
  118. X
  119. XSLIB    = libcypher.s.$(VERSION).a
  120. XDLIB    = libcypher.d.$(VERSION).a
  121. X
  122. X
  123. Xall: test syfre
  124. X
  125. Xfull: clean syfre syfretest
  126. X
  127. Xsyfre:  $(SLIB) $(SOBJS)
  128. X    $(CC) $(CFLAGS) -o syfre $(SOBJS) $(SLIB)
  129. X
  130. Xtest: $(DLIB) $(TOBJS)
  131. X    $(CC) $(CFLAGS) -o test $(TOBJS) $(DLIB)
  132. X
  133. Xclean:
  134. X    $(RM) -f core *.o $(SLIB) $(DLIB)
  135. X    $(RM) -f cyphers/*.o cyphers/*.os
  136. X
  137. Xinstall: syfre syfretest
  138. X    $(STRIP) syfre
  139. X    $(CP) syfre $(BINDIR)/syfre
  140. X    $(CHMOD) 555 $(BINDIR)/syfre
  141. X
  142. Xinstallman: syfre.man
  143. X    $(CP) syfre.man $(MANDIR)/man$(MANSECT)/syfre.$(MANSECT)
  144. X    $(CHMOD) 444 $(MANDIR)/man$(MANSECT)/syfre.$(MANSECT)
  145. X
  146. X
  147. X$(SLIB): $(LOBJS) $(LCYPS_S)
  148. X    $(AR) r $@ $?
  149. X    $(RANLIB) $@
  150. X
  151. X$(DLIB): $(LOBJS) $(LCYPS_D)
  152. X    $(AR) r $@ $?
  153. X    $(RANLIB) $@
  154. X
  155. X.c.o:
  156. X    $(CC) $(CFLAGS) -c $< -o $@
  157. X
  158. X.c.os:
  159. X    $(CC) $(CFLAGS) -DSECURE -c $< -o $@
  160. X
  161. X
  162. X# dependencies
  163. X#
  164. Xcypher.o:   cypher.c  cypher.h data.h
  165. Xdata.o:     data.c             data.h
  166. Xrandom.o:   random.c
  167. Xsyf.o:      syf.c     cypher.h data.h include.h config.h
  168. Xsyfre.o:    syfre.c   cypher.h data.h include.h config.h
  169. Xtest.o:     test.c    cypher.h data.h include.h config.h
  170. Xtext.o:     text.c             data.h include.h config.h
  171. Xversion.o:  version.c cypher.h data.h include.h config.h
  172. END_OF_FILE
  173. if test 2505 -ne `wc -c <'syfre/Makefile'`; then
  174.     echo shar: \"'syfre/Makefile'\" unpacked with wrong size!
  175. fi
  176. # end of 'syfre/Makefile'
  177. fi
  178. if test -f 'syfre/README' -a "${1}" != "-c" ; then 
  179.   echo shar: Will not clobber existing file \"'syfre/README'\"
  180. else
  181. echo shar: Extracting \"'syfre/README'\" \(2061 characters\)
  182. sed "s/^X//" >'syfre/README' <<'END_OF_FILE'
  183. XSyfre is an encryption/decryption utility.  The user inputs two eight
  184. Xcharacter passwords which are used to determine a sequence of 32 cyphers
  185. Xthrough which the data is passed.
  186. X
  187. XEncoding is the default action.  It can also be selected with the "-e"
  188. Xoption.  Decoding requires the "-d" option.
  189. X
  190. XInput is read from stdin, or from a file specified by the "-i filename"
  191. Xoption.  Output goes to stdout, or the file specified by "-o filename".
  192. XWhen using the latter option, already existing files are never overwritten;
  193. Xuse the "-O filename" option to force overwriting.
  194. X
  195. XExtra options:
  196. X    baby:
  197. X        Only 16 cyphers are used.  This makes the output smaller, but
  198. X        less secure.  By default this option is off; the command line
  199. X        option "-b" turns it on.
  200. X    text:
  201. X        Output is text, instead of binary (suitable for email or posting).
  202. X        By default this option is off (since it makes for larger output
  203. X        files); the command line option "-t" turns it on.
  204. X
  205. X-------------
  206. X
  207. XTo build syfre, just type "make".  If this fails, you might have to 
  208. Xchange the makefile.  Most entries which might need changing are near
  209. Xthe beginning of the makefile; be sure that AR, CP, etc, are all pointing
  210. Xto the correct locations.
  211. X
  212. X-------------
  213. X
  214. XDocumentation (found in the docs/ dubdirectory):
  215. X
  216. X    general:  general description of syfre.
  217. X
  218. X    howto:    contains a step-by-step description of how to add new cyphers.
  219. X
  220. X    readme:   this file.
  221. X
  222. X    specific: specific details about the workings of syfre.
  223. X
  224. X    System dependent Makefiles and changes are kept in the directory system.
  225. X
  226. X-------------
  227. X
  228. XIf you have a cypher which is relatively simple and fast and good, and
  229. Xyou want it included in later versions, email it to me.  Please include
  230. Xboth your .c file and a .doc file, roughly in the same format as the
  231. Xones provided (I may change this style if a better one springs up).
  232. XSay something like "new cypher" in the subject line.
  233. X
  234. XMail new cyphers to *one* of (in order of preference):
  235. X
  236. X       wallace@math.berkeley.edu
  237. X       merle@wucs1.wustl.edu     
  238. X
  239. END_OF_FILE
  240. if test 2061 -ne `wc -c <'syfre/README'`; then
  241.     echo shar: \"'syfre/README'\" unpacked with wrong size!
  242. fi
  243. # end of 'syfre/README'
  244. fi
  245. if test -f 'syfre/config.h' -a "${1}" != "-c" ; then 
  246.   echo shar: Will not clobber existing file \"'syfre/config.h'\"
  247. else
  248. echo shar: Extracting \"'syfre/config.h'\" \(290 characters\)
  249. sed "s/^X//" >'syfre/config.h' <<'END_OF_FILE'
  250. X// config.h -- user configuration.
  251. X//
  252. X// written by Marc Wallace, 01 May 93.
  253. X// last change: version 1.0 (14 May 93).
  254. X
  255. X
  256. X// current version number.
  257. X// unless you are creating your own cyphers, leave this be.
  258. X// if you change this, be sure to modify version.c accordingly.
  259. X
  260. X#define VERSION 1
  261. END_OF_FILE
  262. if test 290 -ne `wc -c <'syfre/config.h'`; then
  263.     echo shar: \"'syfre/config.h'\" unpacked with wrong size!
  264. fi
  265. # end of 'syfre/config.h'
  266. fi
  267. if test -f 'syfre/cypher.c' -a "${1}" != "-c" ; then 
  268.   echo shar: Will not clobber existing file \"'syfre/cypher.c'\"
  269. else
  270. echo shar: Extracting \"'syfre/cypher.c'\" \(353 characters\)
  271. sed "s/^X//" >'syfre/cypher.c' <<'END_OF_FILE'
  272. X// cypher.c -- class functions for classes "cypher" and "metacypher".
  273. X//
  274. X// written by Marc Wallace, 26 Apr 93.
  275. X// last change: version 1.1 (14 May 93).
  276. X
  277. X
  278. X#include "data.h"
  279. X#include "cypher.h"
  280. X
  281. X
  282. Xvoid nuthin() {};
  283. X
  284. X
  285. XCypher::Cypher(char* n, Cyfunct e, Cyfunct d, void (*i)() = nuthin)
  286. X    {
  287. X    name = n;
  288. X    encode = e;
  289. X    decode = d;
  290. X    i();
  291. X    };
  292. X
  293. X
  294. END_OF_FILE
  295. if test 353 -ne `wc -c <'syfre/cypher.c'`; then
  296.     echo shar: \"'syfre/cypher.c'\" unpacked with wrong size!
  297. fi
  298. # end of 'syfre/cypher.c'
  299. fi
  300. if test -f 'syfre/cypher.h' -a "${1}" != "-c" ; then 
  301.   echo shar: Will not clobber existing file \"'syfre/cypher.h'\"
  302. else
  303. echo shar: Extracting \"'syfre/cypher.h'\" \(681 characters\)
  304. sed "s/^X//" >'syfre/cypher.h' <<'END_OF_FILE'
  305. X// cypher.h -- class definition for class "cypher".
  306. X//
  307. X// written by Marc Wallace, 26 Apr 93.
  308. X// last change: version 1.1 (14 May 93).
  309. X
  310. X
  311. X// always include data.h before this file.
  312. X
  313. X
  314. Xtypedef Data& (*Cyfunct)(Data&, Data&);
  315. Xextern void nuthin();
  316. X
  317. X
  318. Xclass Cypher
  319. X    {
  320. X    public:
  321. X        Cyfunct encode;  //  Data& (*encode)(Data& in, Data& out);
  322. X        Cyfunct decode;  //  Data& (*decode)(Data& in, Data& out);
  323. X
  324. X        // Cypher class initializer.
  325. X        // Cypher("name", encode(), decode(), init())
  326. X        // init() is an (optional) function to be run for data initialization.
  327. X        Cypher(char* n, Cyfunct e, Cyfunct d, void (*i)() = nuthin);
  328. X        char  *name;
  329. X    };
  330. X
  331. X
  332. END_OF_FILE
  333. if test 681 -ne `wc -c <'syfre/cypher.h'`; then
  334.     echo shar: \"'syfre/cypher.h'\" unpacked with wrong size!
  335. fi
  336. # end of 'syfre/cypher.h'
  337. fi
  338. if test ! -d 'syfre/cyphers' ; then
  339.     echo shar: Creating directory \"'syfre/cyphers'\"
  340.     mkdir 'syfre/cyphers'
  341. fi
  342. if test -f 'syfre/data.c' -a "${1}" != "-c" ; then 
  343.   echo shar: Will not clobber existing file \"'syfre/data.c'\"
  344. else
  345. echo shar: Extracting \"'syfre/data.c'\" \(749 characters\)
  346. sed "s/^X//" >'syfre/data.c' <<'END_OF_FILE'
  347. X// data.c -- class functions for class "Data".
  348. X//
  349. X// written by Marc Wallace, 30 Apr 93.
  350. X// last change: version 1.0 (14 May 93).
  351. X
  352. X
  353. X#include "data.h"
  354. X
  355. X
  356. XData::Data(int m)
  357. X    {
  358. X    data = new unsigned char[m];
  359. X    size = 0;
  360. X    maxsize = m;
  361. X    };
  362. X
  363. X
  364. XData::Data(int m, int s, unsigned char* d)
  365. X    {
  366. X    data = new unsigned char[m];
  367. X    for (int r = 0; r < s; r++)
  368. X        data[r] = d[r];
  369. X    size = s;
  370. X    maxsize = m;
  371. X    };
  372. X
  373. X
  374. Xvoid
  375. XData::reinit(int m)
  376. X    {
  377. X    delete data;
  378. X    Data(m);
  379. X    };
  380. X
  381. X
  382. Xvoid
  383. XData::reinit(int m, int s, unsigned char* d)
  384. X    {
  385. X    if (m > maxsize)
  386. X        {
  387. X        delete data;
  388. X        data = new unsigned char[m];
  389. X        };
  390. X    for (int r = 0; r < s; r++)
  391. X        data[r] = d[r];
  392. X    size = s;
  393. X    maxsize = m;
  394. X    };
  395. X
  396. X
  397. END_OF_FILE
  398. if test 749 -ne `wc -c <'syfre/data.c'`; then
  399.     echo shar: \"'syfre/data.c'\" unpacked with wrong size!
  400. fi
  401. # end of 'syfre/data.c'
  402. fi
  403. if test -f 'syfre/data.h' -a "${1}" != "-c" ; then 
  404.   echo shar: Will not clobber existing file \"'syfre/data.h'\"
  405. else
  406. echo shar: Extracting \"'syfre/data.h'\" \(397 characters\)
  407. sed "s/^X//" >'syfre/data.h' <<'END_OF_FILE'
  408. X// data.h -- class definitions for class "Data".
  409. X//
  410. X// written by Marc Wallace, 30 Apr 93.
  411. X// last change: version 1.0 (02 May 93).
  412. X
  413. X
  414. Xclass Data
  415. X    {
  416. X    public:
  417. X        unsigned char*  data;
  418. X        int    size;
  419. X        int    maxsize;
  420. X
  421. X        Data(int m);
  422. X        Data(int m, int s, unsigned char* d);
  423. X
  424. X        void reinit(int m);
  425. X        void reinit(int m, int s, unsigned char* d);
  426. X    };
  427. X
  428. X
  429. END_OF_FILE
  430. if test 397 -ne `wc -c <'syfre/data.h'`; then
  431.     echo shar: \"'syfre/data.h'\" unpacked with wrong size!
  432. fi
  433. # end of 'syfre/data.h'
  434. fi
  435. if test ! -d 'syfre/docs' ; then
  436.     echo shar: Creating directory \"'syfre/docs'\"
  437.     mkdir 'syfre/docs'
  438. fi
  439. if test -f 'syfre/include.h' -a "${1}" != "-c" ; then 
  440.   echo shar: Will not clobber existing file \"'syfre/include.h'\"
  441. else
  442. echo shar: Extracting \"'syfre/include.h'\" \(461 characters\)
  443. sed "s/^X//" >'syfre/include.h' <<'END_OF_FILE'
  444. X
  445. X//
  446. X// written by Marc Wallace, 30 Apr 93.
  447. X// last change: version 1.0.
  448. X
  449. X
  450. X#include "config.h"
  451. X#include "data.h"
  452. X#include "cypher.h"
  453. X
  454. X
  455. X// from random.c
  456. X//
  457. Xextern void randinit();
  458. Xextern char randc();
  459. Xextern char randc(char, char);
  460. X
  461. X// from syf.c
  462. X//
  463. Xextern Cypher** syf;
  464. Xextern int syfnum;
  465. X
  466. X// from text.c
  467. X//
  468. Xextern void bin2txt(Data&);
  469. Xextern void txt2bin(Data&);
  470. X
  471. X// from version.c
  472. X//
  473. Xextern char *version[];
  474. Xextern int verlimit[];
  475. Xextern Cypher* cypherlist[];
  476. END_OF_FILE
  477. if test 461 -ne `wc -c <'syfre/include.h'`; then
  478.     echo shar: \"'syfre/include.h'\" unpacked with wrong size!
  479. fi
  480. # end of 'syfre/include.h'
  481. fi
  482. if test -f 'syfre/random.c' -a "${1}" != "-c" ; then 
  483.   echo shar: Will not clobber existing file \"'syfre/random.c'\"
  484. else
  485. echo shar: Extracting \"'syfre/random.c'\" \(626 characters\)
  486. sed "s/^X//" >'syfre/random.c' <<'END_OF_FILE'
  487. X// random.c -- randomization routines.
  488. X//
  489. X// written by Marc Wallace, 30 Apr 93.
  490. X// last change: version 1.0 (02 May 93).
  491. X
  492. X
  493. X#include "include.h"
  494. X#include <stdlib.h>
  495. X#include <time.h>
  496. X
  497. X
  498. Xvoid
  499. Xrandinit()
  500. X    {
  501. X    long t;
  502. X    t = time(&t);
  503. X    srand(int(t % 65536));
  504. X    srand(rand());
  505. X    };
  506. X
  507. X
  508. Xchar
  509. Xrandc()
  510. X    {
  511. X    // return a random char value (0-255)
  512. X    if (rand() < 10)
  513. X        srand(rand());
  514. X    return char(rand() % 256);
  515. X    };
  516. X
  517. X
  518. Xchar
  519. Xrandc(char lo, char hi)
  520. X    {
  521. X    // return a random char value (between lo and hi)
  522. X    if (rand() < 10)
  523. X        srand(rand());
  524. X    return char(lo + rand() % (hi - lo + 1));
  525. X    };
  526. X
  527. X
  528. X
  529. END_OF_FILE
  530. if test 626 -ne `wc -c <'syfre/random.c'`; then
  531.     echo shar: \"'syfre/random.c'\" unpacked with wrong size!
  532. fi
  533. # end of 'syfre/random.c'
  534. fi
  535. if test -f 'syfre/syfre.c' -a "${1}" != "-c" ; then 
  536.   echo shar: Will not clobber existing file \"'syfre/syfre.c'\"
  537. else
  538. echo shar: Extracting \"'syfre/syfre.c'\" \(5913 characters\)
  539. sed "s/^X//" >'syfre/syfre.c' <<'END_OF_FILE'
  540. X// syfre.c -- main() for syfre.
  541. X//
  542. X// written by Marc Wallace, 01 May 93.
  543. X// last change: version 1.0 (08 May 93).
  544. X
  545. X
  546. X#include "include.h"
  547. X#include <fcntl.h>
  548. X#include <stdio.h>
  549. X#include <stdlib.h>
  550. X#include <unistd.h>
  551. X
  552. X
  553. Xstatic int input  = 0;   // input stream
  554. Xstatic int output = 1;   // output stream
  555. X
  556. Xstatic int order[32];    // which cyphers to apply when
  557. X
  558. Xstatic Data d1(1024);
  559. Xstatic Data d2(1024);
  560. X
  561. X
  562. Xvoid
  563. Xerror(char* s1, char* s2)
  564. X    {
  565. X    fprintf(stderr, "syfre: error: %s", s1);
  566. X    if (*s2)
  567. X        fprintf(stderr, " '%s'.\n", s2);
  568. X    else
  569. X        fprintf(stderr, ".\n");
  570. X    fflush(stderr);
  571. X    exit(1);
  572. X    }
  573. X
  574. X
  575. Xint
  576. Xencode(int baby, int text)
  577. X    {
  578. X    int last, size, numpass, want;
  579. X    int r, v;
  580. X    unsigned char data[4];
  581. X
  582. X    // how much data do we need to read for this block?
  583. X    // depends on number of passes (16 or 32) and
  584. X    // the text flag.
  585. X    numpass = baby ? 16 : 32;
  586. X    want = (text ? 748 : 1020) - 4 * numpass;
  587. X
  588. X    // we might be reading from stdin.
  589. X    // so read() might return, say, 8 bytes.  this ain't enough.
  590. X    // read in blocks of data 'til we have a large block or an EOF.
  591. X    // '(last < 1)' keeps track of EOF condition.
  592. X    if ((size = read(input, d1.data, want)) > 0)
  593. X        {
  594. X        last = 1;
  595. X        while ((last > 0) && (size < want))
  596. X            {
  597. X            last = read(input, d1.data + size, want - size);
  598. X            if (last > 0)
  599. X                size += last;   
  600. X            }
  601. X        if (last < 1)
  602. X            last = 0;
  603. X        }
  604. X    else
  605. X        last = 0;
  606. X
  607. X    if (size < 1)
  608. X        return 0;  // not much to do here
  609. X
  610. X    // pad out the input
  611. X    for (r = size; r < want; r++)
  612. X        d1.data[r] = randc();
  613. X    d1.size = want;
  614. X
  615. X    // rev up the cypher machine
  616. X    v = verlimit[VERSION];
  617. X    for (r = 0; r < numpass;)
  618. X        {
  619. X        (cypherlist[order[r++] % v]->encode)(d1, d2);
  620. X        (cypherlist[order[r++] % v]->encode)(d2, d1);
  621. X        }
  622. X
  623. X    // convert to text, if necessary
  624. X    if (text)
  625. X        {
  626. X        // need to pad from 748 to 750
  627. X        d1.data[d1.size++] = randc();
  628. X        d1.data[d1.size++] = randc();
  629. X        bin2txt(d1);
  630. X        }
  631. X
  632. X    // create the header for the size, version number, and text flag
  633. X    data[0] = (text ? 'T' : 'B') + (baby ? 32 : 0);
  634. X    data[1] = 'A' + (size % 32);
  635. X    data[2] = 'A' + (size / 32);
  636. X    data[3] = 'A' + VERSION;
  637. X
  638. X    if (write(output, data, 4) < 4)
  639. X        error("could not write output.", "");
  640. X    if (write(output, d1.data, d1.size) < d1.size)
  641. X        error("could not write output.", "");
  642. X
  643. X    return last;
  644. X    }
  645. X
  646. X
  647. Xint
  648. Xdecode()
  649. X    {
  650. X    int baby, text;
  651. X    int size, vers, numpass;
  652. X    int r, v;
  653. X    unsigned char data[4];
  654. X
  655. X    // read in the first four bytes
  656. X    if ((r = read(input, data, 4)) < 1)
  657. X        return 0;
  658. X
  659. X    // parse out the format, size, and version number
  660. X    baby = (data[0] > 'Z') ? 1 : 0;
  661. X    text = ((data[0] == 'T') || (data[0] == 't')) ? 1 : 0;
  662. X    size = data[1] - 'A' + 32 * (data[2] - 'A');
  663. X    vers = data[3] - 'A';
  664. X    numpass = (baby) ? 16 : 32;
  665. X
  666. X    // read in the data and convert if necessary
  667. X    if (read(input, d1.data, 1020) != 1020)
  668. X        error("input is not a syfre file.", "");
  669. X    d1.size = 1020;
  670. X    if (text)
  671. X        {
  672. X        txt2bin(d1);
  673. X        // cut off the padding bytes
  674. X        d1.size = 748;
  675. X        }
  676. X
  677. X    // start up ye old cypher machine
  678. X    v = verlimit[vers];
  679. X    for (r = numpass - 1; r > 0;)
  680. X        {
  681. X        (cypherlist[order[r--] % v]->decode)(d1, d2);
  682. X        (cypherlist[order[r--] % v]->decode)(d2, d1);
  683. X        }
  684. X
  685. X    // output it all
  686. X    write(output, d1.data, size);
  687. X
  688. X    return 1;
  689. X    }
  690. X
  691. X
  692. Xint
  693. Xmain(int argc, char** argv)
  694. X    {
  695. X    int  size;      // size of current data segment
  696. X    int  code = 0;  // encoding = 0, decoding = 1
  697. X    int  baby = 0;  // do less cyphering
  698. X    int  text = 0;  // output only text, not binary
  699. X
  700. X    char  passwd[17];
  701. X    int   r, s, t;
  702. X    char  **p;
  703. X
  704. X    *passwd = 0;
  705. X
  706. X
  707. X    // parse the argc/argv structure
  708. X    p = argv;
  709. X    while(*++p)
  710. X       {
  711. X       if (strcmp("-h", *p) == 0)
  712. X           {
  713. X           printf("%s [-edbt] [-i inputfile] [-oO outputfile]\n", *argv);
  714. X           exit(0);
  715. X           }
  716. X       else if (strcmp("-e", *p) == 0)
  717. X           code = 0;
  718. X       else if (strcmp("-d", *p) == 0)
  719. X           code = 1;
  720. X       else if (strcmp("-b", *p) == 0)
  721. X           baby = 1;
  722. X       else if (strcmp("-t", *p) == 0)
  723. X           text = 1;
  724. X       else if (strcmp("-i", *p) == 0)
  725. X           {
  726. X           if ((input = open(*++p, O_RDONLY, 0)) == -1)
  727. X               error("cannot open input file", *p);
  728. X           }
  729. X       else if (strcmp("-o", *p) == 0)
  730. X           {
  731. X           if ((output = open(*++p, O_WRONLY, 0)) != -1)
  732. X               error("will not clobber existing file", *p);
  733. X           if ((output = creat(*p, 0600)) == -1)
  734. X               error("cannot open output file", *p);
  735. X           }
  736. X       else if (strcmp("-O", *p) == 0)
  737. X           {
  738. X           if ((output = creat(*p, 0600)) == -1)
  739. X               error("cannot open output file", *p);
  740. X           }
  741. X       else
  742. X           error("bad argument:", *p);
  743. X       }
  744. X
  745. X    // read in the password (two iterations)
  746. X    if (!*passwd)
  747. X        {
  748. X        sprintf(passwd, "default password");
  749. X        sprintf(passwd,   "%-8.8s", getpass("Password: "));
  750. X        sprintf(passwd+8, "%-8.8s", getpass("Password: "));
  751. X        }
  752. X
  753. X    // fill the order[] array
  754. X    // these are just raw integers: to get the
  755. X    // actual cypher number to apply, take the
  756. X    // entry modulo (number of cyphers in this version)
  757. X    // (version number may change for decodes, eh?)
  758. X    for (r = 0; r < 16; r++)
  759. X        for (s = 0; s < 2; s++)
  760. X            {
  761. X            t = passwd[r] + r + 5 * s;
  762. X            t += passwd[(3 * s + 2 * r) % 16];
  763. X            t -= (s % 3) ? 17 : 0;
  764. X            order[(r << 1) + s] = t + 1024;
  765. X            }
  766. X
  767. X    // now repeatedly encode/decode block by block
  768. X    t = 1;
  769. X    while(t)
  770. X        t = (code) ? decode() : encode(baby, text);
  771. X    }
  772. X
  773. END_OF_FILE
  774. if test 5913 -ne `wc -c <'syfre/syfre.c'`; then
  775.     echo shar: \"'syfre/syfre.c'\" unpacked with wrong size!
  776. fi
  777. # end of 'syfre/syfre.c'
  778. fi
  779. if test -f 'syfre/syfre.man' -a "${1}" != "-c" ; then 
  780.   echo shar: Will not clobber existing file \"'syfre/syfre.man'\"
  781. else
  782. echo shar: Extracting \"'syfre/syfre.man'\" \(3474 characters\)
  783. sed "s/^X//" >'syfre/syfre.man' <<'END_OF_FILE'
  784. X.\" @(#)syfre.man 1.1 93/05/15; Copyright (c) 1993 - Marc Douglass Wallace
  785. X.\"
  786. X.TH syfre l "15 May 1993" "1.1"
  787. X.SH NAME
  788. Xsyfre \- cypher encryption/decryption utility
  789. X.SH SYNOPSIS
  790. X.B syfre 
  791. X[ 
  792. X.B \-edbt
  793. X] [ 
  794. X.B -i
  795. Xinputfile
  796. X] [ 
  797. X.B -oO
  798. Xoutputfile
  799. X]
  800. X.SH DESCRIPTION
  801. X.I syfre
  802. Xis an encryption utility which uses simple cyphers to encrypt a stream
  803. X(usually stdin).  Two eight character passwords are entered by the user,
  804. Xwhich are used to choose which cyphers to apply.  Data is then read in
  805. Xand outputted in blocks of 1K each.
  806. X.PP
  807. XThe output will always be somewhat larger than the input, size variation
  808. Xdepending upon the options selected.
  809. XAssuming normal encryption,
  810. Xif the output is binary (default), then 956 byte blocks are read in
  811. Xand outputted as 1024 byte blocks (output is always in 1K blocks).
  812. XIf the output is text (
  813. X.B -t
  814. Xoption), 684 byte blocks are used for input.
  815. XIf the baby option (
  816. X.B -b
  817. X) is specified, less encryption is done (sixteen passes instead of thirty-two),
  818. Xbut larger input blocks can be read.  Binary output would read in 988 byte
  819. Xblocks, and text output would read in 716 byte blocks.
  820. X.PP
  821. XIt might seem that the text option would increase the size far beyond what
  822. Xwould normally be considered tolerable.  However, binary encrypted data
  823. Xwhich is then piped through
  824. X.IR uuencode (1)
  825. Xincreases in size by a factor of 4/3.  Indeed, the binary-to-text conversion
  826. Xmethod used internally is very similar to that used in uuencode.
  827. X.PP
  828. XAll versions of 
  829. X.B syfre
  830. Xare backwards-compatible; although later versions may have more cyphers
  831. Xto select from,
  832. X.B syfre
  833. Xwill be able to decrypt files encrypted by an older version.  No facility
  834. Xexists for encrypting data as if it were actually an older version of
  835. X.B syfre .
  836. X.SH OPTIONS
  837. X.TP 5
  838. X.BI -e
  839. XEncode data.  This is the default action.
  840. X.TP 5
  841. X.BI -d
  842. XDecode data.  
  843. X.B syfre
  844. Xautomatically determines text/binary format, whether the baby option was
  845. Xused, and what version of
  846. X.B syfre
  847. Xwas used to encode the data.
  848. X.TP 5
  849. X.BI -b
  850. XBaby option.  Only sixteen cypher passes are made, instead of thirty-two.
  851. XWhen encoding a large file this should decrease output size by three to
  852. Xfive percent.  Default is off (thirty-two passes).
  853. X.TP 5
  854. X.BI -t
  855. XText option.  Output will use only standard text characters ("A-Za-z0-9.,").
  856. XOutput will be much larger (thirty-three to fourty percent larger), but will
  857. Xbe in an easy format for email or usenet posting.  Default is binary.
  858. X.TP 5
  859. X.BI -i " filename
  860. XRead input from
  861. X.BI filename
  862. Xinstead of stdin.
  863. X.TP 5
  864. X.BI -o " filename
  865. XSend output to
  866. X.BI filename
  867. Xinstead of stdout.
  868. X.BI filename
  869. Xwill not be overwritten if it already exists.
  870. X.TP 5
  871. X.BI -O " filename
  872. XSend output to
  873. X.BI filename
  874. Xinstead of stdout.
  875. X.BI filename
  876. Xwill be overwritten if it already exists.
  877. X
  878. X.SH BUGS
  879. XNone known at this time.
  880. X.PP
  881. XDuring initial testing, it seemed that a file encoded with one password
  882. Xand decoded with a different password would cause a core dump.  Although
  883. Xthis could easily be written off as an "unintended feature", it seems to
  884. Xhave disappeared with the cleaning up of the binary-to-text conversion
  885. Xroutines.
  886. X.SH COPYRIGHT
  887. XCopyright (c) 1993 by Marc Douglass Wallace
  888. X.br
  889. X(wallace@math.berkeley.edu)
  890. X
  891. XPermission to use, copy, modify, and distribute this software and its
  892. Xdocumentation for any purpose and without fee is hereby granted,
  893. Xprovided that the above copyright notice appear in all copies and that
  894. Xboth that copyright notice and this permission notice appear in
  895. Xsupporting documentation. 
  896. END_OF_FILE
  897. if test 3474 -ne `wc -c <'syfre/syfre.man'`; then
  898.     echo shar: \"'syfre/syfre.man'\" unpacked with wrong size!
  899. fi
  900. # end of 'syfre/syfre.man'
  901. fi
  902. if test -f 'syfre/test.c' -a "${1}" != "-c" ; then 
  903.   echo shar: Will not clobber existing file \"'syfre/test.c'\"
  904. else
  905. echo shar: Extracting \"'syfre/test.c'\" \(2735 characters\)
  906. sed "s/^X//" >'syfre/test.c' <<'END_OF_FILE'
  907. X// test.c -- testing functions for syfre (alternate main()).
  908. X//
  909. X// written by Marc Wallace, 02 May 93.
  910. X// last change: version 1.0 (02 May 93).
  911. X
  912. X
  913. X#include "include.h"
  914. X#include <stream.h>
  915. X#include <string.h>
  916. X#include <stdiostream.h>
  917. X#include <stdio.h>
  918. X
  919. X
  920. Xextern void syfdump();
  921. Xextern char undo(char);
  922. X
  923. X
  924. Xint main()
  925. X    {
  926. X    Data     d1(1024), d2(1024), d3(1024);
  927. X    int      r, s, t;
  928. X    Cypher*  curr;
  929. X
  930. X    randinit();
  931. X
  932. X    // list all available cyphers
  933. X    cout << "List of all cyphers compiled in version ";
  934. X    cout << version[VERSION] << ":\n";
  935. X    for (r = 0; (r < verlimit[VERSION]); r++)
  936. X        cout << "    " << (cypherlist[r])->name << "\n";
  937. X    cout << "\n";
  938. X
  939. X    for (r = 0; (r < verlimit[VERSION]); r++)
  940. X        {
  941. X        curr = cypherlist[r];
  942. X        cout << "Testing " << curr->name << ":\n    ";
  943. X
  944. X        // test each cypher for each possible size
  945. X        for (d1.size = 4; d1.size < 1024; d1.size += 4)
  946. X            {
  947. X            // fill d1 with random data
  948. X            for (t = 0; t < d1.size; t++)
  949. X                d1.data[t] = randc();
  950. X
  951. X            // encode and then decode (should reverse)
  952. X            (curr->encode)(d1, d2);
  953. X            (curr->decode)(d2, d3);
  954. X
  955. X            // if the sizes differ, it failed miserably
  956. X            if (d1.size != d3.size)
  957. X                {
  958. X                cout << "\n";
  959. X                cout << "    Sizes of X and d(e(X)) do not match.\n";
  960. X                cout << "    Sizes were " << d1.size << " and " << d3.size;
  961. X                cout << "\n\nTerminating cypher tests.\n";
  962. X                return 1;
  963. X                };
  964. X
  965. X            // if one of the bytes is different, it failed
  966. X            for (t = 0; t < d1.size; t++)
  967. X                if (d1.data[t] != d3.data[t])
  968. X                    {
  969. X                    cout << "\n";
  970. X                    cout << "    X and d(e(X)) differ at byte " << t << ".\n";
  971. X
  972. X                    cout << "    debug data:\n";
  973. X                    for (r = t - 4; (r < t + 16) && (r < d3.size); r++)
  974. X                        printf("          %-3d>>   %8x %8x %8x\n", r,
  975. X                        int(d1.data[r]), int(d2.data[r]), int(d3.data[r]));
  976. X                    if (r < t + 16)
  977. X                        for (; (r < t + 16) && (r < d2.size); r++)
  978. X                            printf("          %-3d>>            %8x\n",
  979. X                            r, int(d2.data[r]));
  980. X
  981. X                    cout << "\n\nTerminating cypher tests.\n";
  982. X                    return 2;
  983. X                    }
  984. X
  985. X            // echo something so we know we're working
  986. X            if (d1.size % 32 == 0)
  987. X                {
  988. X                cout << '.';
  989. X                cout.flush();
  990. X                };
  991. X            };
  992. X
  993. X        cout << " passed reversibility test.\n";
  994. X        };
  995. X    };
  996. END_OF_FILE
  997. if test 2735 -ne `wc -c <'syfre/test.c'`; then
  998.     echo shar: \"'syfre/test.c'\" unpacked with wrong size!
  999. fi
  1000. # end of 'syfre/test.c'
  1001. fi
  1002. if test -f 'syfre/text.c' -a "${1}" != "-c" ; then 
  1003.   echo shar: Will not clobber existing file \"'syfre/text.c'\"
  1004. else
  1005. echo shar: Extracting \"'syfre/text.c'\" \(2440 characters\)
  1006. sed "s/^X//" >'syfre/text.c' <<'END_OF_FILE'
  1007. X// text.c -- binary data <--> text data conversion functions.
  1008. X//
  1009. X// written by Marc Wallace, 14 May 93.
  1010. X// last change: version 1.1 (14 May 93).
  1011. X
  1012. X
  1013. X#include "include.h"
  1014. X
  1015. X
  1016. Xstatic unsigned char chars[65] =
  1017. X    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,";
  1018. X
  1019. Xstatic unsigned char bbuf[1024];
  1020. Xstatic unsigned char tbuf[1024];
  1021. X
  1022. X
  1023. Xunsigned char
  1024. Xundo(char c)
  1025. X    {
  1026. X    if (c >= 'A')
  1027. X        return c - 'A' - ((c > 'Z') ? 6 : 0);
  1028. X    else if (c == '.')
  1029. X        return 62;
  1030. X    else if (c == ',')
  1031. X        return 63;
  1032. X    else
  1033. X        return c + 4;
  1034. X    }
  1035. X
  1036. X
  1037. Xvoid
  1038. Xbin2txt(Data& d)
  1039. X    {
  1040. X    int size = d.size;
  1041. X    int newsize = 0;
  1042. X    int rt = 0, rb = 0;
  1043. X
  1044. X    // copy the data out
  1045. X    memcpy(bbuf, d.data, size);
  1046. X
  1047. X    // find the values (0..63) for each output character
  1048. X    while (rb < size)
  1049. X        {
  1050. X        tbuf[rt++]  = bbuf[rb]    & 0x3f;        // first  text byte
  1051. X        tbuf[rt]    = bbuf[rb++] >> 6;
  1052. X        tbuf[rt++] += (bbuf[rb]   & 0x0f) << 2;  // second text byte
  1053. X        tbuf[rt]    = bbuf[rb++] >> 4;
  1054. X        tbuf[rt++] += (bbuf[rb]   & 0x03) << 4;  // third  text byte
  1055. X        tbuf[rt++]  = bbuf[rb++] >> 2;           // fourth text byte
  1056. X        };
  1057. X    size = (size << 2) / 3;
  1058. X
  1059. X    // apply the chars[] array and insert carriage returns
  1060. X    for (rt = 0, newsize = 0; rt < size; rt++)
  1061. X        {
  1062. X        d.data[newsize++] = chars[tbuf[rt]];
  1063. X        if ((rt % 50) == 49)
  1064. X            d.data[newsize++] = '\n';
  1065. X        };
  1066. X    d.size = newsize;
  1067. X    }
  1068. X
  1069. X
  1070. Xvoid
  1071. Xtxt2bin(Data& d)
  1072. X    {
  1073. X    int size = d.size;
  1074. X    int newsize = 0;
  1075. X    int rt, rb;
  1076. X
  1077. X    // copy the data out
  1078. X    memcpy(tbuf, d.data, size);
  1079. X
  1080. X    // remove carriage returns
  1081. X    for (newsize = rt = 0; rt < size; newsize++)
  1082. X        {
  1083. X        tbuf[newsize] = tbuf[rt++];
  1084. X        if (tbuf[rt] == '\n')
  1085. X            rt++;
  1086. X        };
  1087. X    size = newsize;
  1088. X
  1089. X    // undo the chars[] processing
  1090. X    for (rt = 0; rt < size; rt++)
  1091. X        tbuf[rt] = undo(tbuf[rt]);
  1092. X
  1093. X    // unprocess the data
  1094. X    for (rb = rt = 0; rt < size;)
  1095. X        {
  1096. X        bbuf[rb]    = tbuf[rt++];
  1097. X        bbuf[rb++] += (tbuf[rt]   & 0x03) << 6;  // first  binary byte
  1098. X        bbuf[rb]    = tbuf[rt++] >> 2;
  1099. X        bbuf[rb++] += (tbuf[rt]   & 0x0f) << 4;  // second binary byte
  1100. X        bbuf[rb]    = tbuf[rt++] >> 4;
  1101. X        bbuf[rb++] += (tbuf[rt++] & 0x3f) << 2;  // third  binary byte
  1102. X        };
  1103. X
  1104. X    // unapply the chars[] array and fix the size
  1105. X    memcpy(d.data, bbuf, rb);
  1106. X    d.size = rb;
  1107. X    }
  1108. X
  1109. END_OF_FILE
  1110. if test 2440 -ne `wc -c <'syfre/text.c'`; then
  1111.     echo shar: \"'syfre/text.c'\" unpacked with wrong size!
  1112. fi
  1113. # end of 'syfre/text.c'
  1114. fi
  1115. if test -f 'syfre/version.c' -a "${1}" != "-c" ; then 
  1116.   echo shar: Will not clobber existing file \"'syfre/version.c'\"
  1117. else
  1118. echo shar: Extracting \"'syfre/version.c'\" \(1108 characters\)
  1119. sed "s/^X//" >'syfre/version.c' <<'END_OF_FILE'
  1120. X// version.c -- list of version names and their cyphers.
  1121. X//
  1122. X// written by Marc Wallace, 02 May 93.
  1123. X// last change: version 1.1 (26 May 93).
  1124. X
  1125. X
  1126. X#include "include.h"
  1127. X
  1128. X
  1129. Xextern Cypher  recurxor, cubicxor, blockxor, quadadd;
  1130. Xextern Cypher  square,   sixteen,  rotate,   dualxor;
  1131. X
  1132. X
  1133. Xchar *version[] = 
  1134. X    {
  1135. X    "1.0",     // first alpha version
  1136. X    "1.1",     // first beta version
  1137. X    0
  1138. X    };
  1139. X
  1140. X
  1141. Xint verlimit[] =
  1142. X    {
  1143. X    3,   // 1.0
  1144. X    8,   // 1.1
  1145. X    0
  1146. X    };
  1147. X
  1148. X
  1149. XCypher* cypherlist[] = 
  1150. X    {
  1151. X                 // Cypher Name              Ver   Author            
  1152. X                 // -------------            ---   ------
  1153. X    &recurxor,   // Recursive XOR            1.0   Merle
  1154. X    &cubicxor,   // Cubic XOR                1.0   Merle
  1155. X    &blockxor,   // Block XOR                1.0   Merle
  1156. X    &quadadd,    // Quadratic Addition       1.1   Merle
  1157. X    &square,     // Square Mod 251           1.1   Merle
  1158. X    &sixteen,    // Sixteen Square Rotation  1.1   Merle
  1159. X    &rotate,     // Byte Rotation            1.1   Merle
  1160. X    &dualxor,    // Dual XOR                 1.1   Merle
  1161. X
  1162. X    0            // NULL
  1163. X    };
  1164. X
  1165. END_OF_FILE
  1166. if test 1108 -ne `wc -c <'syfre/version.c'`; then
  1167.     echo shar: \"'syfre/version.c'\" unpacked with wrong size!
  1168. fi
  1169. # end of 'syfre/version.c'
  1170. fi
  1171. if test -f 'syfre/cyphers/blockxor.c' -a "${1}" != "-c" ; then 
  1172.   echo shar: Will not clobber existing file \"'syfre/cyphers/blockxor.c'\"
  1173. else
  1174. echo shar: Extracting \"'syfre/cyphers/blockxor.c'\" \(2482 characters\)
  1175. sed "s/^X//" >'syfre/cyphers/blockxor.c' <<'END_OF_FILE'
  1176. X// blockxor.c -- "Block XOR" (cypher).
  1177. X//
  1178. X// written by Marc Wallace (Merle), 07 May 93.
  1179. X// first included in version 1.0.
  1180. X
  1181. X
  1182. X#include "../include.h"
  1183. X
  1184. X
  1185. Xstatic Data&
  1186. Xencode(Data& in, Data& out)
  1187. X    {
  1188. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1189. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1190. X    int             ri;              // temp variable (input stream)
  1191. X    int             ro;              // temp variable (output stream)
  1192. X    int             size = in.size;  // size (input stream)
  1193. X
  1194. X    int    s1, s2, s3;
  1195. X
  1196. X    if (size + 4 > out.maxsize)
  1197. X        out.reinit(size + 4);
  1198. X    out.size = size + 4;
  1199. X
  1200. X    // insert four random characters at the beginning
  1201. X    for (ro = 0; ro < 4; ro++)
  1202. X        dto[ro] = randc();
  1203. X
  1204. X    // set up checkpoints at size/4's
  1205. X    s1 = size >> 2;
  1206. X    s2 = size >> 1;
  1207. X    s3 = s1 + s2;
  1208. X
  1209. X    // for the first half, xor with the second half
  1210. X    for (ri = 0; ri < s2; ri++, ro++)
  1211. X        dto[ro] = dti[ri] ^ dti[s2+ri];
  1212. X
  1213. X    // for the third fourth(!), xor with the last fourth
  1214. X    for (; ri < s3; ri++, ro++)
  1215. X        dto[ro] = dti[ri] ^ dti[s1+ri];
  1216. X
  1217. X    // for the last fourth, xor with our four random bytes
  1218. X    for (; ri < size; ri++, ro++)
  1219. X        dto[ro] = dti[ri] ^ dto[ro % 4];
  1220. X
  1221. X    return out;
  1222. X    };
  1223. X
  1224. X
  1225. Xstatic Data&
  1226. Xdecode(Data& in, Data& out)
  1227. X    {
  1228. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1229. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1230. X    int             ri;              // temp variable (input stream)
  1231. X    int             ro;              // temp variable (output stream)
  1232. X    int             size = in.size;  // size (input stream)
  1233. X
  1234. X    int    s1, s2, s3;
  1235. X
  1236. X    size -= 4;
  1237. X    if (size  > out.maxsize)
  1238. X        out.reinit(size);
  1239. X    out.size = size;
  1240. X
  1241. X    // set up checkpoints at size/4's
  1242. X    s1 = size >> 2;
  1243. X    s2 = size >> 1;
  1244. X    s3 = s1 + s2;
  1245. X
  1246. X    // for the last fourth, xor with our four random bytes
  1247. X    for (ro = s3, ri = s3 + 4; ro < size; ri++, ro++)
  1248. X        dto[ro] = dti[ri] ^ dti[ri % 4];
  1249. X
  1250. X    // for the third fourth, xor with the last fourth
  1251. X    for (ro = s2, ri = s2 + 4; ro < s3; ri++, ro++)
  1252. X        dto[ro] = dti[ri] ^ dto[s1+ro];
  1253. X
  1254. X    // for the first half, xor with the second half
  1255. X    for (ro = 0, ri = 4; ro < s2; ri++, ro++)
  1256. X        dto[ro] = dti[ri] ^ dto[s2+ro];
  1257. X
  1258. X    return out;
  1259. X    };
  1260. X
  1261. X
  1262. X#ifndef SECURE
  1263. XCypher blockxor("Block XOR", encode, decode);
  1264. X#else // SECURE
  1265. XCypher blockxor("(unknown)", encode, decode);
  1266. X#endif // SECURE
  1267. X
  1268. END_OF_FILE
  1269. if test 2482 -ne `wc -c <'syfre/cyphers/blockxor.c'`; then
  1270.     echo shar: \"'syfre/cyphers/blockxor.c'\" unpacked with wrong size!
  1271. fi
  1272. # end of 'syfre/cyphers/blockxor.c'
  1273. fi
  1274. if test -f 'syfre/cyphers/blockxor.doc' -a "${1}" != "-c" ; then 
  1275.   echo shar: Will not clobber existing file \"'syfre/cyphers/blockxor.doc'\"
  1276. else
  1277. echo shar: Extracting \"'syfre/cyphers/blockxor.doc'\" \(447 characters\)
  1278. sed "s/^X//" >'syfre/cyphers/blockxor.doc' <<'END_OF_FILE'
  1279. Xcypher: Block XOR
  1280. Xauthor: Merle (Marc Wallace)
  1281. Xdate:   07 May 93
  1282. Xformal: Cypher blockxor("Block XOR", encode, decode);
  1283. X
  1284. X
  1285. Xchoose four random bytes: a[0..3].  store these first.
  1286. Xbreak the data into fourths (A[x], B[x], C[x], D[x])
  1287. Xxor the first block with the third, second with the fourth.
  1288. Xxor the third block with the fourth.
  1289. Xthen xor each element D[x] with a[x mod 4].
  1290. Xso: A=A+C, B=B+D, C=C+D, D=D+a.
  1291. Xto undo, do exactly the same, in reverse.
  1292. X
  1293. X
  1294. X
  1295. END_OF_FILE
  1296. if test 447 -ne `wc -c <'syfre/cyphers/blockxor.doc'`; then
  1297.     echo shar: \"'syfre/cyphers/blockxor.doc'\" unpacked with wrong size!
  1298. fi
  1299. # end of 'syfre/cyphers/blockxor.doc'
  1300. fi
  1301. if test -f 'syfre/cyphers/cubicxor.c' -a "${1}" != "-c" ; then 
  1302.   echo shar: Will not clobber existing file \"'syfre/cyphers/cubicxor.c'\"
  1303. else
  1304. echo shar: Extracting \"'syfre/cyphers/cubicxor.c'\" \(2150 characters\)
  1305. sed "s/^X//" >'syfre/cyphers/cubicxor.c' <<'END_OF_FILE'
  1306. X// cubicxor.c -- "Cubic XOR" (cypher).
  1307. X//
  1308. X// written by Marc Wallace (Merle), 06 May 93.
  1309. X// first included in version 1.0.
  1310. X
  1311. X
  1312. X#include "../include.h"
  1313. X
  1314. X
  1315. Xstatic char arr[256];
  1316. X
  1317. X
  1318. Xstatic Data&
  1319. Xencode(Data& in, Data& out)
  1320. X    {
  1321. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1322. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1323. X    int             ri;              // temp variable (input stream)
  1324. X    int             ro;              // temp variable (output stream)
  1325. X    int             size = in.size;  // size (input stream)
  1326. X
  1327. X    char   mask = 0;
  1328. X    int    d, x;
  1329. X
  1330. X    if (size + 4 > out.maxsize)
  1331. X        out.reinit(size + 4);
  1332. X    out.size = size + 4;
  1333. X
  1334. X    // insert four random characters at the beginning
  1335. X    for (ro = 0; ro < 4; ro++)
  1336. X        dto[ro] = randc();
  1337. X
  1338. X    // set up the cubic array
  1339. X    for (x = 0; x < 256; x++)
  1340. X        arr[x] = (dto[0] * x*x*x + dto[1] * x*x + dto[2] * x + dto[3]) & 0xff;
  1341. X
  1342. X    // for each byte, xor it with the corresponding arr[x]
  1343. X    for (ri = 0; ri < size; ri++, ro++)
  1344. X        dto[ro] = dti[ri] ^ arr[ri % 256];
  1345. X
  1346. X    return out;
  1347. X    };
  1348. X
  1349. X
  1350. Xstatic Data&
  1351. Xdecode(Data& in, Data& out)
  1352. X    {
  1353. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1354. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1355. X    int             ri;              // temp variable (input stream)
  1356. X    int             ro;              // temp variable (output stream)
  1357. X    int             size = in.size;  // size (input stream)
  1358. X
  1359. X    char   mask = 0;
  1360. X    int    d, x;
  1361. X
  1362. X    size -= 4;
  1363. X    if (size  > out.maxsize)
  1364. X        out.reinit(size);
  1365. X    out.size = size;
  1366. X
  1367. X    // parse four random characters from the beginning
  1368. X    // use them to set up the cubic array
  1369. X    for (x = 0; x < 256; x++)
  1370. X        arr[x] = (dti[0] * x*x*x + dti[1] * x*x + dti[2] * x + dti[3]) & 0xff;
  1371. X    ri = 4;
  1372. X
  1373. X    // for each byte, xor it with the corresponding arr[x]
  1374. X    for (ro = 0; ro < size; ri++, ro++)
  1375. X        dto[ro] = dti[ri] ^ arr[ro % 256];
  1376. X
  1377. X    return out;
  1378. X    };
  1379. X
  1380. X
  1381. X#ifndef SECURE
  1382. XCypher cubicxor("Cubic XOR", encode, decode);
  1383. X#else // SECURE
  1384. XCypher cubicxor("(unknown)", encode, decode);
  1385. X#endif // SECURE
  1386. X
  1387. END_OF_FILE
  1388. if test 2150 -ne `wc -c <'syfre/cyphers/cubicxor.c'`; then
  1389.     echo shar: \"'syfre/cyphers/cubicxor.c'\" unpacked with wrong size!
  1390. fi
  1391. # end of 'syfre/cyphers/cubicxor.c'
  1392. fi
  1393. if test -f 'syfre/cyphers/cubicxor.doc' -a "${1}" != "-c" ; then 
  1394.   echo shar: Will not clobber existing file \"'syfre/cyphers/cubicxor.doc'\"
  1395. else
  1396. echo shar: Extracting \"'syfre/cyphers/cubicxor.doc'\" \(343 characters\)
  1397. sed "s/^X//" >'syfre/cyphers/cubicxor.doc' <<'END_OF_FILE'
  1398. Xcypher: Cubic XOR
  1399. Xauthor: Merle (Marc Wallace)
  1400. Xdate:   06 May 93
  1401. Xformal: Cypher cubicxor("Cubic XOR", encode, decode);
  1402. X
  1403. X
  1404. Xchoose four random bytes: a, b, c, and d.  store them first.
  1405. Xconstruct a table arr[x] = (ax^3 + bx^2 + cx + d) mod 256 (char size).
  1406. Xfor each input I[x] output (I[x] ^ arr[x mod d]).
  1407. Xto recover data, do exactly the same.
  1408. X
  1409. X
  1410. END_OF_FILE
  1411. if test 343 -ne `wc -c <'syfre/cyphers/cubicxor.doc'`; then
  1412.     echo shar: \"'syfre/cyphers/cubicxor.doc'\" unpacked with wrong size!
  1413. fi
  1414. # end of 'syfre/cyphers/cubicxor.doc'
  1415. fi
  1416. if test -f 'syfre/cyphers/dualxor.c' -a "${1}" != "-c" ; then 
  1417.   echo shar: Will not clobber existing file \"'syfre/cyphers/dualxor.c'\"
  1418. else
  1419. echo shar: Extracting \"'syfre/cyphers/dualxor.c'\" \(2253 characters\)
  1420. sed "s/^X//" >'syfre/cyphers/dualxor.c' <<'END_OF_FILE'
  1421. X// dualxor.c -- "Dual XOR" (cypher).
  1422. X//
  1423. X// written by Marc Wallace (Merle), 28 May 93.
  1424. X// first included in version 1.1.
  1425. X
  1426. X
  1427. X#include "../include.h"
  1428. X
  1429. X
  1430. Xstatic Data&
  1431. Xencode(Data& in, Data& out)
  1432. X    {
  1433. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1434. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1435. X    int             ri;              // temp variable (input stream)
  1436. X    int             ro;              // temp variable (output stream)
  1437. X    int             size = in.size;  // size (input stream)
  1438. X
  1439. X    int i, j, k;
  1440. X    int a[4], b[4];
  1441. X
  1442. X    if (size + 4 > out.maxsize)
  1443. X        out.reinit(size + 4);
  1444. X    out.size = size + 4;
  1445. X
  1446. X    // insert four random (masking) characters at the beginning
  1447. X    for (ro = 0; ro < 4; ro++)
  1448. X        {
  1449. X        dto[ro] = a[ro] = randc();
  1450. X        b[ro] = 0xff ^ a[ro];
  1451. X        }
  1452. X
  1453. X    // for each 2-byte block, perform the weird swap
  1454. X    i = ri = 0;
  1455. X    while (ri < size)
  1456. X        {
  1457. X        j = dti[ri++];
  1458. X        k = dti[ri++];
  1459. X        dto[ro++] = (j & a[i]) + (k & b[i]);
  1460. X        dto[ro++] = (k & a[i]) + (j & b[i]);
  1461. X        i = (i + 1) % 4;
  1462. X        }
  1463. X
  1464. X    return out;
  1465. X    };
  1466. X
  1467. X
  1468. Xstatic Data&
  1469. Xdecode(Data& in, Data& out)
  1470. X    {
  1471. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1472. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1473. X    int             ri;              // temp variable (input stream)
  1474. X    int             ro;              // temp variable (output stream)
  1475. X    int             size = in.size;  // size (input stream)
  1476. X
  1477. X    int i, j, k;
  1478. X    int a[4], b[4];
  1479. X
  1480. X    size -= 4;
  1481. X    if (size  > out.maxsize)
  1482. X        out.reinit(size);
  1483. X    out.size = size;
  1484. X
  1485. X    // get the four masking characters from the beginning
  1486. X    for (ri = 0; ri < 4; ri++)
  1487. X        {
  1488. X        a[ri] = dti[ri];
  1489. X        b[ri] = 0xff ^ a[ri];
  1490. X        }
  1491. X
  1492. X    // for each 2-byte block, perform the weird swap
  1493. X    i = ro = 0;
  1494. X    while (ro < size)
  1495. X        {
  1496. X        j = dti[ri++];
  1497. X        k = dti[ri++];
  1498. X        dto[ro++] = (j & a[i]) + (k & b[i]);
  1499. X        dto[ro++] = (k & a[i]) + (j & b[i]);
  1500. X        i = (i + 1) % 4;
  1501. X        }
  1502. X
  1503. X    return out;
  1504. X    };
  1505. X
  1506. X
  1507. X#ifndef SECURE
  1508. XCypher dualxor("Dual XOR", encode, decode);
  1509. X#else // SECURE
  1510. XCypher dualxor("(unknown)", encode, decode);
  1511. X#endif // SECURE
  1512. X
  1513. END_OF_FILE
  1514. if test 2253 -ne `wc -c <'syfre/cyphers/dualxor.c'`; then
  1515.     echo shar: \"'syfre/cyphers/dualxor.c'\" unpacked with wrong size!
  1516. fi
  1517. # end of 'syfre/cyphers/dualxor.c'
  1518. fi
  1519. if test -f 'syfre/cyphers/dualxor.doc' -a "${1}" != "-c" ; then 
  1520.   echo shar: Will not clobber existing file \"'syfre/cyphers/dualxor.doc'\"
  1521. else
  1522. echo shar: Extracting \"'syfre/cyphers/dualxor.doc'\" \(423 characters\)
  1523. sed "s/^X//" >'syfre/cyphers/dualxor.doc' <<'END_OF_FILE'
  1524. Xcypher: Dual XOR
  1525. Xauthor: Merle (Marc Wallace)
  1526. Xdate:   28 May 93
  1527. Xformal: Cypher dualxor("Dual XOR", encode, decode);
  1528. X
  1529. X
  1530. Xstore four random numbers a[0..3].  let b[i] = (!a[i]) (bitwise negation).
  1531. Xfor each pair of entries:
  1532. X  let a and b be the current entries in the table (we loop thru these).
  1533. X  read in x and y.  output ((x & a) + (y & b)) and ((y & a) + (x & b)).
  1534. Xundoing it is exactly the same process, amazingly enough.
  1535. X
  1536. X
  1537. END_OF_FILE
  1538. if test 423 -ne `wc -c <'syfre/cyphers/dualxor.doc'`; then
  1539.     echo shar: \"'syfre/cyphers/dualxor.doc'\" unpacked with wrong size!
  1540. fi
  1541. # end of 'syfre/cyphers/dualxor.doc'
  1542. fi
  1543. if test -f 'syfre/cyphers/quadadd.c' -a "${1}" != "-c" ; then 
  1544.   echo shar: Will not clobber existing file \"'syfre/cyphers/quadadd.c'\"
  1545. else
  1546. echo shar: Extracting \"'syfre/cyphers/quadadd.c'\" \(2340 characters\)
  1547. sed "s/^X//" >'syfre/cyphers/quadadd.c' <<'END_OF_FILE'
  1548. X// quadadd.c -- "Quadratic Addition" (cypher).
  1549. X//
  1550. X// written by Marc Wallace (Merle), 12 May 93.
  1551. X// first included in version 1.1.
  1552. X
  1553. X
  1554. X#include "../include.h"
  1555. X
  1556. X
  1557. Xstatic char arr[256];
  1558. X
  1559. X
  1560. Xstatic Data&
  1561. Xencode(Data& in, Data& out)
  1562. X    {
  1563. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1564. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1565. X    int             ri;              // temp variable (input stream)
  1566. X    int             ro;              // temp variable (output stream)
  1567. X    int             size = in.size;  // size (input stream)
  1568. X
  1569. X    char   mask = 0;
  1570. X    int    d, x;
  1571. X
  1572. X    if (size + 4 > out.maxsize)
  1573. X        out.reinit(size + 4);
  1574. X    out.size = size + 4;
  1575. X
  1576. X    // insert four random characters at the beginning
  1577. X    for (ro = 0; ro < 3; ro++)
  1578. X        dto[ro] = randc();
  1579. X    // making sure the fourth one is not too small
  1580. X    // and not too big (has to be positive > 2)
  1581. X    d = (dto[3] = randc(2,127));
  1582. X    ro++;
  1583. X
  1584. X    // set up the quadratic array
  1585. X    for (x = 0; x < d; x++)
  1586. X        arr[x] = (dto[0] * x * x + dto[1] * x + dto[2]) & 0xff;
  1587. X
  1588. X    // process and output the input, byte by byte
  1589. X    for (ri = 0; ri < size; ri++, ro++)
  1590. X        dto[ro] = (dti[ri] + arr[ri % d]) & 0xff;
  1591. X
  1592. X    return out;
  1593. X    };
  1594. X
  1595. X
  1596. Xstatic Data&
  1597. Xdecode(Data& in, Data& out)
  1598. X    {
  1599. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1600. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1601. X    int             ri;              // temp variable (input stream)
  1602. X    int             ro;              // temp variable (output stream)
  1603. X    int             size = in.size;  // size (input stream)
  1604. X
  1605. X    char   mask = 0;
  1606. X    int    d, x;
  1607. X
  1608. X    size -= 4;
  1609. X    if (size  > out.maxsize)
  1610. X        out.reinit(size);
  1611. X    out.size = size;
  1612. X
  1613. X    // parse four random characters from the beginning
  1614. X    // set up the quadratic array backwards (negative)
  1615. X    // by xor'ing it with 0xff ...
  1616. X    d = dti[3];
  1617. X    for (x = 0; x < d; x++)
  1618. X        arr[x] = -((dti[0] * x * x + dti[1] * x + dti[2]) & 0xff);
  1619. X    ri = 4;
  1620. X
  1621. X    // process and decode the input, byte by byte
  1622. X    for (ro = 0; ro < size; ri++, ro++)
  1623. X        dto[ro] = (dti[ri] + arr[ro % d]) & 0xff;
  1624. X
  1625. X    return out;
  1626. X    };
  1627. X
  1628. X
  1629. X#ifndef SECURE
  1630. XCypher quadadd("Quadratic Addition", encode, decode);
  1631. X#else // SECURE
  1632. XCypher quadadd("(unknown)", encode, decode);
  1633. X#endif // SECURE
  1634. X
  1635. END_OF_FILE
  1636. if test 2340 -ne `wc -c <'syfre/cyphers/quadadd.c'`; then
  1637.     echo shar: \"'syfre/cyphers/quadadd.c'\" unpacked with wrong size!
  1638. fi
  1639. # end of 'syfre/cyphers/quadadd.c'
  1640. fi
  1641. if test -f 'syfre/cyphers/quadadd.doc' -a "${1}" != "-c" ; then 
  1642.   echo shar: Will not clobber existing file \"'syfre/cyphers/quadadd.doc'\"
  1643. else
  1644. echo shar: Extracting \"'syfre/cyphers/quadadd.doc'\" \(377 characters\)
  1645. sed "s/^X//" >'syfre/cyphers/quadadd.doc' <<'END_OF_FILE'
  1646. Xcypher: Quadratic Addition
  1647. Xauthor: Merle (Marc Wallace)
  1648. Xdate:   12 May 93
  1649. Xformal: Cypher quadadd("Quadratic Addition", encode, decode);
  1650. X
  1651. X
  1652. Xchoose four random bytes: a, b, c, and d.  store these first.
  1653. Xconstruct a table arr[x] = (ax^2 + bx + c) mod 256 (char size).
  1654. Xfor each input I[x] output (I[x] + arr[x mod d]) mod 256.
  1655. Xto recover data, use the negative of the polynomial.
  1656. X
  1657. X
  1658. END_OF_FILE
  1659. if test 377 -ne `wc -c <'syfre/cyphers/quadadd.doc'`; then
  1660.     echo shar: \"'syfre/cyphers/quadadd.doc'\" unpacked with wrong size!
  1661. fi
  1662. # end of 'syfre/cyphers/quadadd.doc'
  1663. fi
  1664. if test -f 'syfre/cyphers/recurxor.c' -a "${1}" != "-c" ; then 
  1665.   echo shar: Will not clobber existing file \"'syfre/cyphers/recurxor.c'\"
  1666. else
  1667. echo shar: Extracting \"'syfre/cyphers/recurxor.c'\" \(2001 characters\)
  1668. sed "s/^X//" >'syfre/cyphers/recurxor.c' <<'END_OF_FILE'
  1669. X// recurxor.c -- "Recursive XOR" (cypher).
  1670. X//
  1671. X// written by Marc Wallace (Merle), 30 Apr 93.
  1672. X// first included in version 1.0.
  1673. X
  1674. X
  1675. X#include "../include.h"
  1676. X
  1677. X
  1678. Xstatic Data&
  1679. Xencode(Data& in, Data& out)
  1680. X    {
  1681. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1682. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1683. X    int             ri;              // temp variable (input stream)
  1684. X    int             ro;              // temp variable (output stream)
  1685. X    int             size = in.size;  // size (input stream)
  1686. X
  1687. X    char   mask = 0;
  1688. X
  1689. X    if (size + 4 > out.maxsize)
  1690. X        out.reinit(size + 4);
  1691. X    out.size = size + 4;
  1692. X
  1693. X    // insert two random characters at the beginning
  1694. X    for (ro = 0; ro < 2; ro++)
  1695. X        dto[ro] = randc();
  1696. X
  1697. X    // start up the xor machine
  1698. X    for (ri = 0; ri < size; ri++, ro++)
  1699. X        {
  1700. X        mask ^= dti[ri];
  1701. X        dto[ro] = mask;
  1702. X        };
  1703. X
  1704. X    // insert two random characters at the end
  1705. X    dto[ro++] = randc();
  1706. X    dto[ro++] = randc();
  1707. X
  1708. X    return out;
  1709. X    };
  1710. X
  1711. X
  1712. Xstatic Data&
  1713. Xdecode(Data& in, Data& out)
  1714. X    {
  1715. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1716. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1717. X    int             ri;              // temp variable (input stream)
  1718. X    int             ro;              // temp variable (output stream)
  1719. X    int             size = in.size;  // size (input stream)
  1720. X
  1721. X    char   mask = 0;
  1722. X
  1723. X    size -= 4;
  1724. X    if (size  > out.maxsize)
  1725. X        out.reinit(size);
  1726. X    out.size = size;
  1727. X
  1728. X    // ignore two random characters at the beginning
  1729. X    ri = 2;
  1730. X
  1731. X    // start up the xor machine
  1732. X    for (ro = 0; ro < size; ri++, ro++)
  1733. X        {
  1734. X        dto[ro] = mask ^ dti[ri];
  1735. X        mask = dti[ri];
  1736. X        };
  1737. X
  1738. X    // ignore two random characters at the end
  1739. X    // this part is pretty easy ... ;-)
  1740. X
  1741. X    return out;
  1742. X    };
  1743. X
  1744. X
  1745. X#ifndef SECURE
  1746. XCypher recurxor("Recursive XOR", encode, decode);
  1747. X#else // SECURE
  1748. XCypher recurxor("(unknown)", encode, decode);
  1749. X#endif // SECURE
  1750. X
  1751. END_OF_FILE
  1752. if test 2001 -ne `wc -c <'syfre/cyphers/recurxor.c'`; then
  1753.     echo shar: \"'syfre/cyphers/recurxor.c'\" unpacked with wrong size!
  1754. fi
  1755. # end of 'syfre/cyphers/recurxor.c'
  1756. fi
  1757. if test -f 'syfre/cyphers/recurxor.doc' -a "${1}" != "-c" ; then 
  1758.   echo shar: Will not clobber existing file \"'syfre/cyphers/recurxor.doc'\"
  1759. else
  1760. echo shar: Extracting \"'syfre/cyphers/recurxor.doc'\" \(325 characters\)
  1761. sed "s/^X//" >'syfre/cyphers/recurxor.doc' <<'END_OF_FILE'
  1762. Xcypher: Recursive XOR
  1763. Xauthor: Merle (Marc Wallace)
  1764. Xdate:   30 Apr 93
  1765. Xformal: Cypher recurxor("Recursive XOR", encode, decode);
  1766. X
  1767. X
  1768. Xstore two random bytes.
  1769. Xset Mask = 0.
  1770. Xfor each input I: output (I ^ Mask) (xor) and set Mask = (I ^ Mask).
  1771. Xthen store two more random bytes at the end.
  1772. Xto undo, you do basically the same thing.
  1773. X
  1774. X
  1775. END_OF_FILE
  1776. if test 325 -ne `wc -c <'syfre/cyphers/recurxor.doc'`; then
  1777.     echo shar: \"'syfre/cyphers/recurxor.doc'\" unpacked with wrong size!
  1778. fi
  1779. # end of 'syfre/cyphers/recurxor.doc'
  1780. fi
  1781. if test -f 'syfre/cyphers/rotate.c' -a "${1}" != "-c" ; then 
  1782.   echo shar: Will not clobber existing file \"'syfre/cyphers/rotate.c'\"
  1783. else
  1784. echo shar: Extracting \"'syfre/cyphers/rotate.c'\" \(2790 characters\)
  1785. sed "s/^X//" >'syfre/cyphers/rotate.c' <<'END_OF_FILE'
  1786. X// rotate.c -- "Byte Rotation" (cypher).
  1787. X//
  1788. X// written by Marc Wallace (Merle), 28 May 93.
  1789. X// first included in version 1.1.
  1790. X
  1791. X
  1792. X#include "../include.h"
  1793. X
  1794. X
  1795. Xstatic Data&
  1796. Xencode(Data& in, Data& out)
  1797. X    {
  1798. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1799. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1800. X    int             ri;              // temp variable (input stream)
  1801. X    int             ro;              // temp variable (output stream)
  1802. X    int             size = in.size;  // size (input stream)
  1803. X
  1804. X    int i, curr, tmp;
  1805. X    char a[8];
  1806. X
  1807. X    if (size + 4 > out.maxsize)
  1808. X        out.reinit(size + 4);
  1809. X    out.size = size + 4;
  1810. X
  1811. X    // insert four random characters at the beginning
  1812. X    // these represent a[0..7], four random numbers between 2 and 15
  1813. X    for (i = 0; i < 8; i++)
  1814. X        a[i] = randc(1, 15);
  1815. X    for (ro = 0; ro < 4; ro++)
  1816. X        dto[ro] = 16 * a[2 * ro] + a[2 * ro + 1];
  1817. X
  1818. X    // for each possible block of length a[curr], rotate it
  1819. X    curr = 0;
  1820. X    ri = 0;
  1821. X    while (size - ri > a[curr])
  1822. X        {
  1823. X        // { a0 a1 a2 .. an } --> { a1 a2 .. an a0 }
  1824. X        tmp = dti[ri++];
  1825. X        for (i = 1; i < a[curr]; i++)
  1826. X            dto[ro++] = dti[ri++];
  1827. X        dto[ro++] = tmp;
  1828. X        curr = (curr + 1) % 8;
  1829. X        }
  1830. X
  1831. X    // for the rest, just output the bloody stuff
  1832. X    while (ri < size)
  1833. X        dto[ro++] = dti[ri++];
  1834. X
  1835. X    return out;
  1836. X    };
  1837. X
  1838. X
  1839. Xstatic Data&
  1840. Xdecode(Data& in, Data& out)
  1841. X    {
  1842. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1843. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1844. X    int             ri;              // temp variable (input stream)
  1845. X    int             ro;              // temp variable (output stream)
  1846. X    int             size = in.size;  // size (input stream)
  1847. X
  1848. X    int i, curr, marker;
  1849. X    int a[8];
  1850. X
  1851. X    size -= 4;
  1852. X    if (size  > out.maxsize)
  1853. X        out.reinit(size);
  1854. X    out.size = size;
  1855. X
  1856. X    // get four random characters from the beginning
  1857. X    // these represent a[0..7], four random numbers between 2 and 15
  1858. X    for (ri = 0; ri < 4; ri++)
  1859. X        {
  1860. X        a[2 * ri]     = dti[ri] / 16;
  1861. X        a[2 * ri + 1] = dti[ri] % 16;
  1862. X        }
  1863. X
  1864. X    // for each possible block of length a[curr], unrotate it
  1865. X    curr = 0;
  1866. X    ro = 0;
  1867. X    while (size - ro > a[curr])
  1868. X        {
  1869. X        // { a0 a1 a2 .. an } <-- { a1 a2 .. an a0 }
  1870. X        marker = ro++;
  1871. X        for (i = 1; i < a[curr]; i++)
  1872. X            dto[ro++] = dti[ri++];
  1873. X        dto[marker] = dti[ri++];
  1874. X        curr = (curr + 1) % 8;
  1875. X        }
  1876. X
  1877. X    // for the rest, just output the bloody stuff
  1878. X    while (ro < size)
  1879. X        dto[ro++] = dti[ri++];
  1880. X
  1881. X    return out;
  1882. X    };
  1883. X
  1884. X
  1885. X#ifndef SECURE
  1886. XCypher rotate("Byte Rotation", encode, decode);
  1887. X#else // SECURE
  1888. XCypher rotate("(unknown)", encode, decode);
  1889. X#endif // SECURE
  1890. X
  1891. END_OF_FILE
  1892. if test 2790 -ne `wc -c <'syfre/cyphers/rotate.c'`; then
  1893.     echo shar: \"'syfre/cyphers/rotate.c'\" unpacked with wrong size!
  1894. fi
  1895. # end of 'syfre/cyphers/rotate.c'
  1896. fi
  1897. if test -f 'syfre/cyphers/rotate.doc' -a "${1}" != "-c" ; then 
  1898.   echo shar: Will not clobber existing file \"'syfre/cyphers/rotate.doc'\"
  1899. else
  1900. echo shar: Extracting \"'syfre/cyphers/rotate.doc'\" \(502 characters\)
  1901. sed "s/^X//" >'syfre/cyphers/rotate.doc' <<'END_OF_FILE'
  1902. Xcypher: Byte Rotation
  1903. Xauthor: Merle (Marc Wallace)
  1904. Xdate:   28 May 93
  1905. Xformal: Cypher rotate("Byte Rotation", encode, decode);
  1906. X
  1907. X
  1908. Xconstruct eight random numbers a[0..7] between 2 and 15.
  1909. Xstore them in four bytes.
  1910. Xset curr = 0.
  1911. Xwhile there's enough input left
  1912. X  rotate the next block of a[curr] entries right one and output it.
  1913. X  this sends [a0 a1 a2 .. an] --> [a1 a2 .. an a0].
  1914. X  increment curr (mod 8) and recurse.
  1915. Xif there's extra input left, just output it.
  1916. Xto undo, you rotate to the left instead.
  1917. X
  1918. X
  1919. END_OF_FILE
  1920. if test 502 -ne `wc -c <'syfre/cyphers/rotate.doc'`; then
  1921.     echo shar: \"'syfre/cyphers/rotate.doc'\" unpacked with wrong size!
  1922. fi
  1923. # end of 'syfre/cyphers/rotate.doc'
  1924. fi
  1925. if test -f 'syfre/cyphers/sixteen.c' -a "${1}" != "-c" ; then 
  1926.   echo shar: Will not clobber existing file \"'syfre/cyphers/sixteen.c'\"
  1927. else
  1928. echo shar: Extracting \"'syfre/cyphers/sixteen.c'\" \(2583 characters\)
  1929. sed "s/^X//" >'syfre/cyphers/sixteen.c' <<'END_OF_FILE'
  1930. X// sixteen.c -- "Sixteen Square Rotation" (cypher).
  1931. X//
  1932. X// written by Marc Wallace (Merle), 26 May 93.
  1933. X// first included in version 1.1.
  1934. X
  1935. X
  1936. X#include "../include.h"
  1937. X
  1938. X
  1939. Xstatic unsigned char s[256];
  1940. X
  1941. X
  1942. Xstatic void
  1943. Xinit()
  1944. X    {
  1945. X    int i;
  1946. X
  1947. X    // s[] is a rotation matrix, sending the byte [aaaabbbb]->[bbbbaaaa].
  1948. X    // in other words:
  1949. X    for (i = 0; i < 256; i++)
  1950. X        s[i] = 16 * (i % 16) + (i / 16);
  1951. X    // luckily, s[] is its own inverse.. ;-)
  1952. X    }
  1953. X
  1954. X
  1955. Xstatic Data&
  1956. Xencode(Data& in, Data& out)
  1957. X    {
  1958. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1959. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1960. X    int             ri;              // temp variable (input stream)
  1961. X    int             ro;              // temp variable (output stream)
  1962. X    int             size = in.size;  // size (input stream)
  1963. X
  1964. X    int i;
  1965. X
  1966. X    if (size + 4 > out.maxsize)
  1967. X        out.reinit(size + 4);
  1968. X    out.size = size + 4;
  1969. X
  1970. X    // insert three random characters at the beginning
  1971. X    for (ro = 0; ro < 3; ro++)
  1972. X        dto[ro] = randc();
  1973. X
  1974. X    // for each 256-byte block, perform the rotation on it
  1975. X    ri = 0;
  1976. X    while (size - ri > 255)
  1977. X        {
  1978. X        for (i = 0; i < 256; i++, ro++)
  1979. X            dto[ro] = dti[ri + s[i]];
  1980. X        ri += 256;
  1981. X        }
  1982. X
  1983. X    // for the rest, just output the bloody stuff
  1984. X    while (ri < size)
  1985. X        dto[ro++] = dti[ri++];
  1986. X
  1987. X    // insert one random character at the end
  1988. X    dto[ro++] = randc();
  1989. X
  1990. X    return out;
  1991. X    };
  1992. X
  1993. X
  1994. Xstatic Data&
  1995. Xdecode(Data& in, Data& out)
  1996. X    {
  1997. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  1998. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  1999. X    int             ri;              // temp variable (input stream)
  2000. X    int             ro;              // temp variable (output stream)
  2001. X    int             size = in.size;  // size (input stream)
  2002. X
  2003. X    int i;
  2004. X
  2005. X    size -= 4;
  2006. X    if (size  > out.maxsize)
  2007. X        out.reinit(size);
  2008. X    out.size = size;
  2009. X
  2010. X    // ignore three random characters at the beginning
  2011. X    ri = 3;
  2012. X
  2013. X    // for each 256-byte block, perform the rotation on it
  2014. X    ro = 0;
  2015. X    while (size - ro > 255)
  2016. X        {
  2017. X        for (i = 0; i < 256; i++, ro++)
  2018. X            dto[ro] = dti[ri + s[i]];
  2019. X        ri += 256;
  2020. X        }
  2021. X
  2022. X    // for the rest, just output the bloody stuff
  2023. X    while (ro < size)
  2024. X        dto[ro++] = dti[ri++];
  2025. X
  2026. X    // ignore one random character at the end
  2027. X
  2028. X    return out;
  2029. X    };
  2030. X
  2031. X
  2032. X#ifndef SECURE
  2033. XCypher sixteen("Sixteen Square Rotation", encode, decode, init);
  2034. X#else // SECURE
  2035. XCypher sixteen("(unknown)", encode, decode, init);
  2036. X#endif // SECURE
  2037. X
  2038. END_OF_FILE
  2039. if test 2583 -ne `wc -c <'syfre/cyphers/sixteen.c'`; then
  2040.     echo shar: \"'syfre/cyphers/sixteen.c'\" unpacked with wrong size!
  2041. fi
  2042. # end of 'syfre/cyphers/sixteen.c'
  2043. fi
  2044. if test -f 'syfre/cyphers/sixteen.doc' -a "${1}" != "-c" ; then 
  2045.   echo shar: Will not clobber existing file \"'syfre/cyphers/sixteen.doc'\"
  2046. else
  2047. echo shar: Extracting \"'syfre/cyphers/sixteen.doc'\" \(552 characters\)
  2048. sed "s/^X//" >'syfre/cyphers/sixteen.doc' <<'END_OF_FILE'
  2049. Xcypher: Sixteen Square Rotation
  2050. Xauthor: Merle (Marc Wallace)
  2051. Xdate:   26 May 93
  2052. Xformal: Cypher sixteen("Sixteen Square Rotation", encode, decode, init);
  2053. X
  2054. X
  2055. Xto initialize, construct a table s[].
  2056. Xif [aaaabbbb] is the bit representation of a byte, s[aaaabbbb] = [bbbbaaaa].
  2057. Xso s[] is its own inverse.
  2058. X
  2059. Xstore three random bytes.
  2060. Xfor each block of 256 input bytes I[]: output O[i] = I[s[i]].
  2061. Xfor any extra bytes, just output them.  (lame, I know...)
  2062. Xthen store one more random byte at the end.
  2063. Xto undo, you do basically the same thing, since s[s[i]] = i...
  2064. X
  2065. X
  2066. END_OF_FILE
  2067. if test 552 -ne `wc -c <'syfre/cyphers/sixteen.doc'`; then
  2068.     echo shar: \"'syfre/cyphers/sixteen.doc'\" unpacked with wrong size!
  2069. fi
  2070. # end of 'syfre/cyphers/sixteen.doc'
  2071. fi
  2072. if test -f 'syfre/cyphers/square.c' -a "${1}" != "-c" ; then 
  2073.   echo shar: Will not clobber existing file \"'syfre/cyphers/square.c'\"
  2074. else
  2075. echo shar: Extracting \"'syfre/cyphers/square.c'\" \(2510 characters\)
  2076. sed "s/^X//" >'syfre/cyphers/square.c' <<'END_OF_FILE'
  2077. X// square.c -- "Square Mod 251" (cypher).
  2078. X//
  2079. X// written by Marc Wallace (Merle), 26 May 93.
  2080. X// first included in version 1.1.
  2081. X
  2082. X
  2083. X#include "../include.h"
  2084. X
  2085. X
  2086. Xstatic unsigned char s[256], r[256];
  2087. X
  2088. X
  2089. Xstatic void
  2090. Xinit()
  2091. X    {
  2092. X    int i;
  2093. X
  2094. X    // initialize s[i], the array of squares mod 251.
  2095. X    // for half of the entries we need to multiply by 2 for uniqueness.
  2096. X    for (i = 0; i < 251; i++)
  2097. X        s[i] = (i * i) % 251;
  2098. X    for (i = 126; i < 251; i++)
  2099. X        s[i] = (2 * s[i]) % 251;
  2100. X
  2101. X    // initialize r[i], the array of square roots mod 251.
  2102. X    // we'll need to adjust for the doubling done above.
  2103. X    for (i = 0; i < 251; i++)
  2104. X        r[s[i]] = i;  // tricky, eh?
  2105. X
  2106. X    // fill in s[i] and r[i] for i > 250 (special cases).
  2107. X    for (i = 251; i < 256; i++)
  2108. X        s[i] = r[i] = i;
  2109. X    }
  2110. X
  2111. X
  2112. Xstatic Data&
  2113. Xencode(Data& in, Data& out)
  2114. X    {
  2115. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  2116. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  2117. X    int             ri;              // temp variable (input stream)
  2118. X    int             ro;              // temp variable (output stream)
  2119. X    int             size = in.size;  // size (input stream)
  2120. X
  2121. X    if (size + 4 > out.maxsize)
  2122. X        out.reinit(size + 4);
  2123. X    out.size = size + 4;
  2124. X
  2125. X    // insert two random characters at the beginning
  2126. X    for (ro = 0; ro < 2; ro++)
  2127. X        dto[ro] = randc();
  2128. X
  2129. X    // take the square of everything (using s[])
  2130. X    for (ri = 0; ri < size; ri++, ro++)
  2131. X        dto[ro] = s[dti[ri]];
  2132. X
  2133. X    // insert two random characters at the end
  2134. X    dto[ro++] = randc();
  2135. X    dto[ro++] = randc();
  2136. X
  2137. X    return out;
  2138. X    };
  2139. X
  2140. X
  2141. Xstatic Data&
  2142. Xdecode(Data& in, Data& out)
  2143. X    {
  2144. X    unsigned char*  dti = in.data;   // data pointer (input stream)
  2145. X    unsigned char*  dto = out.data;  // data pointer (output stream)
  2146. X    int             ri;              // temp variable (input stream)
  2147. X    int             ro;              // temp variable (output stream)
  2148. X    int             size = in.size;  // size (input stream)
  2149. X
  2150. X    size -= 4;
  2151. X    if (size  > out.maxsize)
  2152. X        out.reinit(size);
  2153. X    out.size = size;
  2154. X
  2155. X    // ignore two random characters at the beginning
  2156. X    ri = 2;
  2157. X
  2158. X    // take the square root of everything (using r[])
  2159. X    for (ro = 0; ro < size; ri++, ro++)
  2160. X        dto[ro] = r[dti[ri]];
  2161. X
  2162. X    // ignore two random characters at the end
  2163. X
  2164. X    return out;
  2165. X    };
  2166. X
  2167. X
  2168. X#ifndef SECURE
  2169. XCypher square("Square Mod 251", encode, decode, init);
  2170. X#else // SECURE
  2171. XCypher square("(unknown)", encode, decode, init);
  2172. X#endif // SECURE
  2173. X
  2174. END_OF_FILE
  2175. if test 2510 -ne `wc -c <'syfre/cyphers/square.c'`; then
  2176.     echo shar: \"'syfre/cyphers/square.c'\" unpacked with wrong size!
  2177. fi
  2178. # end of 'syfre/cyphers/square.c'
  2179. fi
  2180. if test -f 'syfre/cyphers/square.doc' -a "${1}" != "-c" ; then 
  2181.   echo shar: Will not clobber existing file \"'syfre/cyphers/square.doc'\"
  2182. else
  2183. echo shar: Extracting \"'syfre/cyphers/square.doc'\" \(531 characters\)
  2184. sed "s/^X//" >'syfre/cyphers/square.doc' <<'END_OF_FILE'
  2185. Xcypher: Square Mod 251
  2186. Xauthor: Merle (Marc Wallace)
  2187. Xdate:   26 May 93
  2188. Xformal: Cypher square("Square Mod 251", encode, decode, init);
  2189. X
  2190. X
  2191. Xto initialize, construct two tables s[] and r[].
  2192. Xbasically, s[i] = i^2 mod 251.  but these entries aren't unique.
  2193. Xso, for the last half (which repeat) we multiply by two, a non-square.
  2194. Xr[] is just the inverse matrix for s[].
  2195. X
  2196. Xstore two random bytes.
  2197. Xfor each input I: output s[I].
  2198. Xthen store two more random bytes at the end.
  2199. Xto undo, you do basically the same thing, using r[] instead of s[].
  2200. X
  2201. X
  2202. END_OF_FILE
  2203. if test 531 -ne `wc -c <'syfre/cyphers/square.doc'`; then
  2204.     echo shar: \"'syfre/cyphers/square.doc'\" unpacked with wrong size!
  2205. fi
  2206. # end of 'syfre/cyphers/square.doc'
  2207. fi
  2208. echo shar: End of shell archive.
  2209. exit 0
  2210.  
  2211. exit 0 # Just in case...
  2212.