快速业务通道

Java加密:Unix标准加密方法 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-20
8, 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A }; private static final int byteToUnsigned(byte b) { int value = (int)b; return(value >= 0 ? value : value + 256); } private static int fourBytesToInt(byte b[], int offset) { int value; value = byteToUnsigned(b[offset++]); value |= (byteToUnsigned(b[offset++]) << 8); value |= (byteToUnsigned(b[offset++]) << 16); value |= (byteToUnsigned(b[offset++]) << 24); return(value); } private static final void intToFourBytes(int iValue, byte b[], int offset) { b[offset++] = (byte)((iValue) & 0xff); b[offset++] = (byte)((iValue >>> 8 ) & 0xff); b[offset++] = (byte)((iValue >>> 16) & 0xff); b[offset++] = (byte)((iValue >>> 24) & 0xff); } private static final void PERM_OP(int a, int b, int n, int m, int results[]) { int t; t = ((a >>> n) ^ b) & m; a ^= t << n; b ^= t; results[0] = a; results[1] = b; } private static final int HPERM_OP(int a, int n, int m) { int t; t = ((a << (16 - n)) ^ a) & m; a = a ^ t ^ (t >>> (16 - n)); return(a); } private static int [] des_set_key(byte key[]) { int schedule[] = new int[ITERATIONS * 2]; int c = fourBytesToInt(key, 0); int d = fourBytesToInt(key, 4); int results[] = new int[2]; PERM_OP(d, c, 4, 0x0f0f0f0f, results); d = results[0]; c = results[1]; c = HPERM_OP(c, -2, 0xcccc0000); d = HPERM_OP(d, -2, 0xcccc0000); PERM_OP(d, c, 1, 0x55555555, results); d = results[0]; c = results[1]; PERM_OP(c, d, 8, 0x00ff00ff, results); c = results[0]; d = results[1]; PERM_OP(d, c, 1, 0x55555555, results); d = results[0]; c = results[1]; d = (((d & 0x000000ff) << 16) | (d & 0x0000ff00) | ((d & 0x00ff0000) >>> 16) | ((c & 0xf0000000) >>> 4)); c &= 0x0fffffff; int s, t; int j = 0; for(int i = 0; i < ITERATIONS; i ++) { if(shifts2[i]) { c = (c >>> 2) | (c << 26); d = (d >>> 2) | (d << 26); } else { c = (c >>> 1) | (c << 27); d = (d >>> 1) | (d << 27); } c &= 0x0fffffff; d &= 0x0fffffff; s = skb[0][ (c ) & 0x3f ]| skb[1][((c >>> 6) & 0x03) | ((c >>> 7) & 0x3c)]| skb[2][((c >>> 13) & 0x0f) | ((c >>> 14) & 0x30)]| skb[3][((c >>> 20) & 0x01) | ((c >>> 21) & 0x06) | ((c >>> 22) & 0x38)]; t = skb[4][ (d ) & 0x3f ]| skb[5][((d >>> 7) & 0x03) | ((d >>> 8) & 0x3c)]| skb[6][ (d >>>15) & 0x3f ]| skb[7][((d >>>21) & 0x0f) | ((d >>> 22) & 0x30)]; schedule[j++] = ((t << 16) | (s & 0x0000ffff)) & 0xffffffff; s = ((s >>> 16) | (t & 0xffff0000)); s = (s << 4) | (s >>> 28); schedule[j++] = s & 0xffffffff; } return(schedule); } private static final int D_ENCRYPT ( int L, int

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号