/* java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.math.BigInteger;/** * *

/* * To change this template, choose Tools | Templates * and open the template in the editor. */package test;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.math.BigInteger;/** * *  */public class ElgamaED {    MyElGamal pkc = new MyElGamal(); MyTransformer trfmr;    public byte  encrypt(String fpath,String owner) throws IOException    {        trfmr = pkc.getEncrypter();        File inFile = new File(fpath); int inputLength = (int)(inFile.length()/100 + 1)*100; BufferedInputStream inStrm = new BufferedInputStream( new FileInputStream(inFile)); BufferedOutputStream outStrm = new BufferedOutputStream( new FileOutputStream(“D:”+owner+”.out”)); System.err.println(“Buffer size = ” + inputLength); byte buf = new byteinputLength; System.out.println(“^^^^^^
=====
“+new String(buf)); int nBytes = inStrm.read(buf); System.out.println(”
” + nBytes + ” bytes read”); byte msg = new bytenBytes; System.arraycopy(buf, 0, msg, 0, nBytes); System.out.println(”
=====
“+new String(msg)); byte tmsg = trfmr.transform(msg); System.out.println(“” + tmsg.length + ” bytes produced”);  System.out.println(”
encrypte message
” +new String(tmsg) ); outStrm.write(tmsg); inStrm.close(); outStrm.close();  return tmsg;    }    public String decrypt(String fname,String owner) throws IOException    {               trfmr = pkc.getDecrypter();        File inFile = new File(“D:”+owner+”.out”); int inputLength = (int)(inFile.length()/100 + 1)*100; BufferedInputStream inStrm = new BufferedInputStream( new FileInputStream(inFile)); BufferedOutputStream outStrm = new BufferedOutputStream( new FileOutputStream(“E:”+owner+”1.txt”)); System.err.println(“Buffer size = ” + inputLength); byte buf = new byteinputLength; System.out.println(“^^^^^^
=====
“+new String(buf)); int nBytes = inStrm.read(buf); System.out.println(”
” + nBytes + ” bytes read”); byte msg = new bytenBytes; System.arraycopy(buf, 0, msg, 0, nBytes); System.out.println(”
=====
“+new String(msg)); byte tmsg = trfmr.transform(msg); System.out.println(“” + tmsg.length + ” bytes produced”);  System.out.println(”
encrypte message
” +new String(tmsg) ); outStrm.write(tmsg); inStrm.close(); outStrm.close();  return new String(tmsg);    }}

BACK TO TOP
x

Hi!
I'm Angelica!

Would you like to get a custom essay? How about receiving a customized one?

Check it out