---
title: "Encrypting and decrypting text"
author: "Jacob Kaplan"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Encrypting-and-decrypting-text}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

There are two functions in this package:

* `caesar()` uses a traditional Caesar cipher to encrypt or decrypt text.    
* `seed_cipher()` encrypts or decrypts text based on a specific seed.

For both functions the only required parameter is `text` which is a string or vector of string that you want to encrypt/decrypt. The functions will output a string with the text encrypted (or decrypted). If you do decide to change the default value of the `shift` parameter (`seed` in `seed_cipher()`), which you should to make it secure, make sure not to forget the value you set.

# caesar()

The Caesar cipher is an ancient cipher which is made by shifting the letters of the alphabet by a set number. So a shift of -3, for example, would move each letter to the left by 3, such that A would become X and D would become A. For this package it also includes numbers and punctuation but the concept is the same.  

```{r echo=TRUE}
 caesar::caesar(text = "As a rule, men worry more about what they can't see than about what they can.")
```

You can do it for a vector of strings.

```{r echo=TRUE}
 caesar::caesar(text = c("As a rule, men worry more about what they can't see than about what they can.", "The best way of avenging thyself is not to become like the wrong doer."))
```

You can set the shift yourself as one of the optional parameters. This can be any whole number (positive or negative). If you do decide to change the default value of the `shift` parameter (which you should to make it secure), make sure not to forget the value you set.

```{r echo=TRUE}
 caesar::caesar(text = "As a rule, men worry more about what they can't see than about what they can.", 
        shift = -100)
```

To decrypt the text change the parameter `decrypt` to TRUE.  

```{r echo=TRUE}
 caesar::caesar(text = "Dvcdcuxoh cphqczruuBcpruhcderxwczkdwcwkhBcfdq,wcvhhcwkdqcderxwczkdwcwkhBcfdqa",
        decrypt = TRUE)
```

Make sure the shift value is the same as it was when encrypted.

```{r echo=TRUE}
 caesar::caesar(text = "rj};}ilc>[}d>e}nfiip}dfi>};:flk}n/;k}k/>p}';e=k}j>>}k/;e};:flk}n/;k}k/>p}';e]", 
        shift = -100, 
        decrypt = TRUE)
```



# seed_cipher()

This method randomizes the alphabet based on a seed you set, making it far more secure than the Caesar cipher. 

```{r echo=TRUE}
 caesar::seed_cipher(text = "As a rule, men worry more about what they can't see than about what they can.")
```

You can set the seed yourself as one of the optional parameters. This can be any whole number (positive or negative). If you do decide to change the default value of the `seed` parameter (which you should to make it secure), make sure not to forget the value you set.

```{r echo=TRUE}
 caesar::seed_cipher(text = "As a rule, men worry more about what they can't see than about what they can.", 
        seed = -100)
```

To decrypt the text change the parameter `decrypt` to TRUE.  

```{r echo=TRUE}
 caesar::seed_cipher(text = "R#GdG<VfhbG$hXGeC<<oG$C<hGd+CV/Ge0d/G/0hoGdXg/G#hhG/0dXGd+CV/Ge0d/G/0hoG dX_",
        decrypt = TRUE)
```

Make sure the seed value is the same as it was when encrypted.

```{r echo=TRUE}
 caesar::seed_cipher(text = "Eucfc{%>Dc-Dkc8S{{$c-S{DcfyS%*c8Qf*c*QD$cofkR*cuDDc*QfkcfyS%*c8Qf*c*QD$cofki", 
        seed = -100, 
        decrypt = TRUE)
```
