added swap2

pull/1/head
Avril 4 years ago
parent b926ac7c39
commit e6edae7e99
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,7 +1,7 @@
[package] [package]
name = "khash" name = "khash"
description = "Kana hashes" description = "Kana hashes"
version = "1.1.0" version = "1.2.0"
authors = ["Avril <flanchan@cumallover.me>"] authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018" edition = "2018"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"

@ -23,6 +23,17 @@ mod tests {
assert_eq!(kana, "もッちゅゆをヌョ"); assert_eq!(kana, "もッちゅゆをヌョ");
Ok(()) Ok(())
} }
#[test]
fn rng()
{
let input = b"loli";
for _ in 0..100
{
let context = ctx::Context::new(ctx::Algorithm::Sha256, salt::Salt::random().unwrap());
let kana = generate(&context, input).unwrap();
println!("kana: {}", kana);
}
}
} }
pub const BUFFER_SIZE: usize = 4096; pub const BUFFER_SIZE: usize = 4096;

@ -1,5 +1,6 @@
use std::ops::RangeInclusive; use std::ops::RangeInclusive;
/// All valid kana for the digest
pub const KANA: &[char; 92] = &[ pub const KANA: &[char; 92] = &[
'あ', 'い', 'う', 'え', 'お', 'あ', 'い', 'う', 'え', 'お',
'か', 'き', 'く', 'け', 'こ', 'か', 'き', 'く', 'け', 'こ',
@ -19,10 +20,56 @@ pub const KANA: &[char; 92] = &[
'ハ', 'ヒ', 'フ', 'ヘ', 'ホ', 'ハ', 'ヒ', 'フ', 'ヘ', 'ホ',
'マ', 'ミ', 'ム', 'メ', 'モ', 'マ', 'ミ', 'ム', 'メ', 'モ',
'ラ', 'リ', 'ル', 'レ', 'ロ', 'ラ', 'リ', 'ル', 'レ', 'ロ',
'ヤ', 'ユ', 'ヨ', 'ヤ', 'ユ', 'ヨ', 'ワ', 'ン',
'ワ', 'ン', 'ヲ', 'ヲ', //91
]; ];
/// Valid kana for the
pub const KANA_SWAP: &[Option<char>; 92] = &[
None, None, None, None, None, //a
Some('が'), Some('ぎ'), Some('ぐ'), Some('げ'), Some('ご'), //ka
None, None, None, None, None, //sa
Some('だ'), Some('ぢ'), Some('づ'), Some('で'), Some('ど'), //ta
None, None, None, None, None, //na
Some('ば'), Some('び'), Some('ぶ'), Some('べ'), Some('ぼ'), // ha
None, None, None, None, None, //ma
None, None, None, None, None, //ra
None, None, None, None, None, //ya
None, //wo (45)
None, None, None, None, None, //a
Some('ガ'), Some('ギ'), Some('グ'), Some('ゲ'), Some('ゴ'), //ka
None, None, None, None, None, //sa
Some('ダ'), Some('ヂ'), Some('ヅ'), Some('デ'), Some('ド'), //ta
None, None, None, None, None, //na
Some('バ'), Some('ビ'), Some('ブ'), Some('ベ'), Some('ボ'), // ha
None, None, None, None, None, //ma
None, None, None, None, None, //ra
None, None, None, None, None, //ya
None, //wo (91)
];
pub const KANA_SWAP2: &[Option<char>; 92] = &[
None, None, None, None, None, //a
None, None, None, None, None, //ka
None, None, None, None, None, //sa
None, None, None, None, None, //ta
None, None, None, None, None, //na
Some('ぱ'), Some('ぴ'), Some('ぽ'), Some('ぺ'), Some('ぽ'), //ha
None, None, None, None, None, //ma
None, None, None, None, None, //ra
None, None, None, None, None, //ya
None, //wo (45)
None, None, None, None, None, //a
None, None, None, None, None, //ka
None, None, None, None, None, //sa
None, None, None, None, None, //ta
None, None, None, None, None, //na
Some('パ'), Some('ピ'), Some('プ'), Some('ペ'), Some('ポ'), //ha
None, None, None, None, None, //ma
None, None, None, None, None, //ra
None, None, None, None, None, //ya
None, //wo (91)
];
pub const KANA_SIGN: &[RangeInclusive<usize>; 2] = &[ pub const KANA_SIGN: &[RangeInclusive<usize>; 2] = &[
0..=45, 0..=45,
46..=91, 46..=91,

@ -24,7 +24,12 @@ impl Digest {
let range = &map::KANA_SIGN[sign0 as usize]; let range = &map::KANA_SIGN[sign0 as usize];
let kana = &map::KANA[range.clone()]; let kana = &map::KANA[range.clone()];
let oneesan = usize::from(from[0]) % kana.len(); let oneesan = usize::from(from[0]) % kana.len();
d.0 = Some(kana[oneesan]);
d.0 = Some(match map::KANA_SWAP[oneesan] {
Some(swap) if (from[0] & 0x2) == 0x2 => swap,
Some(_) if (from[0] & 0x8) == 0x8 && map::KANA_SWAP2[oneesan].is_some() => map::KANA_SWAP2[oneesan].unwrap(),
_ => kana[oneesan],
});
if from.len() > 1 { if from.len() > 1 {
if let Some(imoutos) = map::sub(range.start()+oneesan) { if let Some(imoutos) = map::sub(range.start()+oneesan) {
if let Some(imouto) = imoutos[usize::from(from[1]) % map::KANA_SUB.len()] if let Some(imouto) = imoutos[usize::from(from[1]) % map::KANA_SUB.len()]
@ -37,33 +42,6 @@ impl Digest {
d.1 = Self::new(&from[..]).0; d.1 = Self::new(&from[..]).0;
} }
d d
// Old
/*let mut d = Self::default();
let oneesan = usize::from(from[0]) % map::KANA.len();
d.0 = Some(map::KANA[oneesan]);
if from[1] > 0 {
if let Some(imoutos) = map::sub(oneesan) {
let one = (usize::from(from[1]) / map::KANA.len()) % 2;
if imoutos.len() > 0 && one > 0{
d.1 = Some(imoutos[usize::from(from[1]) % imoutos.len()]);
return d;
}
}
let from = [from[1], 0];
d.1 = Self::new(&from[..]).0;
}
d*/
/*let oneesan = usize::from(from) % map::KANA.len();
d.0 = Some(map::KANA[oneesan]);
if let Some(imoutos) = map::sub(oneesan) {
if imoutos.len() > 0 {
}
} else {
}
return d;*/
} }
} }

Loading…
Cancel
Save