Python: How to Cipher in Blender

An adorable little house...

I like shift ciphers as much as the next guy but Caesar is just so damn obvious. If you’re sending a giant wall of nonsense letters to a friend in an email, you might as well wave a giant neon-colored flag around that says “HEY I’M A SHADY BASTARD” to any third parties that might stumble upon it.

A proper cipher should have some form of camouflage. Like a sweet little house on a hill. With fireflies hanging out.

What’s marvelous about shift ciphers is that once you rotate the alphabet, you can keep the shifted numbers and code them into pretty much anything you can represent numerically. In ROT7 (where you shift the alphabet up by 7), A=8, B=9, C=10 and so on. Once you hit 26, loop back to 1. I use 27 for SPACE.

So say your sweet little house on the hill is actually a Blender model. It’s in the positive XYZ axis. And it’s semi-cubical. The dimensions of the cube are 27 by 27 by 27.

You can take those numbers, put them into a list in Python, and loop them into the location parameters of a bunch of fireflies in the scene. Give that to someone, and they can retrieve the coordinates to decipher the message. This is also just an easy way to practice using Python lists.

Useful Commands

#Display Object name and coordinates in System Console
print(obj.name)
print(obj.location)

#Assign values to a list
listname = [ ]

#Accessing items in a list (you can use this like a variable)
#Note that the 1st item in a list is at Position 0
listname[#PositionInList]

#Get the number of items in a list
len(listname)

#Loop through all items in a list
for index in range(len(listname)):
      do this to listname[index]

The Text Editor

Because I’m an idiot, I’ve been using the Python console for the last 3 weeks—that meant I had to start over every time I had a typo. I was on the verge of bashing my keyboard in with a mallet when I realized you can run scripts from the Text Editor in Blender.

Oh. Blender has a text editor.

The Text Editor will also let you save the script as a .txt so you can edit it in Notepad. And run it multiple times without having to retype it.

Since it’s in a .txt, you’ll need to import BPY (all the Blender things) first.

Putting the Message into a Blender Scene

Here’s a sample enciphered message (ROT7):

8 27 1 22 4 12 19 27 1 15 12 27 15 16 1 10 15 15 16 18 12 25 26 27 14 2 16 11 12 27 1 22 27 1 15 12 27 14 8 19 8 5 6 27 26 8 6 26 27 16 26 27 8 9 22 2 1 27 1 15 12 27 20 22 26 1 27 20 8 26 26 16 3 12 19 6 27 2 26 12 13 2 19 27 1 15 16 21 14 27 8 21 27 16 21 1 12 25 26 1 12 19 19 8 25 27 15 16 1 10 15 15 16 18 12 25 27 10 8 21 27 15 8 3 12 27 23 8 25 1 19 6 27 16 1 27 15 8 26 27 14 25 12 8 1 27 23 25 8 10 1 16 10 8 19 27 3 8 19 2 12 27 6 22 2 27 10 8 21 27 4 25 8 23 27 16 1 27 8 25 22 2 21 11 27 6 22 2 27 13 22 25 27 4 8 25 20 1 15 27 8 26 27 6 22 2 27 9 22 2 21 11 27 8 10 25 22 26 26 27 1 15 12 27 10 22 19 11 27 20 22 22 21 26 27 22 13 27 17 8 14 19 8 21 27 9 12 1 8 27 6 22 2 27 10 8 21 27 19 16 12 27 22 21 27 16 1 27 22 21 27 1 15 12 27 9 25 16 19 19 16 8 21 1 27 20 8 25 9 19 12 26 8 21 11 12 11 27 9 12 8 10 15 12 26 27 22 13 27 26 8 21 1 25 8 14 16 21 2 26 27 3 27 16 21 15 8 19 16 21 14 27 1 15 12 27 15 12 8 11 6 27 26 12 8 27 3 8 23 22 25 26 27 6 22 2 27 10 8 21 27 26 19 12 12 23 27 2 21 11 12 25 27 16 1 27 9 12 21 12 8 1 15 27 1 15 12 27 26 1 8 25 26 27 4 15 16 10 15 27 26 15 16 21 12 27 26 22 27 25 12 11 19 6 27 22 21 27 1 15 12 27 11 12 26 12 25 1 27 4 22 25 19 11 27 22 13 27 18 8 18 25 8 13 22 22 21 27 2 26 12 27 16 1 27 1 22 27 26 8 16 19 27 8 27 20 16 21 16 25 8 13 1 27 11 22 4 21 27 1 15 12 27 26 19 22 4 27 15 12 8 3 6 27 25 16 3 12 25 27 20 22 1 15 27 4 12 1 27 16 1 27 13 22 25 27 2 26 12 27 16 21 27 15 8 21 11 1 22 15 8 21 11 10 22 20 9 8 1 27 4 25 8 23 27 16 1 27 25 22 2 21 11 27 6 22 2 25 27 15 12 8 11 27 1 22 27 4 8 25 11 27 22 13 13 27 21 22 5 16 22 2 26 27 13 2 20 12 26 27 22 25 27 8 3 22 16 11 27 1 15 12 27 14 8 7 12 27 22 13 27 1 15 12 27 25 8 3 12 21 22 2 26 27 9 2 14 9 19 8 1 1 12 25 27 9 12 8 26 1 27 22 13 27 1 25 8 8 19 27 26 2 10 15 27 8 27 20 16 21 11 9 22 14 14 16 21 14 19 6 27 26 1 2 23 16 11 27 8 21 16 20 8 19 27 16 1 27 8 26 26 2 20 12 26 27 1 15 8 1 27 16 13 27 6 22 2 27 10 8 21 1 27 26 12 12 27 16 1 27 16 1 27 10 8 21 1 27 26 12 12 27 6 22 2 27 6 22 2 27 10 8 21 27 4 8 3 12 27 6 22 2 25 27 1 22 4 12 19 27 16 21 27 12 20 12 25 14 12 21 10 16 12 26 27 8 26 27 8 27 11 16 26 1 25 12 26 26 27 26 16 14 21 8 19 27 8 21 11 27 22 13 27 10 22 2 25 26 12 27 11 25 6 27 6 22 2 25 26 12 19 13 27 22 13 13 27 4 16 1 15 27 16 1 27 16 13 27 16 1 27 26 1 16 19 19 27 26 12 12 20 26 27 1 22 27 9 12 27 10 19 12 8 21 27 12 21 22 2 14 15 27

This week’s script is very short–just 4 parts to push the message into the model:

Step By Step Blender Cipher

Step 4 is the part that can be customized if you want something other than spheres.

To Push Values from List into Blender

Here’s a copy/paste version:

import bpy

verts=[8,27,1,22,4,12,19,27,1,15,12,27,15,16,1,10,15,15... All the numbers from above]

pos=0

for index in range(len(verts)):
bpy.ops.mesh.primitive_uv_sphere_add(size=.5,location=(verts[pos],verts[pos+1],verts[pos+2]))
pos += 3

Run the script, make sure the spheres are in place, and save the file.

Retrieving the Message

Move the spheres into their own layer and highlight them. Use these 4 lines of code to pull the coordinates out.

import bpy

for obj in bpy.context.selected_objects:
print(obj.name)
print(obj.location)

This will send the name and xyz coordinates to the System console. If it’s not already up, you can open that window here:

Accessing the System Console in Blender

After you run the code, it should display like so:

theresult

Then it’s just a matter of plugging the numbers into an ROT7 decipherer to read the message. Hoping to make the whole thing slightly more user friendly in the next few months.

Advertisements
Tagged , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: