|
|||||||||
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
Refers to the alphabet used by the plaintext of a particular cipher. |
protected int |
blocksize
Stores the block size for the particular cipher. |
protected Alphabet |
cipherAlphabet
Refers to the alphabet used for the ciphertext of a particular cipher. |
Fields inherited from class hcrypto.cipher.CipherEngine |
alphabetRangeOptions |
Constructor Summary | |
BlockCipher()
|
Method Summary | |
protected char |
decodeShift(char ch,
int k)
This method shifts a character in the alphabet ahead the specified number of characters in the alphabet. |
protected char |
encodeShift(char ch,
int k)
This method shifts a character in the alphabet ahead the specified number of characters in the alphabet. |
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 decrypts 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 void |
engineDecryptFile(java.lang.String inFileName,
java.lang.String outFileName,
java.lang.String encoding)
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 void |
engineEncryptFile(java.lang.String inFileName,
java.lang.String outFileName,
java.lang.String encoding)
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
protected Alphabet cipherAlphabet
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 engineEncryptFile(java.lang.String inFileName, java.lang.String outFileName, java.lang.String encoding) 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 fileencoding
- a String giving the name of the encoding scheme -- e.g., "ISO-2022-JP"protected 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 void engineDecryptFile(java.lang.String inFileName, java.lang.String outFileName, java.lang.String encoding) 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 fileencoding
- a String giving the name of the encoding scheme -- e.g., "ISO-2022-JP"protected java.lang.String engineEncrypt(java.lang.String s) throws java.lang.Exception
engineEncrypt
in class CipherEngine
s
- the String to be encryptedprotected java.lang.String engineDecrypt(java.lang.String s) throws java.lang.Exception
engineDecrypt
in class CipherEngine
s
- the String to be encryptedprotected char encodeShift(char ch, int k) throws java.lang.Exception
ch
- the character to be shifted.k
- the size (number of characters) of the shift.protected char decodeShift(char ch, int k) throws java.lang.Exception
ch
- the character to be shifted.k
- the size (number of characters) of the shift.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |