Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
%    Copyright (C) 1992, 1993 Aladdin Enterprises.  All rights reserved.
2
% 
3
% This software is provided AS-IS with no warranty, either express or
4
% implied.
5
% 
6
% This software is distributed under license and may not be copied,
7
% modified or distributed except as expressly authorized under the terms
8
% of the license contained in the file LICENSE in this distribution.
9
% 
10
% For more information about licensing, please refer to
11
% http://www.ghostscript.com/licensing/. For information on
12
% commercial licensing, go to http://www.artifex.com/licensing/ or
13
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14
% San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
 
16
% $Id: type1enc.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
17
% type1enc.ps
18
% PostScript language versions of the Type 1 encryption/decryption algorithms.
19
 
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
 
24
/.type1crypt	% <R> <from> <to> <proc> .type1crypt <R'> <to>
25
		% (auxiliary procedure)
26
 { 4 1 roll
27
 
28
 
29
    {		% Stack: proc R from to index
30
      2 index 1 index get			% proc R from to index C/P
31
      4 index -8 bitshift xor 3 copy put	% proc R from to index P/C
32
      5 index exec				% proc R from to C
33
 
34
%		Compute R' = ((R + C) * 52845 + 22719) mod 65536
35
%		without exceeding a 31-bit integer magnitude, given that
36
%		0 <= R <= 65535 and 0 <= C <= 255.
37
 
38
      4 -1 roll add
39
      dup 20077 mul	% 52845 - 32768
40
      exch 1 and 15 bitshift add	% only care about 16 low-order bits
41
      22719 add 65535 and 3 1 roll
42
    }
43
   for exch pop 3 -1 roll pop
44
 } bind def
45
 
46
% <state> <fromString> <toString> .type1encrypt <newState> <toSubstring>
47
%	Encrypts fromString according to the algorithm for Adobe
48
%	  Type 1 fonts, writing the result into toString.
49
%	  toString must be at least as long as fromString or a
50
%	  rangecheck error occurs.  state is the initial state of
51
%	  the encryption algorithm (a 16-bit non-negative
52
%	  integer); newState is the new state of the algorithm.
53
 
54
/.type1encrypt
55
 { { exch pop } .type1crypt
56
 } bind def
57
 
58
% <state> <fromString> <toString> .type1decrypt <newState> <toSubstring>
59
%	Decrypts fromString according to the algorithm for Adobe
60
%	  Type 1 fonts, writing the result into toString.  Other
61
%	  specifications are as for type1encrypt.
62
 
63
/.type1decrypt
64
 { { pop 2 index exch get } .type1crypt
65
 } bind def