The Nihilist Cipher

Nihilists in The Big Lebowski
Ja, it seems you have forgotten our little deal, Lebowski

It may be easiest to just let Wikipedia explain the background of the Nihilist Cipher:

In the history of cryptography, the Nihilist cipher is a manually operated symmetric encryption cipher originally used by Russian Nihilists in the 1880s to organize terrorism against the tsarist regime.

There are three parts to this cipher:

  • The keyword used to create a polybius square
  • The key to encrypt the plaintext
  • The plaintext to encrypt

Continue reading

Posted in Ciphers, Crypto | Tagged , , , | Leave a comment

The AMSCO Cipher

AMSCO is an incomplete columnar transposition cipher. A bit to unpack there, but basically that means that you’re putting the message into columns and those columns may not have equal lengths. It was invented by an A.M. Scott in the 19th century, but strangely there is almost nothing online about him.

The AMSCO cipher has two main components. The first is the plain text you wish to encrypt. The second is the numeric key. The key can be a max length of 9 and must contain the numbers 1-n, with n being the length of the key. 1234 and 4132 would both be valid keys, but 1245 would not.

Continue reading

Posted in Ciphers, Crypto | Tagged , , , | Leave a comment

Using Array#map to convert arrays cleanly

Just a nice little Javascript tip that I came by awhile ago on Stackoverflow. If you have an array of strings and you want to convert it to an array of numbers the way you would commonly see that done is using parseInt:

var foo = ['1', '4', '2', '10', '3'];
var numbers = foo.map(function(num) {return parseInt(num, 10)});

That works, but it’s kind of wordy. There is actually a more concise option:

Continue reading

Posted in jQuery / Javascript, Web Development | Tagged , , , | Leave a comment

Freemarker Container to JSON – Part 2

In a previous post, I wrote about using a Freemarker macro to dump a Freemarker container to JSON. That’s nice, but it limits you because macros dump the content directly to the page. It would be better to use a function. I tweaked the original macro to convert it into a function. The main thing to note was that instead of using assign, you need to use local. If you do not, the recursive function calls will step on each other’s variables.

The new objectToJsonFunction is as follows:

Continue reading

Posted in Web Development | Tagged , , , , , | Leave a comment

Freemarker Container to JSON

Kind of a random post, but at work we’ve been trying to find a good way to dump a Freemarker object to JSON. I finally found a nice solution online, but it wasn’t even described as having the ability to do what it does, and now I can’t find the source of it. Hopefully this will help someone else out in the future, and if this code looks familiar, please let me know where it’s from so I can cite the source properly.

The following code will take a Freemarker sequence, hash, or collection (or a mixture of all three) and dump the contents to the page as JSON. It may work with other Freemarker data types as well, but I have not tested it. It’s currently a macro, but I think it would be fairly easy to convert it to a function as well.

Continue reading

Posted in Web Development | Tagged , , , | 2 Comments

Even Easier: RESTful API with Node.js and Express Framework

I just finished up an absolutely thrilling four part series on using the Slim PHP Framework to knock out a RESTful API fairly quickly. This post (and likely a follow-up one) will show how it’s even easier to accomplish the same thing with Node.js and the Express Web Application Framework.

For an IDE, instead of the old faithful Netbeans, I switched over to JetBrain’s WebStorm. JetBrain is best known for the very powerful IntelliJ IDEA and WebStorm is their attempt at crafting the ultimate IDE for Javascript development. So far I’ve been pretty impressed, and it seems to be the most evolved Javascript focused development environment out there.

JetBrain WebStorm - It's probably true
JetBrain WebStorm – It’s probably true

Continue reading

Posted in jQuery / Javascript, Web Development | Tagged , , , , , | 2 Comments

Quickly Build RESTful APIs in PHP with Slim – Part 4

The fourth and final part of this series is focusing on using the Slim Framework’s middleware functionality to validate (to a degree) RESTful API requests. This post will show how to add a simple API key to the requests. There is obviously more one could do, like having a secret key (which would not be passed to the server) to encode some data to further validate the user, but a simple API key is a good first step.

Now, the word middleware may conjure up a lot of Dilbert-type images, but Slim’s middleware is simple and highly functional. To start, let’s modify the route:

   // The old route
   // $this->app->get('/:id', array($this, 'getItem'));
   $this->app->get('/:id/:key', array($this,'verifyKey'), array($this, 'getItem'));

Continue reading

Posted in PHP, Web Development | Tagged , , , , , , , | 6 Comments

Quickly Build RESTful APIs in PHP with Slim – Part 3

The first part of this mini-series showed how to use the Slim Framework to set up a really basic RESTful API. The second part discussed how to actually use that API to do the standard Get, Put, Post, and Delete of data. This part is going to discuss two things:

  • How to use jQuery to do Puts and Deletes
  • Make the API responses more useful

The final topic, How to use Slim’s middleware support to limit the API to valid users, is going to be the subject of Part 4. This post was lengthy enough without diving into that subject.

How to use jQuery to do Puts and Deletes
Since modern browsers do not support PUT or DELETE directly from a form, you have to use their support of XMLHttpRequest, and probably the easiest way to do that is with jQuery. To check your browser’s support of XMLHttpRequest, there is an excellent array of tests available at this site.

Continue reading

Posted in jQuery / Javascript, PHP, Web Development | Tagged , , , , , , , | Leave a comment

Quickly Build RESTful APIs in PHP with Slim – Part 2

I was playing around with Slim Framework recently, and decided to write-up another article about it, since it’s such a breeze. The original post highlighted how simple it was to get your Get, Post, Put, and Delete all wired up and ready to do work. This post will show how to create a little class that utilizes Slim and could serve as a launching point to building your own RESTful API. I’m planning one last post on Slim which will show how to use jQuery to do Puts and Deletes (since modern browsers typically only support Gets and Posts), make the API responses more useful, and how to use Slim’s middleware support to limit the API to valid users.

Time for a QuickNap
To make things more manageable, I created a new class for the API implementation. It’s bare bones at the moment and takes the DB connection information as arguments for its constructor.

require 'lib/QuickNap/QuickNap.php';

$dbUser = "api";
$dbPass = "shhhhhhhhhhhhh";
$dbHost = "localhost";
$dbName = "api";

$quickNap = new \QuickNap\QuickNap($dbHost, $dbName, $dbUser, $dbPass);

$quickNap->enable();

Continue reading

Posted in PHP, Web Development | Tagged , , , , , | Leave a comment