Struct PlainTextDetector

Source
pub struct PlainTextDetector {}

Implementations§

Source§

impl PlainTextDetector

Source

pub fn new() -> Self

Source

pub fn is_plain_text( self, plain_or_cipher_text: String, languages: Vec<Language>, minimum_confidence_value: f64, ) -> bool

Detect if plain text if the text correspond to a set of specified know languages.

The presumed plain text is passed as argument. The minimum_confidence_value variable is 1 if we are sure that any word exactly correspond to the corresponding language. The minimum_confidence_value is 0 if we are sure it does not correspond to the corresponding language at all. Return true if it is plain text. Else return false.

use lingua::Language::*;
use lingua::Language;
use cryptatools_core::cryptanalysis::plain_text_detector::PlainTextDetector;
let mut ptd: PlainTextDetector = PlainTextDetector::new();
let text: String = String::from("The ennemies will attack at midnight!");
let is_plain_text = ptd.is_plain_text(text, vec![], 0.0);
assert_eq!(is_plain_text, true);
use lingua::Language::*;
use lingua::Language;
use cryptatools_core::cryptanalysis::plain_text_detector::PlainTextDetector;
let mut ptd: PlainTextDetector = PlainTextDetector::new();
let text: String = String::from("d0n0mIn0thing");
let is_plain_text = ptd.is_plain_text(text, vec![lingua::Language::English, lingua::Language::French], 8.0);
assert_eq!(is_plain_text, false);
Source

pub fn catch_confidence_values( self, plain_or_cipher_text: String, languages: Vec<Language>, ) -> Option<Vec<(Language, f64)>>

For each languages set, return a tuple with confidence value.

The confidence value is a value attributed to a text and a language. More the text corresponds to the corresponding language, more the confidence value will be hight.

use lingua::Language::*;
use lingua::Language;
use cryptatools_core::cryptanalysis::plain_text_detector::PlainTextDetector;
let mut ptd: PlainTextDetector = PlainTextDetector::new();
let text: String = String::from("The ennemies will attack at midnight!");
let is_plain_text = ptd.is_plain_text(text, vec![lingua::Language::English, lingua::Language::French], 0.0);
assert_eq!(is_plain_text, true);
Source

pub fn detect_language( self, plain_or_cipher_text: String, languages: Vec<Language>, ) -> Option<Language>

Detect the language used in a plain text using the confidence value algorithm.

use lingua::Language::*;
use lingua::Language;
use cryptatools_core::cryptanalysis::plain_text_detector::PlainTextDetector;
let mut ptd: PlainTextDetector = PlainTextDetector::new();
let text: String = String::from("languages are awesome");
let detected_language: Option<Language> = ptd.detect_language(text, vec![]);
assert_eq!(detected_language, Some(English));
use lingua::Language::*;
use lingua::Language;
use cryptatools_core::cryptanalysis::plain_text_detector::PlainTextDetector;
let mut ptd: PlainTextDetector = PlainTextDetector::new();
let text: String = String::from("languages are awesome");
let detected_language: Option<Language> = ptd.detect_language(text, vec![lingua::Language::English, lingua::Language::French]);
assert_eq!(detected_language, Some(English));

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<>
§

fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V