Skip to content

derekmichaelwright/cypher

Repository files navigation

cypher

cypher: an R package for coding and decoding secret messages


Installation

devtools::install_github("derekmichaelwright/cypher")
library(cypher)

Code Message

xx <- cypher_code("This is a secret coded message")
xx
## [1] "547 134 154 156 165 82 155 167 83 153 87 168 153 151 163 151 170 83 148 161 155 155 155 82 162 156 168 167 154 154 157"

Decoded Message

cypher_decode(xx)
## [1] "This is a secret coded message"

Shiny App

Download and run the following R script:

https://github.com/derekmichaelwright/cypher/blob/master/shinyapp/app.R


Personalize

A custom cypher for this package can be recreated using the following code. However, it should be noted that the recipient will need the Data/cyphers.RData file to decode the messages.

cyphers <- list()
for(i in 1:999) {
  cyphers[i] <- paste(round(runif(1000, 0, 9)),collapse = "")
}
save(cyphers, file = "Data/cyphers.RData")

How it works

This package uses a Caesar cypher in which each letter gets a different shift. Additionally, each message gets a different set of shifts based on the 3 number code at the start of the message. The first 3 numbers indicate which cypher will be used, and indicates the shift used for every character. then the utf8 codes are converted to integers and the caesar shift is added. For decoding, the first 3 numbers are read and used to find the correct cypher, then the integers are shifted, allowing the integers to be converted back to utf8 coding.


R Script/Functions

cypher_code <- function(x) {
  cn <- round(runif(1, 1, 999))
  x <- paste(c(as.numeric(stringr::str_pad(cn, 3, pad = "0")), utf8ToInt(x) + utf8ToInt(substr(cyphers[cn], 1, nchar(x)))), collapse = " ")
  x
}
cypher_decode <- function(x) {
  x <- as.numeric(unlist(strsplit(x, split = " ")))
  cn <- x[1]
  intToUtf8(x[2:length(x)] - utf8ToInt(substr(cyphers[cn], 1, length(x)-1)))
}

© Derek Michael Wright

About

An R package for coding and decoding secret message.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages