home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sources / hp48 / 281 next >
Encoding:
Text File  |  1992-11-17  |  11.1 KB  |  354 lines

  1. Newsgroups: comp.sources.hp48
  2. Path: sparky!uunet!seq!spell
  3. From: Simone Rapisarda <Simone.Rapisarda@p10.f800.n33.z2.fidonet.org>
  4. Subject:  v07i030:  coder.sr - CODER v1.4, CODER1 v1.0, CODER2 v1.0: Three Strings Encoders/Decoders, Part01/01
  5. Message-ID: <1992Nov18.034452.18754@seq.uncwil.edu>
  6. Followup-To: comp.sys.hp48
  7. Sender: spell@seq.uncwil.edu (Chris Spell)
  8. Organization: Univ. of North Carolina @ Wilmington
  9. Date: Wed, 18 Nov 1992 03:44:52 GMT
  10. Approved: spell@seq.uncwil.edu
  11. Lines: 345
  12.  
  13. Checksum: 1583247124 (verify with brik -cv)
  14. Submitted-by: Simone Rapisarda <Simone.Rapisarda@p10.f800.n33.z2.fidonet.org>
  15. Posting-number: Volume 7, Issue 30
  16. Archive-name: coder.sr/part01
  17.  
  18.  
  19.  
  20. BEGIN_RDME coder.rdm
  21.  
  22. Jim Weisbin reported a bug in CODER which cause it to crash when the string
  23. to encode/decode is empty.
  24.  
  25. I removed the bug and, while I was working on it, I optimized the code too.
  26.  
  27. I also removed the possibility to use other objects instead of strings: in
  28. this way the result is safer than before.
  29. Both the strings may now be tagged, the tags are removed.
  30.  
  31. While I was at it I devoleped other two safer but slower versions of CODER
  32. that I called CODER1 and CODER2. So the following doc describes now a set of
  33. three different (but similar) strings encoder/decoder.
  34.  
  35. Please excuse my bad english.
  36.  
  37. ciao
  38.  
  39.                                                   RAP
  40.  
  41. END_RDME
  42.  
  43. BEGIN_DOC coder.doc
  44.  
  45. Do you keep any top-secret data in your HP48?
  46.  
  47. If yes, the following  set of sys-RPL programs will be very useful to you.
  48.  
  49. =============================================================================
  50.  
  51.  
  52.                              C O D E R    v1.4
  53.                              -----------------
  54.                              C O D E R 1  v1.0
  55.                              -----------------
  56.                              C O D E R 2  v1.0
  57.                              -----------------
  58.  
  59.                          STRING CODERS & DECODERS
  60.  
  61.                                     by
  62.  
  63.                             Simone A. Rapisarda
  64.  
  65.                        These utilities  are dedicated
  66.                        to Jim Weisbin, with gratitude
  67.                       for his excellent ROLDX program.
  68.  
  69. =============================================================================
  70.  
  71.  
  72. +-------------+
  73. | CODER  v1.4 |
  74. +-------------+
  75.  
  76. CODER requires two arguments: a string to encode/decode on level two and a
  77. key string on level one.
  78. The two strings can be of any length, the longer is the key the safer the
  79. encoded string is. If the two strings have the same lenght, the decoding
  80. of an encoded string without the right key is impossible. If the key string
  81. is longer than the string to encode/decode it will be truncated.
  82. The algorithm used is very simple. The program is only 57.5 bytes long. The
  83. coding of a 1000 character string with a 5 character key takes about 0.1
  84. seconds.
  85.  
  86.  
  87.                                USAGE 1
  88.  
  89. |3:                        |             |3:                        |
  90. |2:      "String to Encode"|             |2:                        |
  91. |1:                   "Key"|    ---->    |1:        "Encoded String"|
  92. |CODER ### ### ### ### ### |             |CODER ### ### ### ### ### |
  93. +=====---------------------+             +--------------------------+
  94.  
  95.                                USAGE 2
  96.  
  97. |3:                        |             |3:                        |
  98. |2:      "String to Decode"|             |2:                        |
  99. |1:                   "Key"|    ---->    |1:        "Decoded String"|
  100. |CODER ### ### ### ### ### |             |CODER ### ### ### ### ### |
  101. +=====---------------------+             +--------------------------+
  102.  
  103.  
  104.  
  105.  
  106.                               EXAMPLE 1
  107.  
  108. |3:                        |             |3:                        |
  109. |2:     "ABCDEFGHIJKLMNOPQ"|             |2:                        |
  110. |1:                   "988"|    ---->    |1      "xz{}}~~pqssttvwii"|
  111. |CODER ### ### ### ### ### |             |CODER ### ### ### ### ### |
  112. +=====---------------------+             +--------------------------+
  113.  
  114.                               EXAMPLE 2
  115.  
  116. |3:                        |             |3:                        |
  117. |2:     "xz{}}~~pqssttvwii"|             |2:                        |
  118. |1:                   "988"|    ---->    |1:     "ABCDEFGHIJKLMNOPQ"|
  119. |CODER ### ### ### ### ### |             |CODER ### ### ### ### ### |
  120. +=====---------------------+             +--------------------------+
  121.  
  122.  
  123. =============================================================================
  124.  
  125. +--------------+
  126. | CODER1  v1.0 |
  127. +--------------+
  128.  
  129. CODER1 requires the same arguments as CODER and behaves in the same way.
  130. The only difference is the method used to encode the string that is much
  131. more safer:
  132. - A short key gives excellent results.
  133. - The result is not statistically weak as for CODER.
  134. - The alghoritm used is slower: a 1000 character string takes 7.5 seconds
  135.   and a 100 character string takes 0.3 seconds.
  136.  
  137.  
  138. =============================================================================
  139.  
  140.  
  141. +--------------+
  142. | CODER2  v1.0 |
  143. +--------------+
  144.  
  145. CODER2 requires a String on level two and a Real on level one. The String is
  146. the text to be encoded/decoded and the Real is the key. So the only
  147. difference with thew other two programs is that the key is a Real number and
  148. not a String. This is the safest of the three encoder but it's also the
  149. slower: 21.5 seconds for a 1000 character string and 1.4 seconds for a 100
  150. caracter string.
  151. The Real can be in the range [ MINR, MAXR ] the sign is not used. If the Real
  152. is 0 then the String is not processed.
  153.  
  154. =============================================================================
  155.  
  156.  
  157. Happy Encoding!
  158.  
  159.                                                    RAP
  160.  
  161. END_DOC
  162.  
  163. BEGIN_SRC coder.src
  164.  
  165. I'm a studend attending the second year of Computer Science and I'm not a
  166. professional cryptographer. I've never read articles or books about
  167. cryptology. The behaviour of these three programs came from my personal
  168. considerations and experimentations on the subject and expecially on the XOR
  169. instruction that is the only reversable logic operator. I would really
  170. appreciate any comment or suggestion and particularly a description of the
  171. eventual weaknesses of the algorithms I developed. I know only that for
  172. persons with no experience in cryptology, like me, it should be impossible,
  173. or, at least, very difficult, to discover the original text without the right
  174. key, expecially for CODER2 and CODER1.
  175.  
  176.  
  177. Here is the sys-RPL listing of the programs with some stack diagram and
  178. description. As it's all vanilla sys-RPL I think you should have no problem
  179. to understand what these programs do.
  180.  
  181.  
  182.  
  183. +-------------+
  184. | CODER  v1.4 |
  185. +-------------+
  186.  
  187. Jim Weisbin writes:
  188. "CODER works like this: If the string to decode is longer than the password,
  189.  the password is repeatedly concatenated to itself until its length equals or
  190.  exceeds the string. The two strings are then XOR'd, in system-RPL. Simple,
  191.  but effective!"
  192.  
  193. ::
  194.  CK2NOLASTWD
  195.  CK&DISPATCH0
  196.  FIFTYONE       ->  ( $Text $Key )
  197.  ::
  198.   DUPNULL$?     ->  ( $Text $Key Flag )
  199.   caseDROP      ->  ( $Text )
  200.   OVERLEN$      ->  ( $Text $Key #TextLen )
  201.   SWAP          ->  ( $Text #TextLen $Key )
  202.   BEGIN
  203.   2DUP          ->  ( $Text #TextLen $Key #TextLen $Key )
  204.   LEN$          ->  ( $Text #TextLen $Key #TextLen #KeyLen )
  205.   #>            ->  ( $Text #TextLen $Key Flag )
  206.   OVERSWAP      ->  ( $Text #TextLen $Key $Key Flag )
  207.   WHILE         ->  ( $Text #TextLen $Key $Key )
  208.   &$            ->  ( $Text #TextLen $Key )
  209.   REPEAT        ->  ( $Text #TextLen $Key $Key )
  210.   DROPONE       ->  ( $Text #TextLen $Key #1 )
  211.   ROT           ->  ( $Text $Key #1 #TextLen )
  212.   SUB$          ->  ( $Text $Key )
  213.   XOR$          ->  ( $NewText )
  214.  ;
  215. ;
  216.  
  217.  
  218.  
  219. +--------------+
  220. | CODER1  v1.0 |
  221. +--------------+
  222.  
  223. The program takes the CRC of the Key, turns it into a two character String
  224. and append it to the Key. This is done repeatedly until the Key is longer
  225. then the text. The Key is finally truncated so to cut off the original key
  226. from the new key and then the two strings are XOR'd.
  227.  
  228. ::
  229.  CK2NOLASTWD
  230.  CK&DISPATCH0
  231.  FIFTYONE       ->  ( $Text $Key )
  232.  ::
  233.   OVERLEN$      ->  ( $Text $Key #TextLen )
  234.   DUP#0=        ->  ( $Text $Key #TextLen Flag )
  235.   case2DROP     ->  ( $Text )
  236.   OVERLEN$      ->  ( $Text $Key #TextLen #KeyLen )
  237.   #0=           ->  ( $Text $Key #TextLen Flag )
  238.   case2DROP     ->  ( $Text )
  239.   #1+           ->  ( $Text $Key #TextLen+1 )
  240.   #2/           ->  ( $Text $Key #(TextLen+1)/2 )
  241.   ZERO_DO       ->  ( $Text $Key )
  242.   DUP           ->  ( $Text $Key $Key )
  243.   OCRC          ->  ( $Text $Key #KeyBytes HXSKeyCRC )
  244.   SWAPDROP      ->  ( $Text $Key HXSKeyCRC )
  245.   SWAP&$        ->  ( $Text $Key )
  246.   LOOP
  247.   OVERLEN$      ->  ( $Text $Key #TextLen )
  248.   ONESWAP       ->  ( $Text $Key #1 #TextLen )
  249.   SUB$          ->  ( $Text $Key )
  250.   XOR$          ->  ( $NewText )
  251.  ;
  252. ;
  253.  
  254.  
  255.  
  256. +--------------+
  257. | CODER2  v1.0 |
  258. +--------------+
  259.  
  260. The Real number (the Key) is stored as the seed of the pseudo-random number
  261. generator that is used to create a String (the real Key) of pseudo-random
  262. characters with the same lenght of the text. The two Strings are finally
  263. XOR'd. The slow part of the code is the pseudo-random character generation
  264. that could be easely speeded-up about twenty times by a simple ML routine.
  265. Sorry but at the moment I'm not able to do this.
  266.  
  267. ::
  268.  CK2NOLASTWD
  269.  CK&DISPATCH0
  270.  FORTYNINE      ->  ( $Text %Key )
  271.  ::
  272.   DUP%0=        ->  ( $Text %Key Flag )
  273.   caseDROP      ->  ( $Text )
  274.   DORANDOMIZE   ->  ( $Text )
  275.   NULL$         ->  ( $Text $Key )
  276.   OVERLEN$      ->  ( $Text $Key #TextLen )
  277.   DUP#0=        ->  ( $Text $Key #TextLen Flag )
  278.   case2DROP     ->  ( $Text )
  279.   ZERO_DO       ->  ( $Text $Key )
  280.   %RAN          ->  ( $Text $Key %Random )
  281.   % 256         ->  ( $Text $Key %Random %256 )
  282.   %*            ->  ( $Text $Key %Random*256 )
  283.   %IP>#         ->  ( $Text $Key #Random )
  284.   #>CHR         ->  ( $Text $Key CHRRandom )
  285.   >T$           ->  ( $Text $Key )
  286.   LOOP
  287.   XOR$          ->  ( $Text )
  288.   %0            ->  ( $Text %0 )
  289.   %RANDOMIZE    ->  ( $Text )
  290.  ;
  291. ;
  292.  
  293.  
  294. END_SRC
  295.  
  296.  
  297. BEGIN_ASC coder.asc
  298. %%HP:;
  299. "D9D20D8A81D9F8185B46D9D2090236B491622650322302A170CA1306365038D3
  300. 013D26EE170391505E170649265923033750B9881B2130B21301CFC"
  301. END_ASC
  302.  
  303.  
  304. BEGIN_ASC coder1.asc
  305. %%HP:;
  306. "D9D20D8A81D9F8185B46D9D20226506622607916226506AC3007916FED30E8E3
  307. 03C3708813044950B9F06FE226433702265076E2633750B9881B2130B2130D67
  308. 1"
  309. END_ASC
  310.  
  311.  
  312. BEGIN_ASC coder2.asc
  313. %%HP:;
  314. "D9D20D8A81D9F8144B46D9D20AAB36B4916B70B2FD5502265066226079163C37
  315. 02CFA2339202000000000006520CB9A211CE257A50EE25043370B98814B2A244
  316. 0B2B2130B21304E99"
  317. END_ASC
  318.  
  319. BYTES: #CFC1h 57.5
  320.  
  321. BEGIN_UU coder.uue
  322. begin 644 coder.bin
  323. M2%!(4#0X+46=+="H&)V/@;5DG2V0(&-+&29B!2,R(!H'K#%@8P6#/1#38NYQ;
  324. 5,!D%Y7%@E&*5,C!S!9N(L1(#*S$`N
  325. ``
  326. end
  327. END_UU
  328.  
  329. BYTES: 176Dh 62.5
  330.  
  331. BEGIN_UU coder1.uue
  332. begin 644 coder1.bin
  333. M2%!(4#0X+46=+="H&)V/@;5DG2T@8@5F(@:782)68,H#<!GVW@../C`\!X@Q"
  334. :0)0%FP_V+F(T<R!B!6<N-G,%FXBQ$@,K,0"76
  335. ``
  336. end
  337. END_UU
  338.  
  339. BYTES: 99E4h 70.5
  340.  
  341. BEGIN_UU coder2.uue
  342. begin 644 coder2.bin
  343. M2%!(4#0X+46=+="H&)V/0;1DG2V@NF-+&;8'*]]5(&(%9B(&EV'#<R#\*C,I9
  344. B(```````8"7`FRH1[%*G!>Y20#,'FXA!*RI$L+(2`RLQ`"(&7
  345. ``
  346. end
  347. END_UU
  348. --  
  349.  WolfNet BBS Pisa (Italy) Tel. +39-50-589050 300-14.4K Baud Matrix 2:332/602.0
  350.  Simone Rapisarda - via FidoNet node 2:33/800
  351.  UUCP: ...!gear!wolf!800.10!Simone.Rapisarda
  352.  ARPA: Simone.Rapisarda@p10.f800.n33.z2.fidonet.org
  353.  
  354.