Tag Archives: R

ROT cipher generator/cracker in R

The ever-clever Alex (my wife, dontcha know) sent me a sweet message of garbled gibberish letters with “ROT-13” at the end of it. Naturally, I googled. She used a ROT-13 cipher, which is a simple letter substitution cipher.

Of course, I could have just written the alphabet down on a piece of paper, taken two minutes, and read her (very sweet, as it turns out) message, but where’s the fun in that? Instead, I wrote an R function to generate or crack ROT-style ciphers.

To use this, you enter two arguments: the cipher text and then an integer indicating how many letters to the right (positive integer) or left (negative integer) the function should look for the “right” letter.

Example: My name, Darrin Rogers, is “yvmmdi mjbzmn” if I substitute each letter with the one 5 to the “left” of it in the alphabet. That message can be decrypted (after loading the function in R) with this code:

rot.n(“yvmmdi mjbzmn”, 5)

You can further test out the function with this string, each character encoded with the letter 9 positions away from it in the alphabet:

“evmvi xfeer xzmv pfl lg, evmvi xfeer cvk pfl xf”

Here’s the code.

Continue reading

Graphs with multiple variables

I’ve been trying to get some graphs prepared from the Knowledge & Attitudes data from Fall 2012 (K&A 2012). One of our chunks of data was a series of questions given to survey respondents about their views of the immorality and probable harm caused by various sexual situations (I call these the scenarios): each scenario specified an initiator, a recipient (for lack of a better term), and the age (15 or 21) and sex of each. The initiator was described as “starting a sexual relationship” with the recipient. They always engaged in the same activities: kissing and touching each other’s genitals. There are a lot of variables. Here’s one way to look at them:

  • Initiator sex
  • Initiator age (2 levels: 15 or 21 years old)
  • Recipient sex
  • Recipient age (15 or 21)
  • Immorality rating (DV)
  • Harm rating (DV)

To make things slightly more complex, I simplified the survey forms by cutting out some of the potential crossings of the variables: initiator and perpetrator sex are fully crossed (M/M, M/F, F/M, and F/F conditions) but the ages aren’t–15-year-old initiators are always paired with 21-year-old recipients, and vice-versa. For analysis (but possibly not graphing) purposes it’s also important to know that some comparisons happened between subjects (there were two more-or-less randomly-assigned forms) and others within subjects, with the order of presentation (sadly) fixed. In the future I may do this with more rigorous crossing of all the variables.

I could present subsets of variables in graphs, but I’m really interested in getting as many (independent) variables as possible represented in a single chart, not least because I expect higher-order interactions, and only showing a few variables might obscure those or even mislead the viewer. Here’s an initial stab with only some of the variables:

s.h.01 Continue reading

Dear SPSS: We Have To Break Up

Dear SPSS (or PASW or whatever you call yourself these days),

It’s not working out. For the past few years I’ve tried to pretend everything was all right–and even before that I wasn’t completely satisfied, but I never really expected to be, because there’s no such thing as a perfect statistics application, right? So who’s to say what’s “good enough” in this crazy, mixed-up world? Maybe my standards are too high if I’m not content with your admittedly vast array of analytical features. I guess what I’m trying to say is, It’s not you; it’s me. Continue reading