qq_39277162 2018-03-10 03:37 采纳率: 0%
浏览 1116
已结题

公司里要进行一个加密操作用js写不出,求大神指点

这个是公司里用C语言写的一个加密方法
uint8 SeedToKey(uint8 *seed, uint8 length, uint8 *key)

{

uint8 i;

union{
uint8 byte[4];

uint32 word;

}seedlokal;

if (seed[0] == 0 && seed[1] == 0 && seed[2] == 0 && seed[3] == 0 )
{
return 0;
}
else

{

seedlokal.word = ((uint32)seed[0] << 24) + ((uint32)seed[1] << 16) +((uint32)seed[2] << 8) + (uint32)seed[3];

for (i=0; i<35; i++)

{

if (seedlokal.word & 0x80000000)

{

seedlokal.word = seedlokal.word << 1;

seedlokal.word = seedlokal.word ^ mask;

}

else

{

seedlokal.word = seedlokal.word << 1;

}
}

for (i=0; i<length; i++)
{

key[3-i] = seedlokal.byte[i];

}

}

return 1;

}

还有一个是用java翻译过来的
@Override
public JsonMap seedToKey(String param) {
JSONObject jsonobject = JSONObject.fromObject(param);
String originSeeds = jsonobject.containsKey("originSeeds") ? jsonobject.getString("originSeeds") : "";
String type = jsonobject.containsKey("type") ? jsonobject.getString("type") : "";
originSeeds = originSeeds.substring(originSeeds.length()-10, originSeeds.length()-2);
byte[] keys = new byte[4];
keys[0] = (byte) (Integer.valueOf(originSeeds.substring(0, 2),16) & 0xFF);
keys[1] = (byte) (Integer.valueOf(originSeeds.substring(2, 4),16) & 0xFF);
keys[2] = (byte) (Integer.valueOf(originSeeds.substring(4, 6),16) & 0xFF);
keys[3] = (byte) (Integer.valueOf(originSeeds.substring(6),16) & 0xFF);
byte[] returnByte = this.seedToKey(keys,Integer.valueOf(type));
byte b0 = (byte) Integer.parseInt("09", 16);
byte b1 = (byte) Integer.parseInt("C1", 16);
byte b2 = (byte) Integer.parseInt("27", 16);
byte b3 = (byte) Integer.parseInt("02", 16);
byte b4 = returnByte[0];
byte b5 = returnByte[1];
byte b6 = returnByte[2];
byte b7 = returnByte[3];
byte b8 = this.getCheckCode(new byte[]{b0, b1, b2, b3, b4, b5, b6, b7});
byte[] value = new byte[]{b0, b1, b2, b3, b4, b5, b6, b7, b8};
return new JsonMap("success", "0000", bytesToHexString(value));
}

//借操作,还操作的校验位生成
private byte[] sendLease() {
    byte b0 = (byte) Integer.parseInt("05", 16);
    byte b1 = (byte) Integer.parseInt("C3", 16);
    byte b2 = (byte) Integer.parseInt("27", 16);
    byte b3 = (byte) Integer.parseInt("11", 16);
    byte b4 = this.getCheckCode(new byte[]{b0, b1, b2, b3});
    byte[] value = new byte[]{b0, b1, b2, b3, b4};
    return value;

}

//借操作,还操作的校验位生成
private byte[] sendReturn(){
    byte b0 = (byte) Integer.parseInt("06", 16);
    byte b1 = (byte) Integer.parseInt("C3", 16);
    byte b2 = (byte) Integer.parseInt("27", 16);
    byte b3 = (byte) Integer.parseInt("12", 16);
    byte b4 = this.getCheckCode(new byte[]{b0, b1, b2


        请问各位大神用js怎么把这段加密翻译出来 比如说加密a99cd23d  最后算成了c4a1f654
  • 写回答

2条回答

  • threenewbee 2018-03-10 15:52
    关注

    说base64的都是胡扯,你这个明显是异或加密的。两次加密就是解密。

    评论

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch