
R version 4.5.0 (2025-04-11 ucrt) -- "How About a Twenty-Six"
Copyright (C) 2025 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SVAlignR)
> 
> motif <- "0-50-74-0-50-74-25-26-35"
> alfa <- Cipher(motif)
> alfa
An object of class "Cipher"
Slot "forward":
  0  25  26  35  50  74 
"A" "B" "C" "D" "E" "F" 

Slot "reverse":
   A    B    C    D    E    F    -    ? 
 "0" "25" "26" "35" "50" "74"  ":"  "?" 

Slot "bytes":
[1] 1

> 
> en <-encode(alfa, motif)
> en
[1] "AEFAEFBCD"
> 
> de <- decode(alfa, en)
> de
[1] "0-50-74-0-50-74-25-26-35"
> de == motif
[1] TRUE
> 
> ## bad Cipher inputs
> try( Cipher(13) )
Error in strsplit(sampleText, split) : non-character argument
> try( Cipher(motif, extras = 13) )
Error in Cipher(motif, extras = 13) : 
  All elements of 'extras' must have names.

> try( Cipher(motif, extras = c(z = "zero", 13)) )
Error in Cipher(motif, extras = c(z = "zero", 13)) : 
  All elements of 'extras' must have names.

> try( Cipher(motif, extras = c(A = "zero")) )
Error in Cipher(motif, extras = c(A = "zero")) : 
  Names of 'extras' cannot include symbols in 'sampleText'.

> try( Cipher(motif, extras = c("x" = 26)) )
Error in Cipher(motif, extras = c(x = 26)) : 
  Values of 'extras' cannot match letter in the 'forward' cipher.

> 
> odd <- c(motif, "0-0-50-74-61")
> try( encode(alfa, odd) )
Error in .xlate(text, cipher@forward, "\\-", "", 1) : 
  Text includes unknown characters: 61
> try( encode(odd, alfa) )
Error in strsplit(txt, split) : non-character argument
> 
> ## Longer alphabets
> nchar(IT <- intToUtf8(L <- c(38:44, 46:57, 59:62, 64:126)))
[1] 86
> ## omit hyphen, colon, and question
> JT <- paste(strsplit(IT, "|")[[1]], collapse = "-")
> gamma <- Cipher(JT)
Warning message:
In Cipher(JT) : Input has more than 72 letters. Using two-byte codes.

> 
> b2 <- encode(gamma, JT)
> decode(gamma, b2) == JT
[1] TRUE
> 
> proc.time()
   user  system elapsed 
   1.82    0.17    1.98 
