pub struct PlainTextDetector {}
Implementations§
Source§impl PlainTextDetector
impl PlainTextDetector
pub fn new() -> Self
Sourcepub fn is_plain_text(
self,
plain_or_cipher_text: String,
languages: Vec<Language>,
minimum_confidence_value: f64,
) -> bool
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);
Sourcepub fn catch_confidence_values(
self,
plain_or_cipher_text: String,
languages: Vec<Language>,
) -> Option<Vec<(Language, f64)>>
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);
Sourcepub fn detect_language(
self,
plain_or_cipher_text: String,
languages: Vec<Language>,
) -> Option<Language>
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§
impl Freeze for PlainTextDetector
impl RefUnwindSafe for PlainTextDetector
impl Send for PlainTextDetector
impl Sync for PlainTextDetector
impl Unpin for PlainTextDetector
impl UnwindSafe for PlainTextDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
Create a new handle for an Arc value Read more
§fn clone_handle(handle: Handle) -> Handle
fn clone_handle(handle: Handle) -> Handle
Clone a handle Read more
§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Consume a handle, getting back the initial
Arc<>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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