Fix bink1998 verify

This commit is contained in:
Alex Page 2023-06-19 02:49:46 -04:00
parent 3993cafa35
commit 3057f1bc95
2 changed files with 10 additions and 13 deletions

View file

@ -9,7 +9,7 @@ const P_CHARSET: [char; 24] = [
const PK_LENGTH: usize = 25;
pub fn unbase24(cd_key: &str) -> Vec<u8> {
pub fn base24_decode(cd_key: &str) -> Vec<u8> {
let p_decoded_key: Vec<u8> = cd_key
.chars()
.filter_map(|c| P_CHARSET.iter().position(|&x| x == c).map(|i| i as u8))
@ -25,7 +25,7 @@ pub fn unbase24(cd_key: &str) -> Vec<u8> {
y.to_vec()
}
pub fn base24(byte_seq: &[u8]) -> String {
pub fn base24_encode(byte_seq: &[u8]) -> String {
let mut z = BigNum::from_slice(byte_seq).unwrap();
let mut out: VecDeque<char> = VecDeque::new();
(0..=24).for_each(|_| out.push_front(P_CHARSET[z.div_word(24).unwrap() as usize]));
@ -37,9 +37,9 @@ mod tests {
#[test]
fn test_base24() {
let input = "JTW3TJ7PFJ7V9CCMX84V9PFT8";
let unbase24 = super::unbase24(input);
let unbase24 = super::base24_decode(input);
println!("{:?}", unbase24);
let base24 = super::base24(&unbase24);
let base24 = super::base24_encode(&unbase24);
println!("{}", base24);
assert_eq!(input, base24);
}