Skip to content

Commit

Permalink
update (mapper): salt mapping feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lumbrjx committed Jan 13, 2024
1 parent 3dfd0f3 commit 8666528
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
42 changes: 23 additions & 19 deletions src/encpt/mapping/mapper.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
use crate::maps::first_lvl::*;
use crate::maps::chars::*;
use crate::maps::salt::*;

// uncompleted
pub fn mapper_lvl1(vc: Vec<&str>) -> Result<Vec<[&str; 3]>, &str> {
let mut result: Vec<[&str; 3]> = vec![];
for e in vc {
for s in CHAR_MAP {
if e == s[0] {
result.push(s);
println!("{:?}", s)
#[derive(PartialEq)]
pub enum MpType {
CharMap,
SaltMap,
}

pub fn chr_to_mp(vc: Vec<&str>, mpt: MpType) -> Result<Vec<&str>, &str> {
let mut result: Vec<&str> = vec![];
let mpp: [[&str; 3]; 85];
match mpt {
MpType::CharMap => mpp = CHAR_MAP,
MpType::SaltMap => mpp = SALT_MAP,
}
for e in &vc {
for s in mpp {
if e == &s[0] {
result.push(s[1]);
println!("{:?}", s[1])
}
}
}
if result.is_empty() {
if result.len() != vc.len() {
Err("No matching characters found")
} else {
Ok(result)
Expand All @@ -24,14 +35,7 @@ mod tests {

#[test]
fn try_char() {
let res = mapper_lvl1(vec!["A", "B", "C"]);
assert_eq!(
res,
Ok(vec![
["A", "Av", "671"],
["B", "bQ", "142"],
["C", "TG", "243"]
])
)
let res = chr_to_mp(vec!["A", "B", "C"], MpType::CharMap);
assert_eq!(res, Ok(vec!["Av", "bQ", "TG"]))
}
}
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::encpt::mapping::mapper::mapper_lvl1;
use crate::encpt::mapping::mapper::*;

pub mod maps {
pub mod first_lvl;
pub mod chars;
pub mod salt;
}
mod shared {
pub mod parse;
Expand All @@ -12,5 +13,5 @@ mod encpt {
}
}
fn main() {
let _ = mapper_lvl1(vec!["A", "B", "C"]);
let _ = chr_to_mp(vec!["A", "B", "C"], MpType::CharMap);
}
File renamed without changes.

0 comments on commit 8666528

Please sign in to comment.