type1enc.ps 2.7 KB

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