1 29 package Acme.Crypto; 30 31 import java.io.*; 32 33 44 public abstract class StreamCipher extends Cipher 45 { 46 47 public StreamCipher( int keySize ) 49 { 50 super( keySize ); 51 } 52 53 public abstract byte encrypt( byte clearText ); 55 56 public abstract byte decrypt( byte cipherText ); 58 59 public void encrypt( byte[] clearText, byte[] cipherText ) 61 { 62 encrypt( clearText, 0, cipherText, 0, clearText.length ); 63 } 64 65 public void decrypt( byte[] cipherText, byte[] clearText ) 67 { 68 decrypt( cipherText, 0, clearText, 0, cipherText.length ); 69 } 70 71 public void encrypt( byte[] clearText, int clearOff, byte[] cipherText, int cipherOff, int len ) 75 { 76 for ( int i = 0; i < len; ++i ) 77 cipherText[cipherOff + i] = encrypt( clearText[clearOff + i] ); 78 } 79 80 public void decrypt( byte[] cipherText, int cipherOff, byte[] clearText, int clearOff, int len ) 84 { 85 for ( int i = 0; i < len; ++i ) 86 clearText[clearOff + i] = decrypt( cipherText[cipherOff + i] ); 87 } 88 89 } 90 | Popular Tags |