Learn R Programming

cryptography (version 1.0.0)

four_square: Four-Square Cipher

Description

This can be used to encrypt or decrypt a Four-Square cipher. The Four-Square cipher is a polygraphic substitution cipher that maps digrams of text to two encryption matrices through their position in a square alphabet matrix.

Usage

four_square(message, key1, key2, encrypt = TRUE)

Value

A character vector of either plaintext that has been encrypted or ciphertext that has been decrypted.

Arguments

message

a character vector used as the plaintext to be encrypted or the ciphertext to be decrypted

key1

a character vector used as the encryption key for the first encryption matrix

key2

a character vector used as the encryption key for the second encryption matrix

encrypt

(Default: TRUE) TRUE will encrypt the message, while FALSE will decrypt the message.

Examples

Run this code
four_square("THEPRISONERSHAVEESCAPED", "HACK", "SAFE", encrypt = TRUE)
four_square("SHBOTDTMPFSQDFZSCUHFPBCY", "HACK", "SAFE", encrypt = FALSE)

Run the code above in your browser using DataLab