⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cipher.java

📁 JAVA的加密源程序
💻 JAVA
字号:
/*Christoforos Pirillos @ Villanova University - May 1999based on code from the book "Java Network Programming" by Hughes*/package encryption;/**This is a generic superclass of all ciphers; it declares the basicmethods to encipher and decipher data. The class is oriented towardsciphers that encrypt data in blocks, and provides methods that encryptlarge amounts of data by making repeatead calls to the single blockencryption methods.Actual implementations of this class must provide implementations of the blockSize(), encipherBlock(), and decipherBlock() methods*/public abstract class Cipher {/**Encrypts len bytes of the array plain starting from index off, andreturns the encrypted result*/public byte[] encipher (byte[] plain, int off, int len) {	int n = blockSize();	byte[] cipher = new byte[((len + n -1)/n) *n];	int i;	for (i=0; i<len -n +1; i+=n)		encipherBlock (plain, off+i, cipher, i);	if (i<len) {		byte[] last = new byte[n];		System.arraycopy (plain, off+i, last, 0, len -i);		Crypt.fill ((byte) 0x55, last, len-i, n-len+i);		encipherBlock (last, 0, cipher, i);	}	return cipher;}/**Encrypts the entire byte array plain using the encipher() method*/public byte[] encipher (byte[] plain) {	return encipher (plain, 0, plain.length);}/**Decrypts a block of len bytes of encrypted data cipher starting fromindex off, returning the plaintext result. The length of the encrypteddata must be a multiple of the block size. If we provide an alternativeencipher() method we must also override this method.*/public byte[] decipher (byte[] cipher, int off, int len) {	int n=blockSize();	byte[] plain = new byte[len];	for (int i=0; i<len; i += n)		decipherBlock (cipher, off+i, plain, i);	return plain;}/**Decrypts the entire byte array cipher using the decipher() method.*/public byte[] decipher (byte[] cipher) {	return decipher (cipher, 0, cipher.length);}/**Must be implemented by every encryption algorithm, and should indicatethe block size, in bytes, operated on by the algorithm. A block size ofone indicates an algorithm that encrypts one byte at a time.*/public abstract int blockSize();/**Should encrypt one block of data from offset po of byte array plaininto byte array cipher at offset co. The implementation of this methodmust be capable of encrypting data-in-place; i.e. plain and cipher may bethe same array*/public abstract void encipherBlock (byte[] plain, int po, byte[] cipher,int co);/**Should decrypt one block of data from offset co of byte array cipherinto byte array plain at offset po.*/public abstract void decipherBlock (byte[] cipher, int co, byte[] plain,int po);} /* end of class */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -