在此线性搜索代码中,执行了第8行后,它跳到了第13行,而没有执行for循环。
输出: 输入数组的大小 5 输入元素 输入要搜索的元素
代码如下:
import atob from 'atob';
import forge from 'node-forge';
const InitVector = [0x00, ...];
const EncryptionKey = 'Some Encryption Key';
const initKey = Buffer.from(InitVector).toString(); // Changed this to `initKey`
const convertBase64StringToUint8Array = input => {
const data = atob(input);
const array = Uint8Array.from(data, b => b.charCodeAt(0));
return array;
};
const decrypt = cipher => {
const cipherArray = convertBase64StringToUint8Array(cipher);
const key = forge.pkcs5.pbkdf2(EncryptionKey, iv, 1000, 32);
/**
* Added the following
* Note the key size = 48
* This was due to the fact that the C# dictated that
* the IV was 16 bytes, starting at the end of the key.
*/
const keyAndIV = forge.pkcs5.pbkdf2(encryptionKey, initKey, 1000, 32 + 16);
/**
* Therefore, we cut the iv from the new string
*/
const iv = keyAndIV.slice(32, 32 + 16); // 16 bytes
const decipher = forge.cipher.createDecipher(
'AES-CBC',
forge.util.createBuffer(key)
);
decipher.start({ iv });
decipher.update(forge.util.createBuffer(cipherArray, 'raw'));
const result = decipher.finish();
if (result) {
return decipher.output.data;
} else {
return false;
}
};
答案 0 :(得分:4)
由于条件c > n
,您没有进入for循环,请尝试将其更改为c < n
。
for(c=0; c < n; c++)