- 浏览: 240933 次
- 性别:
- 来自: 广州
-
最新评论
-
Janne:
你好 有源代码?可以发到我的邮箱里学学吗?2731049993 ...
achartengine画出动态折线图的效果 -
anbo724:
我的邮箱 anbo724@gmail.com谢谢@
achartengine画出动态折线图的效果 -
anbo724:
你好 请问有源码没《?谢谢
achartengine画出动态折线图的效果 -
weiday123:
额,觉得这个会不会占堆内存?
AdapterView、Adapter优化 -
wen742538485:
为什么没有呢?权限没加还是发创建了给你删了再想创建?是不允许重 ...
Android中为你的应用程序添加桌面快捷方式
在Java中,java.security.MessageDigest (rt.jar中)已经定义了 MD5 的计算,所以我们只需要简单地调用即可得到 MD5 的128 位整数。然后将此 128 位计 16 个字节转换成 16 进制表示即可。
下面是一个可生成字符串或文件MD5校验码的例子,测试过,可当做工具类直接使用,其中最主要的是getMD5String(String s)和getFileMD5String(File file)两个方法,分别用于生成字符串的md5校验值和生成文件的md5校验值,getFileMD5String_old(File file)方法可删除,不建议使用:
Java代码
package com.why.md5;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
/**
* 默认的密码字符串组合,用来将字节转换成 16 进制表示的字符,apache校验下载的文件的正确性用的就是默认的这个组合
*/
protected static char hexDigits[] = { '0' , '1' , '2' , '3' , '4' , '5' , '6' ,
'7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' };
protected static MessageDigest messagedigest = null ;
static {
try {
messagedigest = MessageDigest.getInstance("MD5" );
} catch (NoSuchAlgorithmException nsaex) {
System.err.println(MD5Util.class .getName()
+ "初始化失败,MessageDigest不支持MD5Util。" );
nsaex.printStackTrace();
}
}
/**
* 生成字符串的md5校验值
*
* @param s
* @return
*/
public static String getMD5String(String s) {
return getMD5String(s.getBytes());
}
/**
* 判断字符串的md5校验码是否与一个已知的md5码相匹配
*
* @param password 要校验的字符串
* @param md5PwdStr 已知的md5校验码
* @return
*/
public static boolean checkPassword(String password, String md5PwdStr) {
String s = getMD5String(password);
return s.equals(md5PwdStr);
}
/**
* 生成文件的md5校验值
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String(File file) throws IOException {
InputStream fis;
fis = new FileInputStream(file);
byte [] buffer = new byte [ 1024 ];
int numRead = 0 ;
while ((numRead = fis.read(buffer)) > 0 ) {
messagedigest.update(buffer, 0 , numRead);
}
fis.close();
return bufferToHex(messagedigest.digest());
}
/**
* JDK1.4中不支持以MappedByteBuffer类型为参数update方法,并且网上有讨论要慎用MappedByteBuffer,
* 原因是当使用 FileChannel.map 方法时,MappedByteBuffer 已经在系统内占用了一个句柄,
* 而使用 FileChannel.close 方法是无法释放这个句柄的,且FileChannel有没有提供类似 unmap 的方法,
* 因此会出现无法删除文件的情况。
*
* 不推荐使用
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String_old(File file) throws IOException {
FileInputStream in = new FileInputStream(file);
FileChannel ch = in.getChannel();
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0 ,
file.length());
messagedigest.update(byteBuffer);
return bufferToHex(messagedigest.digest());
}
public static String getMD5String( byte [] bytes) {
messagedigest.update(bytes);
return bufferToHex(messagedigest.digest());
}
private static String bufferToHex( byte bytes[]) {
return bufferToHex(bytes, 0 , bytes.length);
}
private static String bufferToHex( byte bytes[], int m, int n) {
StringBuffer stringbuffer = new StringBuffer( 2 * n);
int k = m + n;
for ( int l = m; l < k; l++) {
appendHexPair(bytes[l], stringbuffer);
}
return stringbuffer.toString();
}
private static void appendHexPair( byte bt, StringBuffer stringbuffer) {
char c0 = hexDigits[(bt & 0xf0 ) >> 4 ]; // 取字节中高 4 位的数字转换, >>> 为逻辑右移,将符号位一起右移,此处未发现两种符号有何不同
char c1 = hexDigits[bt & 0xf ]; // 取字节中低 4 位的数字转换
stringbuffer.append(c0);
stringbuffer.append(c1);
}
public static void main(String[] args) throws IOException {
long begin = System.currentTimeMillis();
File file = new File( "C:/12345.txt" );
String md5 = getFileMD5String(file);
// String md5 = getMD5String("a");
long end = System.currentTimeMillis();
System.out.println("md5:" + md5 + " time:" + ((end - begin) / 1000 ) + "s" );
}
}
Java代码
package com.why.md5;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
/**
* 默认的密码字符串组合,用来将字节转换成 16 进制表示的字符,apache校验下载的文件的正确性用的就是默认的这个组合
*/
protected static char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
protected static MessageDigest messagedigest = null;
static {
try {
messagedigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException nsaex) {
System.err.println(MD5Util.class.getName()
+ "初始化失败,MessageDigest不支持MD5Util。");
nsaex.printStackTrace();
}
}
/**
* 生成字符串的md5校验值
*
* @param s
* @return
*/
public static String getMD5String(String s) {
return getMD5String(s.getBytes());
}
/**
* 判断字符串的md5校验码是否与一个已知的md5码相匹配
*
* @param password 要校验的字符串
* @param md5PwdStr 已知的md5校验码
* @return
*/
public static boolean checkPassword(String password, String md5PwdStr) {
String s = getMD5String(password);
return s.equals(md5PwdStr);
}
/**
* 生成文件的md5校验值
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String(File file) throws IOException {
InputStream fis;
fis = new FileInputStream(file);
byte[] buffer = new byte[1024];
int numRead = 0;
while ((numRead = fis.read(buffer)) > 0) {
messagedigest.update(buffer, 0, numRead);
}
fis.close();
return bufferToHex(messagedigest.digest());
}
/**
* JDK1.4中不支持以MappedByteBuffer类型为参数update方法,并且网上有讨论要慎用MappedByteBuffer,
* 原因是当使用 FileChannel.map 方法时,MappedByteBuffer 已经在系统内占用了一个句柄,
* 而使用 FileChannel.close 方法是无法释放这个句柄的,且FileChannel有没有提供类似 unmap 的方法,
* 因此会出现无法删除文件的情况。
*
* 不推荐使用
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String_old(File file) throws IOException {
FileInputStream in = new FileInputStream(file);
FileChannel ch = in.getChannel();
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0,
file.length());
messagedigest.update(byteBuffer);
return bufferToHex(messagedigest.digest());
}
public static String getMD5String(byte[] bytes) {
messagedigest.update(bytes);
return bufferToHex(messagedigest.digest());
}
private static String bufferToHex(byte bytes[]) {
return bufferToHex(bytes, 0, bytes.length);
}
private static String bufferToHex(byte bytes[], int m, int n) {
StringBuffer stringbuffer = new StringBuffer(2 * n);
int k = m + n;
for (int l = m; l < k; l++) {
appendHexPair(bytes[l], stringbuffer);
}
return stringbuffer.toString();
}
private static void appendHexPair(byte bt, StringBuffer stringbuffer) {
char c0 = hexDigits[(bt & 0xf0) >> 4];// 取字节中高 4 位的数字转换, >>> 为逻辑右移,将符号位一起右移,此处未发现两种符号有何不同
char c1 = hexDigits[bt & 0xf];// 取字节中低 4 位的数字转换
stringbuffer.append(c0);
stringbuffer.append(c1);
}
public static void main(String[] args) throws IOException {
long begin = System.currentTimeMillis();
File file = new File("C:/12345.txt");
String md5 = getFileMD5String(file);
// String md5 = getMD5String("a");
long end = System.currentTimeMillis();
System.out.println("md5:" + md5 + " time:" + ((end - begin) / 1000) + "s");
}
}
MD5的全称是Message-digest Algorithm 5(信息-摘要算法),用于确保信息传输完整一致。90年代初由MIT的计算机科学实验室和RSA Data Security Inc的Ronald L. Rivest开发出来,经MD2、MD3和MD4发展而来。
任何一个字符串或文件,无论是可执行程序、图像文件、临时文件或者其他任何类型的文件,也不管它体积多大,都有且只有一个独一无二的MD5信息码,并且如果这个文件被修改过,它的MD5码也将随之改变。
Message-Digest泛指字节串(Message)的Hash变换,就是把一个任意长度的字节串变换成一定长的大整数。注意这里说的是“字节串”而不是“字符串”,因为这种变换只与字节的值有关,与字符集或编码方式无关。
MD5用的是哈希函数,在计算机网络中应用较多的不可逆加密算法有RSA公司发明的MD5算法和由美国国家技术标准研究所建议的安全散列算法SHA。
MD5将任意长度的“字节串”变换成一个128bit的大整数,并且它是一个不可逆的字符串变换算法,换句话说就是,即使你看到源程序和算法描述,也无法 将一个MD5的值变换回原始的字符串,从数学原理上说,是因为原始的字符串有无穷多个,这有点象不存在反函数的数学函数。所以,要遇到了md5密码的问 题,比较好的办法是:你可以用这个系统中的md5()函数重新设一个密码,如admin,把生成的一串密码的Hash值覆盖原来的Hash值就行了。
MD5的典型应用是对一段Message(字节串)产生fingerprint(指纹),以防止被“篡改”。举个例子,你将一段话写在一个叫 readme.txt文件中,并对这个readme.txt产生一个MD5的值并记录在案,然后你可以传播这个文件给别人,别人如果修改了文件中的任何内 容,你对这个文件重新计算MD5时就会发现(两个MD5值不相同)。如果再有一个第三方的认证机构,用MD5还可以防止文件作者的“抵赖”,这就是所谓的 数字签名应用。
MD5还广泛用于操作系统的登陆认证上,如Unix、各类BSD系统登录密码、数字签名等诸多方。如在UNIX系统中用户的密码是以 MD5(或其它类似的算法)经Hash运算后存储在文件系统中。当用户登录的时候,系统把用户输入的密码进行MD5 Hash运算,然后再去和保存在文件系统中的MD5值进行比较,进而确定输入的密码是否正确。通过这样的步骤,系统在并不知道用户密码的明码的情况下就可 以确定用户登录系统的合法性。这可以避免用户的密码被具有系统管理员权限的用户知道。
现在被黑客使用最多的一种破译密码的方法就是一种被称为"跑字典"的方法。有两种方法得到字典,一种是日常搜集的用做密码的字符串表,另一种是用排列组合 方法生成的,先用MD5程序计算出这些字典项的MD5值,然后再用目标的MD5值在这个字典中检索。我们假设密码的最大长度为8位字节(8 Bytes),同时密码只能是字母和数字,共26+26+10=62个字符,排列组合出的字典的项数则是 P(62,1)+P(62,2)….+P(62,8),那也已经是一个很天文的数字了,存储这个字典就需要TB级的磁盘阵列,而且这种方法还有一个前提, 就是能获得目标账户的密码MD5值的情况下才可以。这种加密技术被广泛的应用于UNIX系统中,这也是为什么UNIX系统比一般操作系统更为坚固一个重要 原因。
MD5算法
md5算法定义在RFC 1321中,由Ron Rivest(RSA公司)在1992年提出。然而很多学者已经找出了构造md5冲突的方法。这些人中包括中国山东大学的王教授和Hans Dobbertin。所以,单纯使用md5的信息认证模式变得不可靠了。但并不是说md5不能够使用。
MD5以512位分组来处理输入的信息,且每一分组又被划分为16个32位子分组,经过了一系列的处理后,算法的输出由四个32位分组组成,将这四个32位分组级联后将生成一个128位散列值。
MD5算法的计算步骤:
1.通过添加一个1和若干个0的方式,把输入数据长度(按照字节算)变成64m+56
2.添加8个字节到输入数据中去,这样输入数据长度变成了64的倍数
3.把数据划分成块,每块64个字节
4.初始情况下,输出为:
m_state[0] = 0x67452301L;
m_state[1] = 0xefcdab89L;
m_state[2] = 0x98badcfeL;
m_state[3] = 0x10325476L;
5.分别对每块进行计算。输出最后结果。
MD5的算法在RFC1321中实际上已经提供了C的实现,需要注意的是,很多早期的C编译器的int类型是16 bit的,MD5使用了unsigned long int,并认为它是32bit的无符号整数。而在Java中int是32 bit的,long是64 bit的。在MD5的C实现中,使用了大量的位操作。这里需要指出的一点是,尽管Java提供了位操作,由于Java没有unsigned类型,对于右移 位操作多提供了一个无符号右移:>>>,等价于C中的 >> 对于unsigned 数的处理。
下面是一个MD5算法的Java实现:
Java代码
package com.why.md5;
/*******************************************************************************
* MD5_SRC 类实现了RSA Data Security, Inc.在提交给IETF的RFC1321中的MD5_SRC message-digest
* 算法。
******************************************************************************/
public class MD5_SRC {
/*
* 下面这些S11-S44实际上是一个4*4的矩阵,在原始的C实现中是用#define 实现的, 这里把它们实现成为static
* final是表示了只读,且能在同一个进程空间内的多个 Instance间共享
*/
static final int S11 = 7 ;
static final int S12 = 12 ;
static final int S13 = 17 ;
static final int S14 = 22 ;
static final int S21 = 5 ;
static final int S22 = 9 ;
static final int S23 = 14 ;
static final int S24 = 20 ;
static final int S31 = 4 ;
static final int S32 = 11 ;
static final int S33 = 16 ;
static final int S34 = 23 ;
static final int S41 = 6 ;
static final int S42 = 10 ;
static final int S43 = 15 ;
static final int S44 = 21 ;
static final byte [] PADDING = { - 128 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 };
/*
* 下面的三个成员是keyBean计算过程中用到的3个核心数据,在原始的C实现中 被定义到keyBean_CTX结构中
*/
private long [] state = new long [ 4 ]; // state (ABCD)
private long [] count = new long [ 2 ]; // number of bits, modulo 2^64 (lsb first)
private byte [] buffer = new byte [ 64 ]; // input buffer
/*
* digestHexStr是keyBean的唯一一个公共成员,是最新一次计算结果的 16进制ASCII表示.
*/
public String digestHexStr;
/*
* digest,是最新一次计算结果的2进制内部表示,表示128bit的keyBean值.
*/
private byte [] digest = new byte [ 16 ];
/*
* getkeyBeanofStr是类keyBean最主要的公共方法,入口参数是你想要进行keyBean变换的字符串
* 返回的是变换完的结果,这个结果是从公共成员digestHexStr取得的.
*/
public String getkeyBeanofStr(String inbuf) {
keyBeanInit();
keyBeanUpdate(inbuf.getBytes(), inbuf.length());
keyBeanFinal();
digestHexStr = "" ;
for ( int i = 0 ; i < 16 ; i++) {
digestHexStr += byteHEX(digest[i]);
}
return digestHexStr;
}
// 这是keyBean这个类的标准构造函数,JavaBean要求有一个public的并且没有参数的构造函数
public MD5_SRC() {
keyBeanInit();
return ;
}
/* keyBeanInit是一个初始化函数,初始化核心变量,装入标准的幻数 */
private void keyBeanInit() {
count[0 ] = 0L;
count[1 ] = 0L;
// /* Load magic initialization constants.
state[0 ] = 0x67452301L;
state[1 ] = 0xefcdab89L;
state[2 ] = 0x98badcfeL;
state[3 ] = 0x10325476L;
return ;
}
/*
* F, G, H ,I 是4 个基本的keyBean函数,在原始的keyBean的C实现中,由于它们是
* 简单的位运算,可能出于效率的考虑把它们实现成了宏,在java中,我们把它们 实现成了private 方法,名字保持了原来C中的。
*/
private long F( long x, long y, long z) {
return (x & y) | ((~x) & z);
}
private long G( long x, long y, long z) {
return (x & z) | (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 ) a << s) | (( 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 ) a << s) | (( 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 ) a << s) | (( 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 ) a << s) | (( 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 ] += (inputLen << 3 )) < (inputLen << 3 ))
count[1 ]++;
count[1 ] += (inputLen >>> 29 );
partLen = 64 - index;
// Transform as many times as possible.
if (inputLen >= partLen) {
keyBeanMemcpy(buffer, inbuf, index, 0 , partLen);
keyBeanTransform(buffer);
for (i = partLen; i + 63 < inputLen; 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 = (index < 56 ) ? ( 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 ; i < len; 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 */
a = FF(a, b, c, d, x[0 ], S11, 0xd76aa478L); /* 1 */
d = FF(d, a, b, c, x[1 ], S12, 0xe8c7b756L); /* 2 */
c = FF(c, d, a, b, x[2 ], S13, 0x242070dbL); /* 3 */
b = FF(b, c, d, a, x[3 ], S14, 0xc1bdceeeL); /* 4 */
a = FF(a, b, c, d, x[4 ], S11, 0xf57c0fafL); /* 5 */
d = FF(d, a, b, c, x[5 ], S12, 0x4787c62aL); /* 6 */
c = FF(c, d, a, b, x[6 ], S13, 0xa8304613L); /* 7 */
b = FF(b, c, d, a, x[7 ], S14, 0xfd469501L); /* 8 */
a = FF(a, b, c, d, x[8 ], S11, 0x698098d8L); /* 9 */
d = FF(d, a, b, c, x[9 ], S12, 0x8b44f7afL); /* 10 */
c = FF(c, d, a, b, x[10 ], S13, 0xffff5bb1L); /* 11 */
b = FF(b, c, d, a, x[11 ], S14, 0x895cd7beL); /* 12 */
a = FF(a, b, c, d, x[12 ], S11, 0x6b901122L); /* 13 */
d = FF(d, a, b, c, x[13 ], S12, 0xfd987193L); /* 14 */
c = FF(c, d, a, b, x[14 ], S13, 0xa679438eL); /* 15 */
b = FF(b, c, d, a, x[15 ], S14, 0x49b40821L); /* 16 */
/* Round 2 */
a = GG(a, b, c, d, x[1 ], S21, 0xf61e2562L); /* 17 */
d = GG(d, a, b, c, x[6 ], S22, 0xc040b340L); /* 18 */
c = GG(c, d, a, b, x[11 ], S23, 0x265e5a51L); /* 19 */
b = GG(b, c, d, a, x[0 ], S24, 0xe9b6c7aaL); /* 20 */
a = GG(a, b, c, d, x[5 ], S21, 0xd62f105dL); /* 21 */
d = GG(d, a, b, c, x[10 ], S22, 0x2441453L); /* 22 */
c = GG(c, d, a, b, x[15 ], S23, 0xd8a1e681L); /* 23 */
b = GG(b, c, d, a, x[4 ], S24, 0xe7d3fbc8L); /* 24 */
a = GG(a, b, c, d, x[9 ], S21, 0x21e1cde6L); /* 25 */
d = GG(d, a, b, c, x[14 ], S22, 0xc33707d6L); /* 26 */
c = GG(c, d, a, b, x[3 ], S23, 0xf4d50d87L); /* 27 */
b = GG(b, c, d, a, x[8 ], S24, 0x455a14edL); /* 28 */
a = GG(a, b, c, d, x[13 ], S21, 0xa9e3e905L); /* 29 */
d = GG(d, a, b, c, x[2 ], S22, 0xfcefa3f8L); /* 30 */
c = GG(c, d, a, b, x[7 ], S23, 0x676f02d9L); /* 31 */
b = GG(b, c, d, a, x[12 ], S24, 0x8d2a4c8aL); /* 32 */
/* Round 3 */
a = HH(a, b, c, d, x[5 ], S31, 0xfffa3942L); /* 33 */
d = HH(d, a, b, c, x[8 ], S32, 0x8771f681L); /* 34 */
c = HH(c, d, a, b, x[11 ], S33, 0x6d9d6122L); /* 35 */
b = HH(b, c, d, a, x[14 ], S34, 0xfde5380cL); /* 36 */
a = HH(a, b, c, d, x[1 ], S31, 0xa4beea44L); /* 37 */
d = HH(d, a, b, c, x[4 ], S32, 0x4bdecfa9L); /* 38 */
c = HH(c, d, a, b, x[7 ], S33, 0xf6bb4b60L); /* 39 */
b = HH(b, c, d, a, x[10 ], S34, 0xbebfbc70L); /* 40 */
a = HH(a, b, c, d, x[13 ], S31, 0x289b7ec6L); /* 41 */
d = HH(d, a, b, c, x[0 ], S32, 0xeaa127faL); /* 42 */
c = HH(c, d, a, b, x[3 ], S33, 0xd4ef3085L); /* 43 */
b = HH(b, c, d, a, x[6 ], S34, 0x4881d05L); /* 44 */
a = HH(a, b, c, d, x[9 ], S31, 0xd9d4d039L); /* 45 */
d = HH(d, a, b, c, x[12 ], S32, 0xe6db99e5L); /* 46 */
c = HH(c, d, a, b, x[15 ], S33, 0x1fa27cf8L); /* 47 */
b = HH(b, c, d, a, x[2 ], S34, 0xc4ac5665L); /* 48 */
/* Round 4 */
a = II(a, b, c, d, x[0 ], S41, 0xf4292244L); /* 49 */
d = II(d, a, b, c, x[7 ], S42, 0x432aff97L); /* 50 */
c = II(c, d, a, b, x[14 ], S43, 0xab9423a7L); /* 51 */
b = II(b, c, d, a, x[5 ], S44, 0xfc93a039L); /* 52 */
a = II(a, b, c, d, x[12 ], S41, 0x655b59c3L); /* 53 */
d = II(d, a, b, c, x[3 ], S42, 0x8f0ccc92L); /* 54 */
c = II(c, d, a, b, x[10 ], S43, 0xffeff47dL); /* 55 */
b = II(b, c, d, a, x[1 ], S44, 0x85845dd1L); /* 56 */
a = II(a, b, c, d, x[8 ], S41, 0x6fa87e4fL); /* 57 */
d = II(d, a, b, c, x[15 ], S42, 0xfe2ce6e0L); /* 58 */
c = II(c, d, a, b, x[6 ], S43, 0xa3014314L); /* 59 */
b = II(b, c, d, a, x[13 ], S44, 0x4e0811a1L); /* 60 */
a = II(a, b, c, d, x[4 ], S41, 0xf7537e82L); /* 61 */
d = II(d, a, b, c, x[11 ], S42, 0xbd3af235L); /* 62 */
c = II(c, d, a, b, x[2 ], S43, 0x2ad7d2bbL); /* 63 */
b = II(b, c, d, a, x[9 ], S44, 0xeb86d391L); /* 64 */
state[0 ] += a;
state[1 ] += b;
state[2 ] += c;
state[3 ] += d;
}
/*
* Encode把long数组按顺序拆成byte数组,因为java的long类型是64bit的,只拆低32bit,以适应原始C实现的用途
*/
private void Encode( byte [] output, long [] input, int len) {
int i, j;
for (i = 0 , j = 0 ; j < len; i++, j += 4 ) {
output[j] = (byte ) (input[i] & 0xffL);
output[j + 1 ] = ( byte ) ((input[i] >>> 8 ) & 0xffL);
output[j + 2 ] = ( byte ) ((input[i] >>> 16 ) & 0xffL);
output[j + 3 ] = ( byte ) ((input[i] >>> 24 ) & 0xffL);
}
}
/*
* Decode把byte数组按顺序合成成long数组,因为java的long类型是64bit的,
* 只合成低32bit,高32bit清零,以适应原始C实现的用途
*/
private void Decode( long [] output, byte [] input, int len) {
int i, j;
for (i = 0 , j = 0 ; j < len; i++, j += 4 )
output[i] = b2iu(input[j]) | (b2iu(input[j + 1 ]) << 8 )
| (b2iu(input[j + 2 ]) << 16 ) | (b2iu(input[j + 3 ]) << 24 );
return ;
}
/*
* b2iu是我写的一个把byte按照不考虑正负号的原则的”升位”程序,因为java没有unsigned运算
*/
public static long b2iu( byte b) {
return b < 0 ? b & 0x7F + 128 : b;
}
/*
* byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示,
* 因为java中的byte的toString无法实现这一点,我们又没有C语言中的 sprintf(outbuf,"%02X",ib)
*/
public static String byteHEX( byte ib) {
char [] Digit = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' ,
'B' , 'C' , 'D' , 'E' , 'F' };
char [] ob = new char [ 2 ];
ob[0 ] = Digit[(ib >>> 4 ) & 0X0F ];
ob[1 ] = Digit[ib & 0X0F ];
String s = new String(ob);
return s;
}
public static void main(String args[]) {
MD5_SRC m = new MD5_SRC();
System.out.println("keyBean Test suite:" );
System.out.println("keyBean(\"\"):" +m.getkeyBeanofStr( "" ));
System.out.println("keyBean(\"a\"):" +m.getkeyBeanofStr( "a" ));
System.out.println("keyBean(\"abc\"):" +m.getkeyBeanofStr( "abc" ));
System.out.println("keyBean(\"message digest\"):" +m.getkeyBeanofStr( "message digest" ));
System.out.println("keyBean(\"abcdefghijklmnopqrstuvwxyz\"):" +
m.getkeyBeanofStr("abcdefghijklmnopqrstuvwxyz" ));
System.out.println("keyBean(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):" +
m.getkeyBeanofStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ));
}
}
下面是一个可生成字符串或文件MD5校验码的例子,测试过,可当做工具类直接使用,其中最主要的是getMD5String(String s)和getFileMD5String(File file)两个方法,分别用于生成字符串的md5校验值和生成文件的md5校验值,getFileMD5String_old(File file)方法可删除,不建议使用:
Java代码
package com.why.md5;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
/**
* 默认的密码字符串组合,用来将字节转换成 16 进制表示的字符,apache校验下载的文件的正确性用的就是默认的这个组合
*/
protected static char hexDigits[] = { '0' , '1' , '2' , '3' , '4' , '5' , '6' ,
'7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' };
protected static MessageDigest messagedigest = null ;
static {
try {
messagedigest = MessageDigest.getInstance("MD5" );
} catch (NoSuchAlgorithmException nsaex) {
System.err.println(MD5Util.class .getName()
+ "初始化失败,MessageDigest不支持MD5Util。" );
nsaex.printStackTrace();
}
}
/**
* 生成字符串的md5校验值
*
* @param s
* @return
*/
public static String getMD5String(String s) {
return getMD5String(s.getBytes());
}
/**
* 判断字符串的md5校验码是否与一个已知的md5码相匹配
*
* @param password 要校验的字符串
* @param md5PwdStr 已知的md5校验码
* @return
*/
public static boolean checkPassword(String password, String md5PwdStr) {
String s = getMD5String(password);
return s.equals(md5PwdStr);
}
/**
* 生成文件的md5校验值
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String(File file) throws IOException {
InputStream fis;
fis = new FileInputStream(file);
byte [] buffer = new byte [ 1024 ];
int numRead = 0 ;
while ((numRead = fis.read(buffer)) > 0 ) {
messagedigest.update(buffer, 0 , numRead);
}
fis.close();
return bufferToHex(messagedigest.digest());
}
/**
* JDK1.4中不支持以MappedByteBuffer类型为参数update方法,并且网上有讨论要慎用MappedByteBuffer,
* 原因是当使用 FileChannel.map 方法时,MappedByteBuffer 已经在系统内占用了一个句柄,
* 而使用 FileChannel.close 方法是无法释放这个句柄的,且FileChannel有没有提供类似 unmap 的方法,
* 因此会出现无法删除文件的情况。
*
* 不推荐使用
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String_old(File file) throws IOException {
FileInputStream in = new FileInputStream(file);
FileChannel ch = in.getChannel();
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0 ,
file.length());
messagedigest.update(byteBuffer);
return bufferToHex(messagedigest.digest());
}
public static String getMD5String( byte [] bytes) {
messagedigest.update(bytes);
return bufferToHex(messagedigest.digest());
}
private static String bufferToHex( byte bytes[]) {
return bufferToHex(bytes, 0 , bytes.length);
}
private static String bufferToHex( byte bytes[], int m, int n) {
StringBuffer stringbuffer = new StringBuffer( 2 * n);
int k = m + n;
for ( int l = m; l < k; l++) {
appendHexPair(bytes[l], stringbuffer);
}
return stringbuffer.toString();
}
private static void appendHexPair( byte bt, StringBuffer stringbuffer) {
char c0 = hexDigits[(bt & 0xf0 ) >> 4 ]; // 取字节中高 4 位的数字转换, >>> 为逻辑右移,将符号位一起右移,此处未发现两种符号有何不同
char c1 = hexDigits[bt & 0xf ]; // 取字节中低 4 位的数字转换
stringbuffer.append(c0);
stringbuffer.append(c1);
}
public static void main(String[] args) throws IOException {
long begin = System.currentTimeMillis();
File file = new File( "C:/12345.txt" );
String md5 = getFileMD5String(file);
// String md5 = getMD5String("a");
long end = System.currentTimeMillis();
System.out.println("md5:" + md5 + " time:" + ((end - begin) / 1000 ) + "s" );
}
}
Java代码
package com.why.md5;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
/**
* 默认的密码字符串组合,用来将字节转换成 16 进制表示的字符,apache校验下载的文件的正确性用的就是默认的这个组合
*/
protected static char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
protected static MessageDigest messagedigest = null;
static {
try {
messagedigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException nsaex) {
System.err.println(MD5Util.class.getName()
+ "初始化失败,MessageDigest不支持MD5Util。");
nsaex.printStackTrace();
}
}
/**
* 生成字符串的md5校验值
*
* @param s
* @return
*/
public static String getMD5String(String s) {
return getMD5String(s.getBytes());
}
/**
* 判断字符串的md5校验码是否与一个已知的md5码相匹配
*
* @param password 要校验的字符串
* @param md5PwdStr 已知的md5校验码
* @return
*/
public static boolean checkPassword(String password, String md5PwdStr) {
String s = getMD5String(password);
return s.equals(md5PwdStr);
}
/**
* 生成文件的md5校验值
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String(File file) throws IOException {
InputStream fis;
fis = new FileInputStream(file);
byte[] buffer = new byte[1024];
int numRead = 0;
while ((numRead = fis.read(buffer)) > 0) {
messagedigest.update(buffer, 0, numRead);
}
fis.close();
return bufferToHex(messagedigest.digest());
}
/**
* JDK1.4中不支持以MappedByteBuffer类型为参数update方法,并且网上有讨论要慎用MappedByteBuffer,
* 原因是当使用 FileChannel.map 方法时,MappedByteBuffer 已经在系统内占用了一个句柄,
* 而使用 FileChannel.close 方法是无法释放这个句柄的,且FileChannel有没有提供类似 unmap 的方法,
* 因此会出现无法删除文件的情况。
*
* 不推荐使用
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String_old(File file) throws IOException {
FileInputStream in = new FileInputStream(file);
FileChannel ch = in.getChannel();
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0,
file.length());
messagedigest.update(byteBuffer);
return bufferToHex(messagedigest.digest());
}
public static String getMD5String(byte[] bytes) {
messagedigest.update(bytes);
return bufferToHex(messagedigest.digest());
}
private static String bufferToHex(byte bytes[]) {
return bufferToHex(bytes, 0, bytes.length);
}
private static String bufferToHex(byte bytes[], int m, int n) {
StringBuffer stringbuffer = new StringBuffer(2 * n);
int k = m + n;
for (int l = m; l < k; l++) {
appendHexPair(bytes[l], stringbuffer);
}
return stringbuffer.toString();
}
private static void appendHexPair(byte bt, StringBuffer stringbuffer) {
char c0 = hexDigits[(bt & 0xf0) >> 4];// 取字节中高 4 位的数字转换, >>> 为逻辑右移,将符号位一起右移,此处未发现两种符号有何不同
char c1 = hexDigits[bt & 0xf];// 取字节中低 4 位的数字转换
stringbuffer.append(c0);
stringbuffer.append(c1);
}
public static void main(String[] args) throws IOException {
long begin = System.currentTimeMillis();
File file = new File("C:/12345.txt");
String md5 = getFileMD5String(file);
// String md5 = getMD5String("a");
long end = System.currentTimeMillis();
System.out.println("md5:" + md5 + " time:" + ((end - begin) / 1000) + "s");
}
}
MD5的全称是Message-digest Algorithm 5(信息-摘要算法),用于确保信息传输完整一致。90年代初由MIT的计算机科学实验室和RSA Data Security Inc的Ronald L. Rivest开发出来,经MD2、MD3和MD4发展而来。
任何一个字符串或文件,无论是可执行程序、图像文件、临时文件或者其他任何类型的文件,也不管它体积多大,都有且只有一个独一无二的MD5信息码,并且如果这个文件被修改过,它的MD5码也将随之改变。
Message-Digest泛指字节串(Message)的Hash变换,就是把一个任意长度的字节串变换成一定长的大整数。注意这里说的是“字节串”而不是“字符串”,因为这种变换只与字节的值有关,与字符集或编码方式无关。
MD5用的是哈希函数,在计算机网络中应用较多的不可逆加密算法有RSA公司发明的MD5算法和由美国国家技术标准研究所建议的安全散列算法SHA。
MD5将任意长度的“字节串”变换成一个128bit的大整数,并且它是一个不可逆的字符串变换算法,换句话说就是,即使你看到源程序和算法描述,也无法 将一个MD5的值变换回原始的字符串,从数学原理上说,是因为原始的字符串有无穷多个,这有点象不存在反函数的数学函数。所以,要遇到了md5密码的问 题,比较好的办法是:你可以用这个系统中的md5()函数重新设一个密码,如admin,把生成的一串密码的Hash值覆盖原来的Hash值就行了。
MD5的典型应用是对一段Message(字节串)产生fingerprint(指纹),以防止被“篡改”。举个例子,你将一段话写在一个叫 readme.txt文件中,并对这个readme.txt产生一个MD5的值并记录在案,然后你可以传播这个文件给别人,别人如果修改了文件中的任何内 容,你对这个文件重新计算MD5时就会发现(两个MD5值不相同)。如果再有一个第三方的认证机构,用MD5还可以防止文件作者的“抵赖”,这就是所谓的 数字签名应用。
MD5还广泛用于操作系统的登陆认证上,如Unix、各类BSD系统登录密码、数字签名等诸多方。如在UNIX系统中用户的密码是以 MD5(或其它类似的算法)经Hash运算后存储在文件系统中。当用户登录的时候,系统把用户输入的密码进行MD5 Hash运算,然后再去和保存在文件系统中的MD5值进行比较,进而确定输入的密码是否正确。通过这样的步骤,系统在并不知道用户密码的明码的情况下就可 以确定用户登录系统的合法性。这可以避免用户的密码被具有系统管理员权限的用户知道。
现在被黑客使用最多的一种破译密码的方法就是一种被称为"跑字典"的方法。有两种方法得到字典,一种是日常搜集的用做密码的字符串表,另一种是用排列组合 方法生成的,先用MD5程序计算出这些字典项的MD5值,然后再用目标的MD5值在这个字典中检索。我们假设密码的最大长度为8位字节(8 Bytes),同时密码只能是字母和数字,共26+26+10=62个字符,排列组合出的字典的项数则是 P(62,1)+P(62,2)….+P(62,8),那也已经是一个很天文的数字了,存储这个字典就需要TB级的磁盘阵列,而且这种方法还有一个前提, 就是能获得目标账户的密码MD5值的情况下才可以。这种加密技术被广泛的应用于UNIX系统中,这也是为什么UNIX系统比一般操作系统更为坚固一个重要 原因。
MD5算法
md5算法定义在RFC 1321中,由Ron Rivest(RSA公司)在1992年提出。然而很多学者已经找出了构造md5冲突的方法。这些人中包括中国山东大学的王教授和Hans Dobbertin。所以,单纯使用md5的信息认证模式变得不可靠了。但并不是说md5不能够使用。
MD5以512位分组来处理输入的信息,且每一分组又被划分为16个32位子分组,经过了一系列的处理后,算法的输出由四个32位分组组成,将这四个32位分组级联后将生成一个128位散列值。
MD5算法的计算步骤:
1.通过添加一个1和若干个0的方式,把输入数据长度(按照字节算)变成64m+56
2.添加8个字节到输入数据中去,这样输入数据长度变成了64的倍数
3.把数据划分成块,每块64个字节
4.初始情况下,输出为:
m_state[0] = 0x67452301L;
m_state[1] = 0xefcdab89L;
m_state[2] = 0x98badcfeL;
m_state[3] = 0x10325476L;
5.分别对每块进行计算。输出最后结果。
MD5的算法在RFC1321中实际上已经提供了C的实现,需要注意的是,很多早期的C编译器的int类型是16 bit的,MD5使用了unsigned long int,并认为它是32bit的无符号整数。而在Java中int是32 bit的,long是64 bit的。在MD5的C实现中,使用了大量的位操作。这里需要指出的一点是,尽管Java提供了位操作,由于Java没有unsigned类型,对于右移 位操作多提供了一个无符号右移:>>>,等价于C中的 >> 对于unsigned 数的处理。
下面是一个MD5算法的Java实现:
Java代码
package com.why.md5;
/*******************************************************************************
* MD5_SRC 类实现了RSA Data Security, Inc.在提交给IETF的RFC1321中的MD5_SRC message-digest
* 算法。
******************************************************************************/
public class MD5_SRC {
/*
* 下面这些S11-S44实际上是一个4*4的矩阵,在原始的C实现中是用#define 实现的, 这里把它们实现成为static
* final是表示了只读,且能在同一个进程空间内的多个 Instance间共享
*/
static final int S11 = 7 ;
static final int S12 = 12 ;
static final int S13 = 17 ;
static final int S14 = 22 ;
static final int S21 = 5 ;
static final int S22 = 9 ;
static final int S23 = 14 ;
static final int S24 = 20 ;
static final int S31 = 4 ;
static final int S32 = 11 ;
static final int S33 = 16 ;
static final int S34 = 23 ;
static final int S41 = 6 ;
static final int S42 = 10 ;
static final int S43 = 15 ;
static final int S44 = 21 ;
static final byte [] PADDING = { - 128 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 };
/*
* 下面的三个成员是keyBean计算过程中用到的3个核心数据,在原始的C实现中 被定义到keyBean_CTX结构中
*/
private long [] state = new long [ 4 ]; // state (ABCD)
private long [] count = new long [ 2 ]; // number of bits, modulo 2^64 (lsb first)
private byte [] buffer = new byte [ 64 ]; // input buffer
/*
* digestHexStr是keyBean的唯一一个公共成员,是最新一次计算结果的 16进制ASCII表示.
*/
public String digestHexStr;
/*
* digest,是最新一次计算结果的2进制内部表示,表示128bit的keyBean值.
*/
private byte [] digest = new byte [ 16 ];
/*
* getkeyBeanofStr是类keyBean最主要的公共方法,入口参数是你想要进行keyBean变换的字符串
* 返回的是变换完的结果,这个结果是从公共成员digestHexStr取得的.
*/
public String getkeyBeanofStr(String inbuf) {
keyBeanInit();
keyBeanUpdate(inbuf.getBytes(), inbuf.length());
keyBeanFinal();
digestHexStr = "" ;
for ( int i = 0 ; i < 16 ; i++) {
digestHexStr += byteHEX(digest[i]);
}
return digestHexStr;
}
// 这是keyBean这个类的标准构造函数,JavaBean要求有一个public的并且没有参数的构造函数
public MD5_SRC() {
keyBeanInit();
return ;
}
/* keyBeanInit是一个初始化函数,初始化核心变量,装入标准的幻数 */
private void keyBeanInit() {
count[0 ] = 0L;
count[1 ] = 0L;
// /* Load magic initialization constants.
state[0 ] = 0x67452301L;
state[1 ] = 0xefcdab89L;
state[2 ] = 0x98badcfeL;
state[3 ] = 0x10325476L;
return ;
}
/*
* F, G, H ,I 是4 个基本的keyBean函数,在原始的keyBean的C实现中,由于它们是
* 简单的位运算,可能出于效率的考虑把它们实现成了宏,在java中,我们把它们 实现成了private 方法,名字保持了原来C中的。
*/
private long F( long x, long y, long z) {
return (x & y) | ((~x) & z);
}
private long G( long x, long y, long z) {
return (x & z) | (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 ) a << s) | (( 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 ) a << s) | (( 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 ) a << s) | (( 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 ) a << s) | (( 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 ] += (inputLen << 3 )) < (inputLen << 3 ))
count[1 ]++;
count[1 ] += (inputLen >>> 29 );
partLen = 64 - index;
// Transform as many times as possible.
if (inputLen >= partLen) {
keyBeanMemcpy(buffer, inbuf, index, 0 , partLen);
keyBeanTransform(buffer);
for (i = partLen; i + 63 < inputLen; 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 = (index < 56 ) ? ( 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 ; i < len; 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 */
a = FF(a, b, c, d, x[0 ], S11, 0xd76aa478L); /* 1 */
d = FF(d, a, b, c, x[1 ], S12, 0xe8c7b756L); /* 2 */
c = FF(c, d, a, b, x[2 ], S13, 0x242070dbL); /* 3 */
b = FF(b, c, d, a, x[3 ], S14, 0xc1bdceeeL); /* 4 */
a = FF(a, b, c, d, x[4 ], S11, 0xf57c0fafL); /* 5 */
d = FF(d, a, b, c, x[5 ], S12, 0x4787c62aL); /* 6 */
c = FF(c, d, a, b, x[6 ], S13, 0xa8304613L); /* 7 */
b = FF(b, c, d, a, x[7 ], S14, 0xfd469501L); /* 8 */
a = FF(a, b, c, d, x[8 ], S11, 0x698098d8L); /* 9 */
d = FF(d, a, b, c, x[9 ], S12, 0x8b44f7afL); /* 10 */
c = FF(c, d, a, b, x[10 ], S13, 0xffff5bb1L); /* 11 */
b = FF(b, c, d, a, x[11 ], S14, 0x895cd7beL); /* 12 */
a = FF(a, b, c, d, x[12 ], S11, 0x6b901122L); /* 13 */
d = FF(d, a, b, c, x[13 ], S12, 0xfd987193L); /* 14 */
c = FF(c, d, a, b, x[14 ], S13, 0xa679438eL); /* 15 */
b = FF(b, c, d, a, x[15 ], S14, 0x49b40821L); /* 16 */
/* Round 2 */
a = GG(a, b, c, d, x[1 ], S21, 0xf61e2562L); /* 17 */
d = GG(d, a, b, c, x[6 ], S22, 0xc040b340L); /* 18 */
c = GG(c, d, a, b, x[11 ], S23, 0x265e5a51L); /* 19 */
b = GG(b, c, d, a, x[0 ], S24, 0xe9b6c7aaL); /* 20 */
a = GG(a, b, c, d, x[5 ], S21, 0xd62f105dL); /* 21 */
d = GG(d, a, b, c, x[10 ], S22, 0x2441453L); /* 22 */
c = GG(c, d, a, b, x[15 ], S23, 0xd8a1e681L); /* 23 */
b = GG(b, c, d, a, x[4 ], S24, 0xe7d3fbc8L); /* 24 */
a = GG(a, b, c, d, x[9 ], S21, 0x21e1cde6L); /* 25 */
d = GG(d, a, b, c, x[14 ], S22, 0xc33707d6L); /* 26 */
c = GG(c, d, a, b, x[3 ], S23, 0xf4d50d87L); /* 27 */
b = GG(b, c, d, a, x[8 ], S24, 0x455a14edL); /* 28 */
a = GG(a, b, c, d, x[13 ], S21, 0xa9e3e905L); /* 29 */
d = GG(d, a, b, c, x[2 ], S22, 0xfcefa3f8L); /* 30 */
c = GG(c, d, a, b, x[7 ], S23, 0x676f02d9L); /* 31 */
b = GG(b, c, d, a, x[12 ], S24, 0x8d2a4c8aL); /* 32 */
/* Round 3 */
a = HH(a, b, c, d, x[5 ], S31, 0xfffa3942L); /* 33 */
d = HH(d, a, b, c, x[8 ], S32, 0x8771f681L); /* 34 */
c = HH(c, d, a, b, x[11 ], S33, 0x6d9d6122L); /* 35 */
b = HH(b, c, d, a, x[14 ], S34, 0xfde5380cL); /* 36 */
a = HH(a, b, c, d, x[1 ], S31, 0xa4beea44L); /* 37 */
d = HH(d, a, b, c, x[4 ], S32, 0x4bdecfa9L); /* 38 */
c = HH(c, d, a, b, x[7 ], S33, 0xf6bb4b60L); /* 39 */
b = HH(b, c, d, a, x[10 ], S34, 0xbebfbc70L); /* 40 */
a = HH(a, b, c, d, x[13 ], S31, 0x289b7ec6L); /* 41 */
d = HH(d, a, b, c, x[0 ], S32, 0xeaa127faL); /* 42 */
c = HH(c, d, a, b, x[3 ], S33, 0xd4ef3085L); /* 43 */
b = HH(b, c, d, a, x[6 ], S34, 0x4881d05L); /* 44 */
a = HH(a, b, c, d, x[9 ], S31, 0xd9d4d039L); /* 45 */
d = HH(d, a, b, c, x[12 ], S32, 0xe6db99e5L); /* 46 */
c = HH(c, d, a, b, x[15 ], S33, 0x1fa27cf8L); /* 47 */
b = HH(b, c, d, a, x[2 ], S34, 0xc4ac5665L); /* 48 */
/* Round 4 */
a = II(a, b, c, d, x[0 ], S41, 0xf4292244L); /* 49 */
d = II(d, a, b, c, x[7 ], S42, 0x432aff97L); /* 50 */
c = II(c, d, a, b, x[14 ], S43, 0xab9423a7L); /* 51 */
b = II(b, c, d, a, x[5 ], S44, 0xfc93a039L); /* 52 */
a = II(a, b, c, d, x[12 ], S41, 0x655b59c3L); /* 53 */
d = II(d, a, b, c, x[3 ], S42, 0x8f0ccc92L); /* 54 */
c = II(c, d, a, b, x[10 ], S43, 0xffeff47dL); /* 55 */
b = II(b, c, d, a, x[1 ], S44, 0x85845dd1L); /* 56 */
a = II(a, b, c, d, x[8 ], S41, 0x6fa87e4fL); /* 57 */
d = II(d, a, b, c, x[15 ], S42, 0xfe2ce6e0L); /* 58 */
c = II(c, d, a, b, x[6 ], S43, 0xa3014314L); /* 59 */
b = II(b, c, d, a, x[13 ], S44, 0x4e0811a1L); /* 60 */
a = II(a, b, c, d, x[4 ], S41, 0xf7537e82L); /* 61 */
d = II(d, a, b, c, x[11 ], S42, 0xbd3af235L); /* 62 */
c = II(c, d, a, b, x[2 ], S43, 0x2ad7d2bbL); /* 63 */
b = II(b, c, d, a, x[9 ], S44, 0xeb86d391L); /* 64 */
state[0 ] += a;
state[1 ] += b;
state[2 ] += c;
state[3 ] += d;
}
/*
* Encode把long数组按顺序拆成byte数组,因为java的long类型是64bit的,只拆低32bit,以适应原始C实现的用途
*/
private void Encode( byte [] output, long [] input, int len) {
int i, j;
for (i = 0 , j = 0 ; j < len; i++, j += 4 ) {
output[j] = (byte ) (input[i] & 0xffL);
output[j + 1 ] = ( byte ) ((input[i] >>> 8 ) & 0xffL);
output[j + 2 ] = ( byte ) ((input[i] >>> 16 ) & 0xffL);
output[j + 3 ] = ( byte ) ((input[i] >>> 24 ) & 0xffL);
}
}
/*
* Decode把byte数组按顺序合成成long数组,因为java的long类型是64bit的,
* 只合成低32bit,高32bit清零,以适应原始C实现的用途
*/
private void Decode( long [] output, byte [] input, int len) {
int i, j;
for (i = 0 , j = 0 ; j < len; i++, j += 4 )
output[i] = b2iu(input[j]) | (b2iu(input[j + 1 ]) << 8 )
| (b2iu(input[j + 2 ]) << 16 ) | (b2iu(input[j + 3 ]) << 24 );
return ;
}
/*
* b2iu是我写的一个把byte按照不考虑正负号的原则的”升位”程序,因为java没有unsigned运算
*/
public static long b2iu( byte b) {
return b < 0 ? b & 0x7F + 128 : b;
}
/*
* byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示,
* 因为java中的byte的toString无法实现这一点,我们又没有C语言中的 sprintf(outbuf,"%02X",ib)
*/
public static String byteHEX( byte ib) {
char [] Digit = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' ,
'B' , 'C' , 'D' , 'E' , 'F' };
char [] ob = new char [ 2 ];
ob[0 ] = Digit[(ib >>> 4 ) & 0X0F ];
ob[1 ] = Digit[ib & 0X0F ];
String s = new String(ob);
return s;
}
public static void main(String args[]) {
MD5_SRC m = new MD5_SRC();
System.out.println("keyBean Test suite:" );
System.out.println("keyBean(\"\"):" +m.getkeyBeanofStr( "" ));
System.out.println("keyBean(\"a\"):" +m.getkeyBeanofStr( "a" ));
System.out.println("keyBean(\"abc\"):" +m.getkeyBeanofStr( "abc" ));
System.out.println("keyBean(\"message digest\"):" +m.getkeyBeanofStr( "message digest" ));
System.out.println("keyBean(\"abcdefghijklmnopqrstuvwxyz\"):" +
m.getkeyBeanofStr("abcdefghijklmnopqrstuvwxyz" ));
System.out.println("keyBean(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):" +
m.getkeyBeanofStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ));
}
}
发表评论
-
Android Tween动画之RotateAnimation实现图片不停旋转
2012-11-26 22:38 1107本文主要介绍Android中如何使用rotate实现图片不停旋 ... -
Android实现widget定时更新
2012-11-04 20:20 973在开发Android的widget时,第一个需要解决的问题就是 ... -
来自腾讯、谷歌、百度等名企的精选面试五十题
2012-10-07 23:08 952http://www.apkway.com/thread-90 ... -
Android 中Parcelable的作用
2012-09-24 09:53 896android提供了一种新的类型:Parcel。本类被用作封装 ... -
[Android算法] 【eoeAndroid索引】史上最牛最全android开发知识汇总
2012-09-13 09:33 1166http://www.eoeandroid.com/threa ... -
安卓航班推荐70个具有商业实战性的精品Android源码
2012-08-01 00:00 957http://www.apkway.com/thread-58 ... -
Android测试教程汇总
2012-08-02 14:51 1193http://www.apkway.com/thread-67 ... -
Service 与 Thread 的区别
2012-07-26 00:10 935Service 与 Thread 的区别 很多时候,你可能 ... -
android 使用百度地图画轨迹
2012-07-26 00:08 2672import android.content.Context ... -
android百度地图半径画圆
2012-07-26 00:07 2826Java代码 import android.content ... -
Android下获取开机时间
2012-07-26 00:05 1350我的思路是:程序里注册个广播接收器,接收开机启动的广播,当程序 ... -
android 高仿【优酷】圆盘旋转菜单 的实现
2012-07-26 00:03 1412MyAnimation.java Java代码 pack ... -
android 3D 转盘效果(附源码)
2012-07-25 23:41 1856一个仿3D的转盘效果,有倒影特效,旋转图标还可自动放大缩小。由 ... -
Android Thread
2012-07-23 10:47 1108创建新线程的常用方式: 1. 直接使用Thread创建 ... -
Android 通过手说tts中文语音包实现中文朗读
2012-07-22 17:09 1841Android 通过手说tts中文语音包实现中文朗读 ... -
Android 使用HTTPClient调用Web请求(查询手机号码区域)
2012-07-21 00:33 1293Android通过Apache HttpClient调用网上提 ... -
Android+struts2+JSON方式的手机开发
2012-07-21 00:14 1213http://topmanopensource.iteye.c ... -
android九宫格实现
2012-07-21 00:03 1046android九宫格实现,开始以为很复杂,其实只要知道了如何布 ... -
Android ListView圆角实现
2012-07-20 23:59 1243在android上开发项目,如 ... -
Android 将一个Activity转化为View显示出来
2012-07-19 10:27 2108最近看到好多opengl牛人写了些立方体,卷页之类的华丽的代码 ...
相关推荐
利用Simulink实现混合储能系统在直流微网中的下垂控制策略研究:保持直流母线电压稳定的实践与探究,Simulink仿真下的光储直流微网混合储能系统下垂控制策略优化研究(注意版本要求为2021A以上),混合储能系统 光储微网 下垂控制 Simulink仿真 注意版本2021A以上 由光伏发电系统和混合储能系统构成直流微网。 混合储能系统由超级电容器和蓄电池构成,通过控制混合储能系统来维持直流母线电压稳定。 混合储能系统采用下垂控制来实现超级电容和蓄电池的功率分配,蓄电池响应低频量,超级电容响应高频量。 通过改变光照来影响光伏出力,控制混合储能系统保持微网直流母线电压稳定在380V,不受光伏出力变化影响。 ,混合储能系统; 光储微网; 下垂控制; Simulink仿真; 版本2021A; 直流母线电压稳定; 光伏出力变化; 超级电容器; 蓄电池。,2021A+混合储能系统:光储微网下垂控制Simulink仿真研究
内容概要:本文档是针对JavaScript这一跨平台解释型语言的详尽入门手册,首先概述了JavaScript的概念及其重要特性,强调它不仅适用于前端同时也活跃于Node.js的服务器环境之中,从而成为全栈开发的重要技能。紧接着文档阐述了JavaScript的基本语法元素如变量声明、数据类型、运算符及控制结构,让新手理解JavaScript的语法规则,并通过函数与对象操作加深印象。之后介绍了一些常见的实用工具和高级用法,例如模板字符串、解构赋值以及异步编程手段(比如Promise)。对于想要深入探索的应用场景给出了广泛的指引,无论是传统的web开发还是新兴领域的IoT或自动化脚本编写皆有所涉猎。 适合人群:对于那些没有编程背景或有其他编程经验但仍希望了解并擅长运用JavaScript的个人来说非常适合。 使用场景及目标:目的是向初学者提供足够的理论指导和技术实践机会,使他们能够在不同平台上利用JavaScript创造出有意义的作品;不论是想要从事专业软件开发或是业余项目爱好者都能够从中受益。 其他说明:文档还提供了大量权威且有用的外部链接供进一步深造学习,包括但不限于主流的在线课程、权威的技术参考资料及充满活力的支持社区。
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
级联H桥SVG无功补偿系统在不平衡电网中的三层控制策略:电压电流双闭环PI控制、相间与相内电压均衡管理,级联H桥SVG无功补偿系统在不平衡电网中的三层控制策略:电压电流双闭环PI控制、相间与相内电压均衡管理,不平衡电网下的svg无功补偿,级联H桥svg无功补偿statcom,采用三层控制策略。 (1)第一层采用电压电流双闭环pi控制,电压电流正负序分离,电压外环通过产生基波正序有功电流三相所有H桥模块直流侧平均电压恒定,电流内环采用前馈解耦控制; (2)第二层相间电压均衡控制,注入零序电压,控制通过注入零序电压维持相间电压平衡; (3)第三层相内电压均衡控制,使其所有子模块吸收的有功功率与其损耗补,从而保证所有H桥子模块直流侧电压值等于给定值。 有参考资料。 639,核心关键词: 1. 不平衡电网下的SVG无功补偿 2. 级联H桥SVG无功补偿STATCOM 3. 三层控制策略 4. 电压电流双闭环PI控制 5. 电压电流正负序分离 6. 直流侧平均电压恒定 7. 前馈解耦控制 8. 相间电压均衡控制 9. 零序电压注入 10. 相内电压均衡控制 以上十个关键词用分号分隔的格式为:不
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
基于主从博弈的动态定价策略与电动汽车充电管理优化在智能小区的实践(MATLAB+CPLEX gurobi实现),基于主从博弈理论的智能小区电动汽车充电与代理商动态定价策略优化研究,MATLAB代码:基于主从博弈的智能小区代理商定价策略及电动汽车充电管理 关键词:电动汽车 主从博弈 动态定价 智能小区 充放电优化 参考文档:《基于主从博弈的智能小区代理商定价策略及电动汽车充电管理》基本复现 仿真平台:MATLAB+CPLEX gurobi平台 主要内容:代码主要做的是一个电动汽车充电管理和智能小区代理商动态定价的问题,将代理商和车主各自追求利益最大化建模为主从博弈,上层以代理商的充电电价作为优化变量,下层以电动汽车的充电策略作为优化变量,通过优化得出最优电价策略以及动态充电策略。 ,电动汽车; 主从博弈; 动态定价; 智能小区; 充放电优化; MATLAB; CPLEX; gurobi平台。,基于主从博弈的电动汽车充电管理与定价策略优化MATLAB代码实现
基于Matlab语言实现的设计项目 2、适用人群:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业或毕业设计中的部分功能,作为“参考资料”使用。 3、解压说明:本资源需要电脑端使用WinRAR、7zip等解压工具进行解压,没有解压工具的自行百度下载即可。 4、免责声明:本资源作为“参考资料”而不是“定制需求”,代码只能作为参考,不能完全复制照搬。不一定能够满足所有人的需求,需要有一定的基础能够看懂代码,能够自行调试代码并解决报错,能够自行添加功能修改代码。由于作者大厂工作较忙,不提供答疑服务,如不存在资源缺失问题概不负责,谢谢理解。
资源内项目源码是均来自个人的课程设计、毕业设计或者具体项目,代码都测试ok,都是运行成功后才上传资源,答辩评审绝对信服的,拿来就能用。放心下载使用!源码、说明、论文、数据集一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 4、如有侵权请私信博主,感谢支持
Labiew噪音与振动检测模块源码揭秘:傅里叶变换与倍频程技术应用于实际项目,LabVIEW平台噪声与振动检测模块源码解析:基于傅里叶变换与倍频程原理的实用功能模块,已成功应用于实际项目,虚拟产品退换政策严谨执行,Labiew噪音与振动检测模块源码,改功能模块已运用到实际项目,原理是利用傅里叶变和倍频程实现的,产品一旦发概不 。 需要的可以联系哟 ,Labiew源码; 噪音与振动检测模块; 傅里叶变换; 倍频程; 实际项目运用,Labiew傅里叶变换倍频程噪音振动检测模块源码
基于Comsol多物理场仿真的光伏集热器异形体建模技术研究,探索comsol多物理场仿真技术:光伏集热器异形体建模应用,comsol多物理场仿真,光伏集热器,异形体建模 ,comsol多物理场仿真; 光伏集热器仿真; 异形体建模,Comsol多物理场仿真在光伏集热器及异形体建模中的应用
器官3D分割-基于WinForm框架开发的医学影像系统源码+sln+演示视频(毕设基于c#和python开发).zip 【项目简单介绍】 主要功能 肺炎诊断 器官 3D 分割 该系统具备肺炎诊断和器官 3D 分割的功能,并模仿了罗万科技的系统界面风格。 python和c#开发实现
MATLAB可以用于开发水果识别系统。这种系统通常利用机器学习和图像处理技术,对输入的水果图像进行特征提取和分类识别。以下是开发水果识别系统的一般步骤: 1. 数据收集:收集包含各种水果类别的图像数据集。 2. 数据预处理:对图像进行预处理,包括裁剪、缩放、灰度化等操作。 3. 特征提取:从每个水果图像中提取特征,例如颜色直方图、纹理特征、形状特征等。 4. 数据标记:为每个图像标记水果类别,形成训练集和测试集。 5. 模型训练:使用机器学习算法(如支持向量机、卷积神经网络等)对训练集进行训练,建立水果识别模型。 6. 模型测试:使用测试集对模型进行测试和评估,调整模型超参数以提高准确率。 7. 系统集成:将训练好的模型集成到MATLAB应用程序中,实现水果识别功能。 8. 用户界面设计:设计用户友好的界面,以便用户上传水果图像并查看识别结果。 MATLAB提供了丰富的图像处理工具箱和机器学习工具箱,可以帮助开发者快速构建水果识别系统。通过结合这些工具箱,可以实现水果的快速、准确识别。
COMSOL声子晶体仿真研究:一维至三维能带与带隙分析及色散曲线弹性波声波分析,声子晶体仿真:COMSOL代做能带图、带隙图及弹性波、声波分析与优化设计,COMSOL代做 声子晶体仿真,一维,二维,三维能带图,带隙图,色散曲线,弹性波,声波。 ,COMSOL代做;声子晶体仿真;一维/二维/三维能带图;带隙图;色散曲线;弹性波仿真;声波分析,COMSOL声子晶体仿真专家:一至三维声波模拟及能带图绘制
Matlab Simulink仿真探究Flyback反激式开关电源性能表现与优化策略,Matlab Simulink仿真探究Flyback反激式开关电源的工作机制,Matlab Simulimk仿真,Flyback反激式开关电源仿真 ,Matlab; Simulink仿真; Flyback反激式; 开关电源仿真,Matlab Simulink在Flyback反激式开关电源仿真中的应用
陪读租房系统(源码+数据库+论文+ppt)java开发springboot框架javaweb,可做计算机毕业设计或课程设计 【功能需求】 本系统有三个角色:管理员、租客和房主,要求具备以下功能: (a) 管理员;管理员使用本系统涉到的功能主要有:首页、个人中心、租客管理、房主管理、房源信息管理、房源类型管理、教育书籍管理、文章分类管理、租房信息管理、合同信息管理、在线咨询管理、咨阅回复管理、教育论坛、系统管理等功能。 (b) 租客;进入前台系统可以实现首页、房源信息、教育书籍、教育论坛、公告信息、后台管理等功能进行操作。 (C) 房主;进入系统可以实现首页、个人中心、房源信息管理、租房信息管理、合同信息管理、在线咨询管理、咨询回复管理等功能进行操作。 【环境需要】 1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.数据库:MySql 5.7/8.0等版本均可; 【购买须知】 本源码项目经过严格的调试,项目已确保无误,可直接用于课程实训或毕业设计提交。里面都有配套的运行环境软件,讲解视频,部署视频教程,一应俱全,可以自己按照教程导入运行。附有论文参考,使学习者能够快速掌握系统设计和实现的核心技术。
vue3的一些语法以及知识点
1、文件内容:libicu-doc-50.2-4.el7_7.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/libicu-doc-50.2-4.el7_7.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
水果销售商城(源码+数据库+论文+ppt)java开发springboot框架javaweb,可做计算机毕业设计或课程设计 【功能需求】 水果购物网站用户可以注册登录,在首页开通会员卡,查看水果,购买水果,查看水果信息,以及个人中心修改个人资料,在自己的后台查看自己的购买记录等。 水果购物网站管理员功能:个人中心管理,用户管理,会员管理,会员卡管理,开通会员记录管理,积分管理,水果管理,购买水果订单管理,积分兑换管理,积分兑换记录管理,加积分记录管理,减积分记录管理。 【环境需要】 1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.数据库:MySql 5.7/8.0等版本均可; 【购买须知】 本源码项目经过严格的调试,项目已确保无误,可直接用于课程实训或毕业设计提交。里面都有配套的运行环境软件,讲解视频,部署视频教程,一应俱全,可以自己按照教程导入运行。附有论文参考,使学习者能够快速掌握系统设计和实现的核心技术。
基于Matlab的双输入深度学习模型构建指南:处理序列与图像数据的创新性应用,Matlab双输入深度学习模型搭建指南:如何处理两种输入数据并实现创新与优势,Matlab搭建双输入深度学习模型,双输入网络。 相比普通的单输入网络,双输入网络能处理两种输入数据,在科研上也更具有优势和创新性。 如何用Matlab搭建双输入网络也是困扰本人很长时间的一个问题,现已弄明白。 注意,需要Matlab 2022b及以上版本,以下版本估计是都不行。 本程序是两个输入全为一维序列的情况(第二个输入序列是第一个输入序列的特征值,或者变后的序列)。 也可改为两边输入都是图像,或者一边输入图像,一边输入图像的一维特征序列。 本程序工作如下: 1、加载数据,两种输入数据一一对应,第二个数据是第一个数据做FFT之后的序列,属于一个类别。 两种数据样本数相等,序列长度不相等。 2、搭建双输入网络,此网络一边是CNN-LSTM,一边是CNN。 3、训练。 4、测试,输出准确率。 注:程序可直接运行,包教会和调通。 可以有偿修改为两边输入都是图像,或一边输入图像一边输入序列的模型。 可有偿替数据,调通程序。 程序注释详
包含十大管理49个过程组的输入与输出和解释,还有EVA铮值管理的公式汇总和解释