There are certain generalities that have to be followed in order to create a block cipher. The code you have shown is technically not a block cipher. Generalities such as:
- In a block cipher the message is broken into blocks, each of which is then encrypted (ie like a substitution on very big characters - 64-bits or more)
- A block cipher consists of two paired algorithms, one for encryption, E, and the other for decryption, E−1. Both algorithms accept two inputs: an input block of size n bits and a key of size k bits, yielding an n-bit output block. For any one fixed key, decryption is the inverse function of encryption.
Encryption in block cipher mode (ECB, CBC) uses a specific flow:
- The first thing that a block cipher must do is break the plaintext into equally-sized blocks, usually 8 bytes, for instance the ASCII encoding of
imablock
. - Encrypt the plaintext using a cipher.
- Decrypt the message.
The choice of cipher is implementation dependent.
The point being, while you may have followed the flow for Encryption-Decryption, you program doesn't satisfy the generalities of block ciphers. You need to break your message into blocks to implement a symmetric cipher.
What you have implemented, is simple encryption and not a block cipher.
There are so many references:
- Block Ciphers - Neat and clean explanation for block ciphers and related operations.
- Wikipedia - Block Ciphers - Obvious reference.. :P
Hope it helps. :)