|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--hcrypto.cipher.CipherEngine | +--hcrypto.cipher.BlockCipher
This abstract class represents a basic block cipher. It provides implementations of methods to encrypt and decrypt files and strings, for the entire range of cipher engines.
Subclasses of this class must implement three methods: engineInit(HistoricalKey), engineEncode(String) and engineDecode(String). Of course, each particular cipher algorithm will implement these methods in its own way.
Traditional character ciphers, such as Caesar, Simple Substitution, Vigenere, and Enigma, can be represented as special cases of a block cipher by setting the blocksize to 1. This should be done in the engineInit() method.
The engineEncrypt() and engineDecrypt() methods also handle padding of strings that are smaller than blocksize. Details on the padding scheme are provided in Alphabet.
The class contains algorithm-independent implementations of the following methods: engineEncrypt(String), engineDecrypt(String), engineEncryptFile(String, String), and engineDecryptFile(String,String).
Field Summary | |
protected Alphabet |
alphabet
Stores a reference to the alphabet used by the particular cipher. |
protected int |
blocksize
Stores the block size for the particular cipher. |
Fields inherited from class hcrypto.cipher.CipherEngine |
alphabetRangeOptions |
Constructor Summary | |
BlockCipher()
|
Method Summary | |
protected abstract java.lang.String |
engineDecode(java.lang.String s)
This abstract method must be implemented in the subclass to perform basic decrypting step for a given cipher algorithm. |
protected java.lang.String |
engineDecrypt(java.lang.String s)
This method encrypts a String, returning a String. |
protected void |
engineDecryptFile(java.lang.String inFileName,
java.lang.String outFileName)
This method decrypts its input file storing the decrypted data in the output file. |
protected abstract java.lang.String |
engineEncode(java.lang.String s)
This abstract method must be implemented in the subclass to perform basic encrypting step for a given cipher algorithm. |
protected java.lang.String |
engineEncrypt(java.lang.String s)
This method encrypts a String, returning a String. |
protected void |
engineEncryptFile(java.lang.String inFileName,
java.lang.String outFileName)
This method encrypts its input file storing the encrypted text in the output file. |
protected abstract void |
engineInit(HistoricalKey key)
This abstract method must be implemented in the subclass to perform initializations required by a given cipher algorithm. |
Methods inherited from class hcrypto.cipher.CipherEngine |
getAlphabetRangeOptions |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int blocksize
protected Alphabet alphabet
Constructor Detail |
public BlockCipher()
Method Detail |
protected abstract void engineInit(HistoricalKey key) throws java.lang.Exception
engineInit
in class CipherEngine
key
- an instance of a HistoricalKey subclass appropriate to
the particular cipher algorithmprotected abstract java.lang.String engineEncode(java.lang.String s) throws java.lang.Exception
protected abstract java.lang.String engineDecode(java.lang.String s) throws java.lang.Exception
protected final void engineEncryptFile(java.lang.String inFileName, java.lang.String outFileName) throws java.lang.Exception
engineEncryptFile
in class CipherEngine
inFileName
- a String giving the name of the input fileoutFileName
- a String giving the name of the output fileprotected final void engineDecryptFile(java.lang.String inFileName, java.lang.String outFileName) throws java.lang.Exception
engineDecryptFile
in class CipherEngine
inFileName
- a String giving the name of the input fileoutFileName
- a String giving the name of the output fileprotected final java.lang.String engineEncrypt(java.lang.String s) throws java.lang.Exception
engineEncrypt
in class CipherEngine
s
- the String to be encryptedprotected final java.lang.String engineDecrypt(java.lang.String s) throws java.lang.Exception
engineDecrypt
in class CipherEngine
s
- the String to be encrypted
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |