S-DES

生成密钥

//S-DES 第一部分 生成密钥
let secretKey = "0111111101";
const p10=[2, 4, 1, 6, 3, 9, 0, 8, 7, 5];
const p8 = [5, 2, 6, 3, 7, 4, 9, 8];

const substituteMaker = (translate) => {
    //生成置换函数
    return (key) => {
        let res = [];
        for (let i = 0; i < translate.length; i++) {
            res.push(key[translate[i]]);
        }
        return res.join('');
    }


}

secretKey = substituteMaker(p10)(secretKey);

const l1 = (key,count=1) => {
    let keyArr = key.split('');
    let l = keyArr.slice(0, 5);//不包括end
    let r = keyArr.slice(5, 10);
    for(let i=0;i<count;i++){
        l.push(l.shift());
        r.push(r.shift());
    }
    return l.concat(r).join('');
}

secretKey = l1(secretKey)



const key1 = substituteMaker(p8)(secretKey);
console.log('key1',key1);

secretKey = l1(secretKey,2)

const key2 = substituteMaker(p8)(secretKey);
console.log('key2',key2);

//key1 01011111
//key2 11111100



//S-DES 第二部分 加密
const cipherText="10100010";

加密演示

http://demo.guohere.com/sdes/

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注