Skip to content

Commit

Permalink
Update block.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
SymmetricChaos committed Oct 23, 2023
1 parent 42cbe9f commit 9235ee3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions codes/src/other/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct BlockCode {
pub width: usize,
pub alphabet: Vec<char>,
pub symbols: Vec<char>,
pub spaced: bool,
}

impl Default for BlockCode {
Expand All @@ -33,6 +34,7 @@ impl Default for BlockCode {
width: 5,
alphabet: Alphabet::BasicLatin.chars().collect_vec(),
symbols: vec!['0', '1'],
spaced: false,
}
}
}
Expand Down Expand Up @@ -89,12 +91,16 @@ impl Code for BlockCode {
}
out.push(self.num_to_string(n));
}
Ok(out.join(""))
if self.spaced {
Ok(out.join(" "))
} else {
Ok(out.join(""))
}
}

fn decode(&self, text: &str) -> Result<String, CodeError> {
let mut out = String::new();

let text = text.replace(" ", "");
let pows = (0..self.width).rev().cycle();
let mut val = 0;
for (c, p) in text.chars().zip(pows) {
Expand Down

0 comments on commit 9235ee3

Please sign in to comment.