|
@@ -2,151 +2,16 @@
|
|
|
// 库的入口文件统一命名为lib.rs
|
|
|
|
|
|
// 引用模块
|
|
|
-// mod test;
|
|
|
-// mod keygen;
|
|
|
+// mod random_test;
|
|
|
+// mod keygen_test;
|
|
|
+// mod qr_code_test;
|
|
|
|
|
|
// 将其他模块的成员声明为当前模块直接可用的,等同于java的静态引用
|
|
|
// 若省略这句,下面不可以直接使用Random结构体,而需要加上模块名,即test::Random
|
|
|
-// use self::test::Random;
|
|
|
-//
|
|
|
-// use std::thread;
|
|
|
-// use std::sync::mpsc;
|
|
|
-// use std::collections::HashMap;
|
|
|
-// use chrono::prelude::*;
|
|
|
-//
|
|
|
-// use std::io::{stdout, BufWriter};
|
|
|
-// use ferris_says::say;
|
|
|
+// use self::random_test::{test, Random};
|
|
|
|
|
|
fn main() {
|
|
|
- // let stdout = stdout();
|
|
|
- // let out = b"Hello fellow Rustaceans!";
|
|
|
- // let width = 24;
|
|
|
- //
|
|
|
- // let mut writer = BufWriter::new(stdout.lock());
|
|
|
- // say(out, width, &mut writer).unwrap(); // unwrap为rust预定义错误处理模式,正常时返回OK值,错误时panic!
|
|
|
- //
|
|
|
- // let rd = Random { seed: 100 };
|
|
|
- // println!("a random number:{}", rd.next());
|
|
|
- // let id = keygen::next_id();
|
|
|
- // println!("key from keygen:{}", id);
|
|
|
- // println!();
|
|
|
- // test_next_id();
|
|
|
-
|
|
|
- // QRCode
|
|
|
- let arr_first = [
|
|
|
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
|
|
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
|
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
|
|
|
- ];
|
|
|
- let arr_domain = [
|
|
|
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-',
|
|
|
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
|
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
|
|
|
- ];
|
|
|
- for size in 2..47 { // 英文域名长度2到46个字符
|
|
|
- for c in arr_first.iter() {
|
|
|
- walk(format!("{}", c).as_str(), size - 1, &arr_domain)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // OCR
|
|
|
- // let mut lt = leptess::LepTess::new(None, "chi_sim").unwrap();
|
|
|
- // lt.set_image("./tmp/qrcode.png");
|
|
|
- // println!("OCR result:{}", lt.get_utf8_text().unwrap());
|
|
|
-}
|
|
|
-
|
|
|
-fn walk(s: &str, level: i32, arr: &[char]) {
|
|
|
- for c in arr.iter() {
|
|
|
- let new_s = format!("{}{}", s, c);
|
|
|
- if level == 0 {
|
|
|
- let data_http = format!("http://{}.com", new_s);
|
|
|
- qr_code_gen(data_http.as_str());
|
|
|
-
|
|
|
- let data_https = format!("https://{}.com", new_s);
|
|
|
- qr_code_gen(data_https.as_str());
|
|
|
- } else {
|
|
|
- walk(new_s.as_str(), level - 1, arr)
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-fn qr_code_gen(data: &str) {
|
|
|
- //println!("QR code for {}", data);
|
|
|
-
|
|
|
- let out_path = "./tmp";
|
|
|
- let name = base64::encode(data);
|
|
|
-
|
|
|
- let code_m = qrcode::QrCode::new(data).unwrap();
|
|
|
- let image_m = code_m.render::<image::Luma<u8>>().build();
|
|
|
- image_m.save(format!("{}/{}_M.png", out_path, name)).unwrap();
|
|
|
-
|
|
|
- let code_l = qrcode::QrCode::with_error_correction_level(data, qrcode::EcLevel::L).unwrap();
|
|
|
- let image_l = code_l.render::<image::Luma<u8>>().build();
|
|
|
- image_l.save(format!("{}/{}_L.png", out_path, name)).unwrap();
|
|
|
-
|
|
|
- let code_q = qrcode::QrCode::with_error_correction_level(data, qrcode::EcLevel::Q).unwrap();
|
|
|
- let image_q = code_q.render::<image::Luma<u8>>().build();
|
|
|
- image_q.save(format!("{}/{}_Q.png", out_path, name)).unwrap();
|
|
|
-
|
|
|
- let code_h = qrcode::QrCode::with_error_correction_level(data, qrcode::EcLevel::H).unwrap();
|
|
|
- let image_h = code_h.render::<image::Luma<u8>>().build();
|
|
|
- image_h.save(format!("{}/{}_H.png", out_path, name)).unwrap();
|
|
|
+ // random_test::test();
|
|
|
+ // keygen_test::test();
|
|
|
+ // qr_code_test::test(2, 3);
|
|
|
}
|
|
|
-
|
|
|
-// fn test_next_id() {
|
|
|
-// let id_size = 100000;
|
|
|
-//
|
|
|
-// let start_time = Utc::now().timestamp_nanos();
|
|
|
-// let (tx, rx) = mpsc::channel();
|
|
|
-//
|
|
|
-//
|
|
|
-// for _ in 0..id_size {
|
|
|
-// let tx = tx.clone();
|
|
|
-// thread::spawn(move || {
|
|
|
-// let id = keygen::next_id();
|
|
|
-// tx.send(id).unwrap()
|
|
|
-// });
|
|
|
-// };
|
|
|
-//
|
|
|
-// let (tx2, rx2) = mpsc::channel();
|
|
|
-// let tx2 = tx2.clone();
|
|
|
-// let handle = thread::spawn(move || {
|
|
|
-// let mut m: HashMap<u64, i32> = HashMap::new();
|
|
|
-// let mut i = id_size;
|
|
|
-// loop {
|
|
|
-// let id = rx.recv().unwrap();
|
|
|
-// //let mut wrap = wrap.lock().unwrap();
|
|
|
-// if m.contains_key(&id) {
|
|
|
-// let v = *(m.get_mut(&id).unwrap());
|
|
|
-// m.insert(id, v + 1);
|
|
|
-// } else {
|
|
|
-// m.insert(id, 1);
|
|
|
-// }
|
|
|
-// i -= 1;
|
|
|
-// if i == 0 {
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// tx2.send(m).unwrap();
|
|
|
-// });
|
|
|
-//
|
|
|
-// handle.join().expect("The thread being joined has panicked");
|
|
|
-//
|
|
|
-// let m = rx2.recv().unwrap();
|
|
|
-//
|
|
|
-// let end_time = Utc::now().timestamp_nanos();
|
|
|
-// let used_time = end_time - start_time;
|
|
|
-// println!("Id size: {}\nTotal seconds:{}\nAvg nanos per id:{}", m.len(), used_time / 1000000000, (used_time as i64) / (id_size as i64));
|
|
|
-//
|
|
|
-// let mut bad_size = 0;
|
|
|
-// for (_, v) in m.iter() {
|
|
|
-// if *v > 1 {
|
|
|
-// bad_size += 1;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if bad_size > 0 {
|
|
|
-// println!("Not good")
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|