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 ROT cipher generator/cracker in R
I gave a 50-minute presentation at SUNY Fredonia’s Spring 2016 Faculty Professional Development Day. It was a very nice experience. Of course, I prepared way more content than was reasonable for a 50-minute presentation, but I think it went well, anyway. Here is the presentation (PowerPoint; I know all the cool R people use LaTeX for their R presentation slides, but… ).
One thing I did not do in the presentation was a demo I created for simulating 100,000 games of Twenty-One against a dealer, when you have a “hold rule” of 18 or higher, and the dealer has a rule of 17 or higher. It’s over-simplified: Aces always count as 1, and there are only two card draws after the initial deal. However, I think it is at least a little bit fun.
At some point I should go back and add the possibility of Aces being 1 or 11, and also make the output at each step pretty. But for an intro workshop this seemed appropriate, if too long-winded for a 50-minute session. The code is after the break. Continue reading Intro to R and a Gambling Demo
I occasionally write functions in R to help me with some aspect of teaching, usually teaching undergrad stats. I always intend to share them with others, but I don’t actually know many other people who use R for teaching. So why not share in blog posts? I’ll start now.
Disclaimer: This functions is untested by anyone but me, it might not work, and I provide no guarantee of accuracy. I mean, I try, but you know…
An R function for visualizing single-sample z-tests, a function I named zvis, produces graphs as below, using (usually) pretty simple options:
zvis(x=104, mu0=100, sigma=15, n=30)
I won’t paste the code here because it’s kind of long, but anyone interested can have it from this link –> zvis. The whole set of arguments can be seen after the break. If, by chance, anyone is interested in this function and wants more explanation of these options, or has suggestions for improving the function, please let me know. Continue reading R for Teaching: Visualize a z-test