zoukankan      html  css  js  c++  java
  • 字符md5分类查找

    const md5=require('./utils/md5')
    const fs=require('fs-extra');

    //分割符号和字符长度
    const splitCode=',';
    const tagLen=3;
    const dir='tag/';
    fs.ensureDirSync(dir);

    //查找
    function find(s1) {
    const mstr= md5(String(s1))
    const tag=mstr.substring(0,tagLen);
    const tagpath=dir+tag
    if(fs.existsSync(tagpath)) {
    const arr=fs.readFileSync(tagpath).toString().split(splitCode)
    const i=arr.indexOf(s1);
    if(i>-1){
    return [tag,i];
    }else{
    return [tag,-1];
    }
    }
    return [tag,-2]
    }
    //保存字符
    function save(s1) {
    const posArr=find(s1);
    const tagPath=dir+posArr[0]
    if(posArr[1]===-2){
    fs.writeFileSync(tagPath,s1);
    }else if(posArr[1]===-1){
    const arr=fs.readFileSync(tagPath).toString().split(splitCode)
    arr.push(s1);
    fs.writeFileSync(tagPath,arr.join(splitCode))
    }
    }

    //获取id,16进制
    function getId16(s1){
    const arr=find(s1);
    if(arr[1]>-1){
    return arr[0]+arr[1].toString(16)
    }else{
    return -1
    }
    }
    //获取id,10进制
    function getId10(s1) {
    const id16=getId16(s1)
    return parseInt(id16,16)
    }
    //查找id16位置
    function findById16(id16) {
    const tag=id16.substring(0,tagLen);
    const id=parseInt(id16.substr(tagLen-1),16)
    return [tag,id]
    }
    //查找id10位置
    function findById10(id) {
    return findById16(id.toString(16));
    }

    const id10=getId10('caoke1112')
    const id16=getId16('caoke111')


    if(id10!==-1){
    console.log(findById10(id10))
    }
    console.log(id10)
  • 相关阅读:
    CVE-2014-6271 Shellshock 破壳漏洞 复现
    0ctf-ezdoor-复现分析
    phpinfo中敏感信息记录
    未授权访问总结学习
    关于PHP内部类的一些总结学习
    PHP反序列化总结
    SSRF和XSS-filter_var(), preg_match() 和 parse_url()绕过学习
    Java14:你需要知道的新特性
    结构型设计模式
    项目总结
  • 原文地址:https://www.cnblogs.com/caoke/p/11902123.html
Copyright © 2011-2022 走看看