       ciphers and programming style

• To: mathgroup at smc.vnet.net
• Subject: [mg13274] ciphers and programming style
• From: Tom <toad at planet.eon.net>
• Date: Fri, 17 Jul 1998 03:18:13 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Hello Mathematica users.

I recently worked on a simple set of definitions to produce a cipher.  A
cipher uses pictures to represent the letters of the alphabet.  This
cipher was used in one of the books about "The Shadow".  Once the basic
pictures were created, in order to disguise the code, they could be
rotated by 90 degrees or 180 degrees, and so on.  This would provide
practice in the application of transformations to geometric figures, a
topic in high school geometry.  I would give the basic cipher, then
give the students a code to decipher where all the letters in the basic
cipher were rotated by 90 degrees or 180 degrees or something like
that.

I managed to get this all to work, but I learned some things that I
didn't know before, and I wondered if someone could help me "clean up"
my efforts somewhat?

All the letters in the cipher are based on circles with various lines
from the center of the circle to points on the circle.  For example,
here is what the letter "k" looks like.

k=Graphics[{Circle[{0,0},1], Line[{{0,1},{0,0},{1,0}}]},
AspectRatio->Automatic];

Show[k];

I wanted to be able to put all the letters into a graphics array at the
end, so that is why I used AspectRatio->Automatic

Since I would be using the same points on the circle for all the letters
(in various forms) and I also thought it would make it easier to rotate
the letter forms, I created a list of points.  Here is part of the
list.

pts={{0,0},{1,0},{0,1},{-1,0},{0,-1}};

So now, I can create letters based on these points.  Below are my
definitions of f,g,k and l

f=Graphics[{Circle[{0,0},1],
Line[{pts[], pts[]}],
Line[{pts[], pts[]}]},AspectRatio->Automatic];

g=Graphics[{Circle[{0,0},1],
Line[{pts[], pts[]}]},AspectRatio->Automatic];

k=Graphics[{Circle[{0,0},1],
Line[{pts[],pts[], pts[] }]},AspectRatio->Automatic];

l=Graphics[{Circle[{0,0},1],
Line[{pts[],pts[], pts[] }]},AspectRatio->Automatic];

Show[GraphicsArray[{f,g,k,l}]];

So far, so good.....

I then found I could rotate all my "letters" 90 degrees by rotating my
list of points by 90 degrees.  I used the rotation matrix
{{0,1},{-1,0}} Here is my original list of points again

pts={{0,0},{1,0},{0,1},{-1,0},{0,-1}};

Using dot product.....

pts=Transpose[{{0,1},{-1,0}}.Transpose[pts]]

{{0,0},{0,-1},{1,0},{0,1},{-1,0}}

So I did get a list of points, rotated through 90 degrees.  (Clockwise)
Here is where things got messy.

First of all, I realized I now messed up my original list of points.
And secondly, I found, to my astonishment, that Mathematica still used
the OLD VALUE of pts when drawing the letters.  I probably read this
somewhere and "knew" it but I had not experienced it before.

Show[GraphicsArray[{f,g,k,l}]];

The letters are not rotated.  So, I needed to redefine the letters and
then redraw them.  SO I redefined the letters and then

Show[GraphicsArray[{f,g,k,l}]];

There they are.....  After I redefined the definitions of f,g,k and l.
Things work fine.  The question is, how might I have done this more
elegantly?  Not having any programming background I would appreciate
any pointers on how I might have implemeted this more nicely. Thanks
for any assistance you might provide.

Sincerely,

Tom

```

• Prev by Date: Re: Limit doesn't work properly
• Next by Date: Re: Default format for new cells
• Previous by thread: Slice plot of 3D data
• Next by thread: Re: ciphers and programming style