【java首次适应算法代码 java首次适应算法代码怎么写】}
/*
* F, G, H ,I 是4个基本的keyBean函数,在原始的keyBean的C实现中,由于它们是
* 简单的位运算 , 可能出于效率的考虑把它们实现成了宏,在java中,我们把它们 实现成了private方法 , 名字保持了原来C中的 。
*/
private long F(long x, long y, long z) {
return (xy) | ((~x)z);
}
private long G(long x, long y, long z) {
return (xz) | (y(~z));
}
private long H(long x, long y, long z) {
return x ^ y ^ z;
}
private long I(long x, long y, long z) {
return y ^ (x | (~z));
}
/*
* FF,GG,HH和II将调用F,G,H,I进行近一步变换 FF, GG, HH, and II transformations for
* rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent
* recomputation.
*/
private long FF(long a, long b, long c, long d, long x, long s, long ac) {
a += F(b, c, d) + x + ac;
a = ((int) as) | ((int) a(32 - s));
a += b;
return a;
}
private long GG(long a, long b, long c, long d, long x, long s, long ac) {
a += G(b, c, d) + x + ac;
a = ((int) as) | ((int) a(32 - s));
a += b;
return a;
}
private long HH(long a, long b, long c, long d, long x, long s, long ac) {
a += H(b, c, d) + x + ac;
a = ((int) as) | ((int) a(32 - s));
a += b;
return a;
}
private long II(long a, long b, long c, long d, long x, long s, long ac) {
a += I(b, c, d) + x + ac;
a = ((int) as) | ((int) a(32 - s));
a += b;
return a;
}
/*
* keyBeanUpdate是keyBean的主计算过程,inbuf是要变换的字节串,inputlen是长度,这个
* 函数由getkeyBeanofStr调用,调用之前需要调用keyBeaninit,因此把它设计成private的
*/
private void keyBeanUpdate(byte[] inbuf, int inputLen) {
int i, index, partLen;
byte[] block = new byte[64];
index = (int) (count[0]3)0x3F;
// /* Update number of bits */
if ((count[0] += (inputLen3))(inputLen3))
count[1]++;
count[1] += (inputLen29);
partLen = 64 - index;
// Transform as many times as possible.
if (inputLen = partLen) {
keyBeanMemcpy(buffer, inbuf, index, 0, partLen);
keyBeanTransform(buffer);
for (i = partLen; i + 63inputLen; i += 64) {
keyBeanMemcpy(block, inbuf, 0, i, 64);
keyBeanTransform(block);
}
index = 0;
} else
i = 0;
// /* Buffer remaining input */
keyBeanMemcpy(buffer, inbuf, index, i, inputLen - i);
}
/*
* keyBeanFinal整理和填写输出结果
*/
private void keyBeanFinal() {
byte[] bits = new byte[8];
int index, padLen;
// /* Save number of bits */
Encode(bits, count, 8);
// /* Pad out to 56 mod 64.
index = (int) (count[0]3)0x3f;
padLen = (index56) ? (56 - index) : (120 - index);
keyBeanUpdate(PADDING, padLen);
// /* Append length (before padding) */
keyBeanUpdate(bits, 8);
// /* Store state in digest */
Encode(digest, state, 16);
}
/*
* keyBeanMemcpy是一个内部使用的byte数组的块拷贝函数,从input的inpos开始把len长度的
* 字节拷贝到output的outpos位置开始
*/
private void keyBeanMemcpy(byte[] output, byte[] input, int outpos,
int inpos, int len) {
int i;
for (i = 0; ilen; i++)
output[outpos + i] = input[inpos + i];
}
/*
* keyBeanTransform是keyBean核心变换程序,有keyBeanUpdate调用,block是分块的原始字节
*/
private void keyBeanTransform(byte block[]) {
long a = state[0], b = state[1], c = state[2], d = state[3];
long[] x = new long[16];
Decode(x, block, 64);
/* Round 1 */
推荐阅读
- 益智网页小游戏儿童版,网页儿童游戏大全
- 刀剑乱舞ios服如何充值,刀剑乱舞安卓iOS通用吗
- 网络卡怎么接路由器,上网卡接路由器
- linux中单独ps命令,linux怎么用ps
- sub在c语言里宏函数 c语言substring函数用法
- erp和会计信息系统的关系大吗,erp与会计信息系统的关系
- 联通用什么手机看电影免流,联通手机营业厅免流量看电影
- 大班角色扮演游戏课程教案,大班角色扮演游戏设计
- 函数公式python的简单介绍