Java加密:Unix标准加密方法 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-20
R, int S, int E0, int E1, int s[]
)
{
int t, u, v;
v = R ^ (R >>> 16);
u = v & E0;
v = v & E1;
u = (u ^ (u << 16)) ^ R ^ s[S];
t = (v ^ (v << 16)) ^ R ^ s[S + 1];
t = (t >>> 4) | (t << 28);
L ^= SPtrans[1][(t ) & 0x3f] |
SPtrans[3][(t >>> 8) & 0x3f] |
SPtrans[5][(t >>> 16) & 0x3f] |
SPtrans[7][(t >>> 24) & 0x3f] |
SPtrans[0][(u ) & 0x3f] |
SPtrans[2][(u >>> 8) & 0x3f] |
SPtrans[4][(u >>> 16) & 0x3f] |
SPtrans[6][(u >>> 24) & 0x3f];
return(L);
}
private static final int [] body(int schedule[], int Eswap0, int Eswap1)
{
int left = 0;
int right = 0;
int t = 0;
for(int j = 0; j < 25; j ++)
{
for(int i = 0; i < ITERATIONS * 2; i += 4)
{
left = D_ENCRYPT(left, right, i, Eswap0, Eswap1,
schedule);
right = D_ENCRYPT(right, left, i + 2, Eswap0, Eswap1,
schedule);
}
t = left;
left = right;
right = t;
}
t = right;
right = (left >>> 1) | (left << 31);
left = (t >>> 1) | (t << 31);
left &= 0xffffffff;
right &= 0xffffffff;
int results[] = new int[2];
PERM_OP(right, left, 1, 0x55555555, results);
right = results[0]; left = results[1];
PERM_OP(left, right, 8, 0x00ff00ff, results);
left = results[0]; right = results[1];
PERM_OP(right, left, 2, 0x33333333, results);
right = results[0]; left = results[1];
PERM_OP(left, right, 16, 0x0000ffff, results);
left = results[0]; right = results[1];
PERM_OP(right, left, 4, 0x0f0f0f0f, results);
right = results[0]; left = results[1];
int out[] = new int[2];
out[0] = left; out[1] = right;
return(out);
}
public synchronized static final String crypt(String salt, String original)
{
while(salt.length() < 2) salt += "A";
StringBuffer buffer = new StringBuffer(" ");
char charZero = salt.charAt(0);
char charOne = salt.charAt(1);
buffer.setCharAt(0, charZero);
buffer.setCharAt(1, charOne);
int Eswap0 = con_salt[(int)charZero];
int Eswap1 = con_salt[(int)charOne] << 4;
byte key[] = new byte[8];
for(int i = 0; i < key.length; i ++) key[i] = (byte)0;
for(int i = 0; i < key.length && i < original.length(); i ++)
{
int iChar = (int)original.charAt(i);
key[i] = (byte)(iChar << 1);
}
int schedule[] = des_set_key(key);
int out[] = body(schedule, Eswap0, Eswap1);
byte b[] = new byte[9];
intToFourBytes(out[0], b, 0);
intToFourBytes(out[1], b, 4);
b[8] = 0;
for(int i = 2, y = 0, u = 0x80; i < 13; i ++)
{
for(int j = 0, c = 0; j < 6; j ++)
{
c <<= 1;
if(((int)b[y] & u) != 0) c |= 1;
u >>>= 1;
if(u == 0)
{
y++;
u = 0x80;
}
buffer.setCharAt(i, (char)cov_2char[c]);
}
}
return(buffer.toString());
}
} |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于Java加密:Unix标准加密方法 - 编程入门网的所有评论