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 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