home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / lib / type1enc.ps < prev    next >
Encoding:
Text File  |  2000-12-05  |  2.7 KB  |  68 lines

  1. %    Copyright (C) 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of AFPL Ghostscript.
  3. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  4. % distributor accepts any responsibility for the consequences of using it, or
  5. % for whether it serves any particular purpose or works at all, unless he or
  6. % she says so in writing.  Refer to the Aladdin Free Public License (the
  7. % "License") for full details.
  8. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. % in a plain ASCII text file named PUBLIC.  The License grants you the right
  10. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. % conditions described in the License.  Among other things, the License
  12. % requires that the copyright notice and this notice be preserved on all
  13. % copies.
  14.  
  15. % $Id: type1enc.ps,v 1.2 2000/09/19 18:29:11 lpd Exp $
  16. % type1enc.ps
  17. % PostScript language versions of the Type 1 encryption/decryption algorithms.
  18.  
  19. % This file is normally not needed with Ghostscript, since Ghostscript
  20. % implements these algorithms in C.  For the specifications, see Chapter 7 of
  21. % "Adobe Type 1 Font Format," ISBN 0-201-57044-0, published by Addison-Wesley.
  22.  
  23. /.type1crypt    % <R> <from> <to> <proc> .type1crypt <R'> <to>
  24.         % (auxiliary procedure)
  25.  { 4 1 roll
  26.    0 2 index length getinterval
  27.    0 1 2 index length 1 sub
  28.     {        % Stack: proc R from to index
  29.       2 index 1 index get            % proc R from to index C/P
  30.       4 index -8 bitshift xor 3 copy put    % proc R from to index P/C
  31.       5 index exec                % proc R from to C
  32.  
  33. %        Compute R' = ((R + C) * 52845 + 22719) mod 65536
  34. %        without exceeding a 31-bit integer magnitude, given that
  35. %        0 <= R <= 65535 and 0 <= C <= 255.
  36.  
  37.       4 -1 roll add
  38.       dup 20077 mul    % 52845 - 32768
  39.       exch 1 and 15 bitshift add    % only care about 16 low-order bits
  40.       22719 add 65535 and 3 1 roll
  41.     }
  42.    for exch pop 3 -1 roll pop
  43.  } bind def
  44.  
  45. % <state> <fromString> <toString> .type1encrypt <newState> <toSubstring>
  46. %    Encrypts fromString according to the algorithm for Adobe
  47. %      Type 1 fonts, writing the result into toString.
  48. %      toString must be at least as long as fromString or a
  49. %      rangecheck error occurs.  state is the initial state of
  50. %      the encryption algorithm (a 16-bit non-negative
  51. %      integer); newState is the new state of the algorithm.
  52.  
  53. /.type1encrypt
  54.  { { exch pop } .type1crypt
  55.  } bind def
  56.  
  57. % <state> <fromString> <toString> .type1decrypt <newState> <toSubstring>
  58. %    Decrypts fromString according to the algorithm for Adobe
  59. %      Type 1 fonts, writing the result into toString.  Other
  60. %      specifications are as for type1encrypt.
  61.  
  62. /.type1decrypt
  63.  { { pop 2 index exch get } .type1crypt
  64.  } bind def
  65.