分组密码SAFER+的C#实现
2009-02-27 08:18:34 来源:WEB开发网道理很明显,因为这是模256的加法运算,所以只能采取在运算的每一步将部分和结果与0xFF做与(&)操作,从而保证其值介于0-255之间,因而不能采用通常意义上的二维数组乘法来进行处理。
接着进行一个输出变换,代码为:
input[0] = (byte)((input[0] ^ n_LocKeyExpandBox[16 * m_nChipherLen]));/* 此处不能做xFF */
input[2] = (byte)((input[2] + n_LocKeyExpandBox[16 * m_nChipherLen + 1]) & 0xFF);
input[4] = (byte)((input[4] + n_LocKeyExpandBox[16 * m_nChipherLen + 2]) & 0xFF);
input[6] = (byte)((input[6] ^ n_LocKeyExpandBox[16 * m_nChipherLen + 3]) & 0xFF);
input[8] = (byte)((input[8] ^ n_LocKeyExpandBox[16 * m_nChipherLen + 4]) & 0xFF);
input[10] = (byte)((input[10] + n_LocKeyExpandBox[16 * m_nChipherLen + 5]) & 0xFF);
input[12] = (byte)((input[12] + n_LocKeyExpandBox[16 * m_nChipherLen + 6]) & 0xFF);
input[14] = (byte)((input[14] ^ n_LocKeyExpandBox[16 * m_nChipherLen + 7]) & 0xFF);
input[16] = (byte)((input[16] ^ n_LocKeyExpandBox[16 * m_nChipherLen + 8]) & 0xFF);
input[18] = (byte)((input[18] + n_LocKeyExpandBox[16 * m_nChipherLen + 9]) & 0xFF);
input[20] = (byte)((input[20] + n_LocKeyExpandBox[16 * m_nChipherLen + 10]) & 0xFF);
input[22] = (byte)((input[22] ^ n_LocKeyExpandBox[16 * m_nChipherLen + 11]) & 0xFF);
input[24] = (byte)((input[24] ^ n_LocKeyExpandBox[16 * m_nChipherLen + 12]) & 0xFF);
input[26] = (byte)((input[26] + n_LocKeyExpandBox[16 * m_nChipherLen + 13]) & 0xFF);
input[28] = (byte)((input[28] + n_LocKeyExpandBox[16 * m_nChipherLen + 14]) & 0xFF);
input[30] = (byte)((input[30] ^ n_LocKeyExpandBox[16 * m_nChipherLen + 15]) & 0xFF);
更多精彩
赞助商链接