%!PS % Attempts at reading CID glyphs % ============================== % by Don Lancaster READGLYP.PSL /ggnum 113 store % Copyright c 2010 by Don Lancaster & Synergetics, Box 809, Thatcher, AZ, 85552 % (928) 428-4073 Email: don@tinaja.com Website: http://www.tinaja.com % Consulting services available http://www.tinaja.com/info01.html % Linking welcome. Reposting expressly forbidden. % All commercial rights and all electronic media rights ~fully~ reserved. % Linking usually welcome. Reposting expressly forbidden. Version 1.1 % IMPORTANT NOTE: Don Lancaster's file gonzo.ps is required for this program. % After obvious location mods, uncomment ONE of the following two lines: (C:\\Documents and Settings\\don\\Desktop\\gonzo\\gonzo.ps) run % use internal gonzo % (A:\\gonzo.ps) run % use external gonzo % NOTE THAT ALL PS FILENAME STRINGS !!!DEMAND!!! DOUBLE REVERSE SLASHES. % GONZO20A Guru Gonzo PostScript power tools (Interim release) % Includes gonzo justification and layout utilities. % Copyright c 1990, 1996, 2001 by Don Lancaster and Synergetics, Box 809, % Thatcher Arizona, 5552 (928) 428-4073 don@tinaja.com support % via http://www.tinaja.com All commercial rights and all electronic % media rights **FULLY** reserved. Reposting is expressly forbidden. %%%%%%%%%%%%%%%%%%%%%%%%%% % attempt to read and write CID glyphs... %% excerpted from the type 1 font format doc % < http://partners.adobe.com/public/developer/en/font/T1_SPEC.PDF > ( 1 hstem 12 0 dotsection 3 vstem 12 1 vstem3 4 vmoveto 12 2 hstem3 5 rlineto 12 6 seac 6 hlineto 12 7 sbw 7 vlineto 12 12 div 8 rrcurveto 12 16 callothersubr 9 closepath 12 17 pop 10 callsubr 12 33 setcurrentpoint 11 return 12 escape 13 hsbw 14 endchar 21 rmoveto 22 hmoveto 30 vhcurveto 31 hvcurveto ) pop % for eexec, r is ( To Encrypt a Sequence of Plaintext Bytes to Produce a Sequence of Ciphertext Bytes 1. Generate n random bytes to be additional plaintext bytes at the beginning of the sequence of plaintext bytes, for some value of n. 2. Initialize an unsigned 16-bit integer variable R to the encryption key. 3. For each 8-bit byte, P, of plaintext (beginning with the newly added random bytes) execute the following steps: a. Assign the high order 8 bits of R to a temporary variable, T. b. Exclusive-OR P with T, producing a ciphertext byte, C. c. Compute the next value of R by the formula ((C + R) * c1 + c2) mod 65536, where c1 is 52845 (decimal) and c2 is 22719 (decimal). This encryption step can be performed by the following C language program, where r is initialized to the key for the encryption type: unsigned short int r; unsigned short int c1 = 52845; unsigned short int c2 = 22719; unsigned char Encrypt(plain) unsigned char plain; {unsigned char cipher; cipher = (plain ^ (r>>8)); r = (cipher + r) * c1 + c2; return cipher; } ) pop ( To Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence of Plaintext Bytes 1. Initialize an unsigned 16-bit integer variable R to the encryption key (the same key as used to encrypt). 2. For each 8-bit byte, C, of ciphertext the following steps are executed: a. Assign the high order 8 bits of R to a temporary variable, T. b. Exclusive-OR C with T, producing a plaintext byte, P. c. Compute the next value of R by the formula ((C + R) x c1 + c2) mod 65536, where c1 and c2 are the same constants that were used to encrypt. 3. Discard the first n bytes of plaintext; these are the random bytes added during encryption. The remainder of the plaintext bytes are the original sequence. The decryption step can be performed by the following C language program, where r is initialized to the key for the encryption type: unsigned short int r; unsigned short int c1 = 52845; unsigned short int c2 = 22719; unsigned char Decrypt(cipher) unsigned char cipher; {unsigned char plain; plain = (cipher ^ (r>>8)); r = (cipher + r) * c1 + c2; return plain; } ) pop ( 7.3 Charstring Encryption In charstring encryption, the initial key for the variable R is 4330 (decimal). The number of random bytes, n, is set within the font. By default, n is 4. However, if an entry name lenIV is present in the Private dictionary, then n is the value associated with lenIV. (Version 23.0 of the PostScript interpreter requires n to be 4.) Unlike eexec encryption, charstring encryption imposes no restrictions on the values of the initial ciphertext bytes. A continuation of the encoding example in section 6.6 shows how the charstring can be encrypted. Recall that the charstring looked like BDF9B40D8BEF038BEF01F8ECEF018B16F9 5006EF07FCEC06F88807F8EC06EF07FD5006090E in ASCII hexadecimal notation. These 74 ASCII hexadecimal characters represent 37 plaintext bytes of charstring. Generate four random plaintext bytes to insert at the front of this plaintext charstring. This example uses four zeros (for ease of explanation), resulting in this plaintext: 00000000BDF9B40D8BEF038BEF01F8ECEF018B16F9 5006EF07FCEC06F88807F8EC06EF07FD5006090E Apply charstring encryption to produce the following 41 bytes of ciphertext expressed in ASCII hexadecimal: 10BF31704FAB5B1F03F9B68B1F39A66521B1841F14 81697F8E12B7F7DDD6E3D7248D965B1CD45E2114 ) pop /instring <00000000BDF9B40D8BEF038BEF01F8ECEF018B16F95006EF07FCEC06F88807F8EC06EF07FD5006090E> store /initialkeyr 4330 store % initial key for charstring encoding /c1 52845 store % first encryption constant /c1f1 10569 store % factoring stunt to stay within integer range? /c1f2 5 store /c2 22719 store % second encryption constant /hexstuff [ (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) (A) (B) (C) (D) (E) (F) ] store /r initialkeyr cvi 65536 mod store % init as 16 bit integer (\n\nr is now ) r 20 string cvs mergestr == /encrypt { /enchex (hex bytes are ) store /initialkeyr 4330 store % initial key for charstring encoding /c1 52845 store % first encryption constant /c1f1 10569 store % factoring stunt to stay within integer range? /c1f2 5 store /c2 22719 store % second encryption constant /hexstuff [ (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) (A) (B) (C) (D) (E) (F) ] store /r initialkeyr cvi 65536 mod store % init as 16 bit integer (\n\nr is now ) r 20 string cvs mergestr == 0 1 instring length 1 sub { /curinstringpos exch store instring curinstringpos get /curinchar exch store /t r 256 idiv store % temporary high 8 bit stash of r curinchar t xor cvi /curoutchar exch store curoutchar == curoutchar 16 mod /lowbyte exch store curoutchar 16 idiv /highbyte exch store hexstuff highbyte get hexstuff lowbyte get mergestr /curhexchar exch store curhexchar == /enchex enchex curhexchar mergestr store % calculate new r value /r curoutchar r add cvi 65536 mod c1f1 mul % factoring stunt to stay integer??? cvi 65536 mod c1f2 mul cvi 65536 mod c2 add cvi 65536 mod store (\n\nr is now ) r 20 string cvs mergestr == } for enchex ( ...) mergestr == } store % encrypt % 5 {encrypt} repeat (\n\nstarting new encryptdecrypt...\n\n\n) print flush %%%%%%%%%%%%%%%% try one routine for both encrypt decrypt /initialkeyr 4330 store % initial key for charstring encoding /c1 52845 store % first encryption constant /c1f1 10569 store % factoring stunt to stay within integer range? /c1f2 5 store /c2 22719 store % second encryption constant /hexstuff [ (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) (A) (B) (C) (D) (E) (F) ] store /encryptcharstring { /inhexstring exch store /outhexstring (<) store /r initialkeyr cvi 65536 mod store % init as 16 bit integer inhexstring { r 256 idiv xor /curoutchar exch store outhexstring hexstuff curoutchar 16 idiv get mergestr hexstuff curoutchar 16 mod get mergestr /outhexstring exch store /r curoutchar r add cvi 65536 mod c1f1 mul % factoring stunt to stay integer??? cvi 65536 mod c1f2 mul cvi 65536 mod c2 add cvi 65536 mod store } forall % for each input character outhexstring (>) mergestr /outhexstring exch store outhexstring dup print flush }store /decryptcharstring { /inhexstring exch store /outhexstring (<) store /r initialkeyr cvi 65536 mod store % init as 16 bit integer inhexstring { dup /curinchar exch store r 256 idiv xor /curoutchar exch store outhexstring hexstuff curoutchar 16 idiv get mergestr hexstuff curoutchar 16 mod get mergestr /outhexstring exch store /r curinchar r add cvi 65536 mod c1f1 mul % factoring stunt to stay integer??? cvi 65536 mod c1f2 mul cvi 65536 mod c2 add cvi 65536 mod store } forall % for each input character outhexstring (>) mergestr /outhexstring exch store outhexstring dup print flush }store %%%%%%%%%%%%%%%%%% TEST AREA %%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <00000000BDF9B40D8BEF038BEF01F8ECEF018B16F95006EF07FCEC06F88807F8EC06EF07FD5006090E> encryptcharstring <10BF31704FAB5B1F03F9B68B1F39A66521B1841F1481697F8E12B7F7DDD6E3D7248D965B1CD45E2114> decryptcharstring % now try it with real data... (\n\n\n\n\n\ntest area below\n\n\n) print flush % this was entry 2 of 77 on rtl 1.19 /teststring <001C60D8A8C9B849F23C9DDE7519FC526107D180135A5BBDBFFDD54CC058F D2FAC9738946B3B5BD654A5DADD7A0A32A9AA018EF565E649F47CFF0F3924038 60699B3A3F5D0316FFE9FC6018C87298F41907C3D6B988D4BEC5AB112D59DD23 1604A9B7FF68EFF265BD7485C710B03192A354D77E60EA587A1960B908AEF96D 23D8D11B26C92EE1BEA226D0836563831303D064914994AC670930E714B7F22A 953D51CEC9506DF287DAB8C9DF3DDA337D587E10F294D4FDDBED558> store %%% charstring decript of 4330 yields... /initialkeyr 4330 store % initial key for charstring encoding (\n\nentry 2 with 4330\n\n) print flush teststring decryptcharstring /returnedstring <10C47BE23843763B0B16C844CF9304A4A712635F109FDB83D333881EE389E27 611C8ACE470C12A47A80B00143A6D8F00238B038143EAEB8BE74D713B88E9F36 3327BA02D688CCE3F85A420CD29EC09099A6B33F0AA9A3E0820B8640A4C748D9 A9CDA840E130484B771841D4513EE614CCBA53A604DBED97391352905DCBB084 16EE2AF9637D6237EB14B3FAA70619C46A0D55AB933A839E7CFCE5B1F9F7C0A1 9351650716BA4349023A4EF85B775E6B9389D15F23508804FF8B6> store % which CORRECTLY closes as... (\n\nbackflush...\n\n) print flush returnedstring encryptcharstring <001C60D8A8C9B849F23C9DDE7519FC526107D180135A5BBDBFFDD54CC058FD2 FAC9738946B3B5BD654A5DADD7A0A32A9AA018EF565E649F47CFF0F392403860 699B3A3F5D0316FFE9FC6018C87298F41907C3D6B988D4BEC5AB112D59DD2316 04A9B7FF68EFF265BD7485C710B03192A354D77E60EA587A1960B908AEF96D23 D8D11B26C92EE1BEA226D0836563831303D064914994AC670930E714B7F22A95 3D51CEC9506DF287DAB8C9DF3DDA337D587E10F294D4FDDBED558> % and analyzes as... % woofbark ( <10 C4 7B E2 % padding 38 43 76 3B 0B 16 C8 44 CF 93 04 A4 A7 12 63 5F 10 9F DB 83 D3 33 88 1E E3 89 E2 76 11 C8 AC E4 70C 12 A4 7A 80 B0 01 43 A6 D8 F0 02 38 B0 38 14 3E AE B8 BE 74 D7 13 B8 8E 9F 36 33 27 BA 02 D6 88 CC E3 F8 5A 42 0C D2 9E C0 90 99 A6 B3 3F 0A A9 A3 E0 82 0B 86 40 A4 C7 48 D9 > pop ) pop % try original uncrypt example ( < 00 00 00 00 % padding BD F9 B4 0D 8B EF 03 8B EF 01 F8 EC EF 01 8B 16 F9 50 06 EF 07 FC EC 06 F8 88 07 F8 EC 06 EF 07 FD 50 06 09 0E> pop ) pop %% try password of 5839 decrypt /initialkeyr 5839 store % initial key for charstring encoding (\n\nentry 2 with 5839\n\n) print flush teststring decryptcharstring /returnedstring5839 <16BC28C92713E507C55E0E9BBE03FD9BEE87A542AAC1E3162A4D4D1D542844AB35EB837BB25D79C834EF38711A2E8B15636864D55EF9D548F7E72C60EFD624F604C9C6B5A5B7DBC07A6535119CC63B9D90D678247D2B39DE2A85D41A42CC8D46555CA87E199F7EC1C0B9C2381EC00090DF3DE865DBC319D1D56564D280E43EB44F9F069F8C97CA59C802179FA72330FAFD96F626C26007B68C3AFE7EF58DA12543E5A210A306FFC1AD5AB94F9E6621D4DF4C6E00CA843C4F63BF> store (\n\n5839 returns as...\n\n) print flush /initialkeyr 5839 store returnedstring5839 encryptcharstring % try 5839 decrypt analysis ( <16 BC 28 C9 27 13 E5 07 C5 5E 0E 9B BE 03 FD 9B EE 87 A5 42 AA C1 E3 16 2A 4D 4D 1D 54 28 44 AB 35 EB 83 7B B2 5D 79 C8 34 EF 38 71 1A 2E 8B 15 63 68 64 D5 5E F9 D5 48 F7 E7 2C 60 EF D6 24 F6 04 C9 C6 B5 A5 B7 D ) pop (\n\n\n) print flush % EOF