Skip to main content

atbash

Function atbash 

Source
pub fn atbash(text: &str) -> String
Expand description

Applies the Atbash cipher to a UTF-8 string, substituting only ASCII letters.

Each uppercase letter maps to its mirror: AZ, BY, …, ZA. Lowercase letters mirror within their own range: az, by, …, za. Case is preserved. All other bytes pass through unchanged. Applying this function twice to the same input returns the original string.

§Examples

use rune_atbash::atbash;

assert_eq!(atbash("Hello, World!"), "Svool, Dliow!");
assert_eq!(atbash("Svool, Dliow!"), "Hello, World!");
assert_eq!(atbash("abcxyz"), "zyxcba");
assert_eq!(atbash("ABCXYZ"), "ZYXCBA");
assert_eq!(atbash("123 !@#"), "123 !@#");
assert_eq!(atbash(""), "");