Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[package]
name = "rot26"
version = "0.2.0"
authors = ["jD91mZM2 <[email protected]>"]
description = "Pure rust rewrite of the rot26 algorithm"
license-file = "LICENSE"
name = "rot26"
repository = "https://github.com/jD91mZM2/rot26"
version = "0.1.2"
edition = "2021"
categories = ["algorithms", "cryptography"]
keywords = ["rot26", "encryption"]

[dependencies.rayon]
optional = true
version = "0.9.0"
[dependencies]
rayon = { version = "1.10", optional = true }

[features]
c_api = []

[lib]
crate-type = ["rlib", "staticlib"]
# https://github.com/rust-lang/cargo/issues/4881
4 changes: 2 additions & 2 deletions src/c_api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ::*;
use super::*;
use std::{
ffi::{CStr, CString},
os::raw::*,
Expand All @@ -8,7 +8,7 @@ use std::{
/// Free the Rust-owned string in a safe way.
#[no_mangle]
pub extern fn rot26_free(input: *mut c_char) {
unsafe { CString::from_raw(input); }
unsafe { drop(CString::from_raw(input)); }
}

/// Encrypt the input using rot26.
Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub fn decrypt_rot13(input: &str) -> String {
pub fn encrypt_any(input: &str, amount: u32) -> String {
let closure = |c| {
let base = match c {
'a'...'z' => 'a' as u32,
'A'...'Z' => 'A' as u32,
'a'..='z' => 'a' as u32,
'A'..='Z' => 'A' as u32,
_ => return c
};

Expand All @@ -62,8 +62,8 @@ pub fn encrypt_any(input: &str, amount: u32) -> String {
pub fn decrypt_any(input: &str, amount: u32) -> String {
let closure = |c| {
let base = match c {
'a'...'z' => 'a' as u32,
'A'...'Z' => 'A' as u32,
'a'..='z' => 'a' as u32,
'A'..='Z' => 'A' as u32,
_ => return c
};

Expand All @@ -77,14 +77,14 @@ pub fn decrypt_any(input: &str, amount: u32) -> String {

#[cfg(test)]
mod tests {
use ::*;
use super::*;

#[test]
fn test_rot26() {
let plain = "hello";
let plain = "hello😃";
let encrypted = encrypt(plain);

assert_eq!(encrypted, "hello");
assert_eq!(encrypted, "hello😃");

let decrypted = decrypt(&encrypted);

Expand Down Expand Up @@ -116,10 +116,10 @@ mod tests {
fn test_rot_any() {
let amount = 1;

let plain = "hello";
let plain = "hello😃";
let encrypted = encrypt_any(plain, amount);

assert_eq!(encrypted, "ifmmp");
assert_eq!(encrypted, "ifmmp😃");

let decrypted = decrypt_any(&encrypted, amount);

Expand Down