Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #3295
| From | ken <ken@spamcop.net> |
|---|---|
| Newsgroups | comp.lang.postscript |
| Subject | Re: PostScript Checksum |
| Date | 2018-08-08 08:54 +0100 |
| Message-ID | <MPG.35d4b1f12f353b3398992b@usenet.plus.net> (permalink) |
| References | <9361a5ca-d7cd-4859-8418-d487110aada7@googlegroups.com> |
In article <9361a5ca-d7cd-4859-8418-d487110aada7@googlegroups.com>,
henry.k.adarkwa@gmail.com says...
>
> I have this line of code in PostScript
>
> /checksum {0 --exch-- {2 3 1 2 3 } {1 --index-- 10 --mod-- --mul-- 3 -1 --roll-- --add-- --exch-- 10 --idiv-- } --forall-- --pop-- }
>
> does anyone understand how it works
As I said on Stack Overflow, that isn't actually PostScript, it looks
like its the result of '==' or something on a procedure while running a
PostScript program.
The giveaway is the fact that all the operators are surrounded with '--'
Is there a reason why you can't post the original PostScript code,
rather than relying on the dump ?
The reason I say this is that while I can explain the procedure, it
relies on an argument being passed on the stack, and its not possible to
tell from the procedure itself what that argument is. It 'looks like'
its a number though.
What this does is;
push 0 on the operand stack
- stack now contains <unknown> 0
exchange the top two entries on the operand stack
- stack now contains 0 <unknown>
Push an executable array of 5 numbers on the stack
- stack now contains 0 <unknown> {2 3 1 2 3}
Push an executable array on the operand stack
- stack now contains 0 <unknown> {2 3 1 2 3 }{....}
forall. For every entry in the object 2nd on the stack, execute the
array topmost on the stack.
Discard the top object on the operand stack
So for every element 0 to n of the packed array {2 3 1 2 3} the
interpreter puts the n'th element element on the stack and then:
Initial Stack
0 <unknown>
Push the 1st array element
- stack now contains 0 <unknown> 2
1 index - copy the second element from the stack
- stack now contains 0 <unknown> 2 <unknown>
10 mod - apply modulo 10
- stack now contains 0 <unknown> 2 <unknown mod 10>
mul - multiply the top two elements
- stack now contains 0 <unknown> <(unknown mod 10) x 2>
3 -1 roll - circular shift the top 3 stack elements
- stack now contains <unkown> <(unknown mod 10) x 2> 0
add
- stack now contains <unknown> <((unknown mod 10) x 2) + 0>
exch - exchange the top two elements
- stack now contains <((unknown mod 10) x 2) + 0> <unknown>
10 idiv - divide by 10, returning the quotient
- stack now contains <((unknown mod 10) x 2) + 0> floor(<unknown>
/ 10)
push the 2nd array element
- stack now contains <((unknown mod 10) x 2) + 0> floor(<unknown>
/ 10) 3
...
...
...
Finally, pop one of the numbers from the stack, leaving the calculated
value.
So the routine takes a number applies some mathematical operations to it
repeatedly, using a stored pattern, and returns a number.
You wouldn't be trying to break some kind of encryption would you ?
Ken
Back to comp.lang.postscript | Previous | Next — Previous in thread | Find similar
PostScript Checksum Henry Adarkwa <henry.k.adarkwa@gmail.com> - 2018-08-07 06:45 -0700 Re: PostScript Checksum ken <ken@spamcop.net> - 2018-08-08 08:54 +0100
csiph-web