use rand::Rng;
use clap::{Command, Arg};
fn hash1(a: &str) -> u32 {
let mut num: u32 = 0;
for c in a.chars() {
num = num.wrapping_mul(43) + c as u32;
}
num
}
fn hash2(a: &str) -> u32 {
let mut num: u32 = 0;
for c in a.chars() {
num = (num << 4) + c as u32;
let num2 = num & 0xF000_0000;
if num2 != 0 {
num ^= num2 >> 24;
num ^= num2;
}
}
num
}
fn get_license(email: &str) -> String {
let alpha_numeric = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
let num = ((hash1(email) as u64) << 32) + hash2(email) as u64;
let mut license = String::new();
for i in 0..12 {
let index = ((num >> (64 - (i + 1) * 5)) & 31) as usize;
license.push(alpha_numeric.chars().nth(index).unwrap());
}
let mut rng = rand::thread_rng();
let mut text = String::new();
for i in 0..192 {
if i == 172 {
text = format!("{}{}", &text[..160], &license);
}
text.push(alpha_numeric.chars().nth(rng.gen_range(0..alpha_numeric.len())).unwrap());
}
text
}
fn main() {
let args = Command::new("listary")
.version("1.0")
.author("Mr.D <[email protected]>")
.about("Listary 6.X 注册机")
.arg(
Arg::new("email")
.short('e')
.long("email")
)
.get_matches();
let email = args.get_one::<String>("email").expect("required");
println!("{}", listarykeygen::get_license(email));
}
using System;
public class Program {
private static uint hash1(string a)
{
uint num = 0U;
foreach (char c in a)
{
num = 43U * num + (uint)c;
}
return num;
}
private static uint hash2(string a)
{
uint num = 0U;
foreach (char c in a)
{
num = (num << 4) + (uint)c;
uint num2 = num & 4026531840U;
if (num2 != 0U)
{
num ^= num2 >> 24;
num ^= num2;
}
}
return num;
}
public static string getLicense(string email)
{
string ALPHA_NUMERIC = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
ulong num = ((ulong)hash1(email) << 32) + (ulong)hash2(email);
string license = "";
for (int i = 0; i < 12; i++)
{
int index = (int)(num >> 64 - (i + 1) * 5) & 31;
license += ALPHA_NUMERIC[index];
}
Random random = new Random();
string text = "";
for (int i = 0; i < 192; i++)
{
if (i == 172)
{
text = text.Substring(0, 160) + license;
}
text += ALPHA_NUMERIC[random.Next(0, ALPHA_NUMERIC.Length)];
}
return text;
}
public static void Main()
{
string email = "[email protected]";
string license = getLicense(email);
Console.WriteLine(license);
}
}
三、网友写的Python版注册机
3.1、安装numpy库
pip install numpy
3.2、新建一个listarykeygen.py,写入以下代码
import numpy as np
import random
def hash1(a: str) -> np.uint32:
num = np.uint32(0)
for c in a:
num = np.uint32(43) * num + np.uint32(ord(c))
return num
def hash2(a: str) -> np.uint32:
num = np.uint32(0)
for c in a:
num = (num << np.uint32(4)) + np.uint32(ord(c))
num2 = num & np.uint32(4026531840)
if num2 != np.uint32(0):
num ^= num2 >> np.uint32(24)
num ^= num2
return num
def getLicense(email: str) -> str:
ALPHA_NUMERIC = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"
num = np.uint64(hash1(email)) << np.uint64(32) | np.uint64(hash2(email))
license = ""
for i in range(12):
index = int((num >> np.uint64(64 - (i + 1) * 5)) & np.uint64(31))
license += ALPHA_NUMERIC[index]
random.seed()
text = ""
for i in range(192):
if i == 172:
text = text[:160] + license
text += ALPHA_NUMERIC[np.random.randint(0, len(ALPHA_NUMERIC))]
return text
email = "[email protected]"
license = getLicense(email)
print(license)