Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Block division in cryptography

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Block division in cryptography

    I have used FileInputStream class but its not working properly to divide the bits into blocks.I will attach the coding,help me out to fix the problem.

    public static void main(String[] args) {
     
    ReadFileExample newclass = new ReadFileExample();
    System.out.println("cryptography");
    File input = new File("D:/java/source.txt");
    File output = new File("D:/java/target.txt");
    byte[] block = new byte[18];
    try {
    FileInputStream fis = new FileInputStream(input);
    FileOutputStream fos = new FileOutputStream(output);
    //CipherOutputStream cos = new CipherOutputStream(fos);
    System.out.println("Total file size to read (in bytes) : "
    + fis.length());
    int i;
    while ((i = fis.read(byte[18]))!= -1) {
    System.out.println(block);
    fos.write(block, 0, i);
    }
    fos.close();
    }
    catch (Exception e)
    {
    System.out.println("invalid");
    }
     
    }}


  2. #2
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Block division in cryptography

    First remove the compilation error from your code.

    System.out.println("Total file size to read (in bytes) : "+fis.length());
    There is no such method like "fis.length()" in FileInputStream class.

    and ,
    while ((i = fis.read(byte[18]))!= -1) {
    System.out.println(block);
    fos.write(block, 0, i);
    }

    Method fis.read(byte[]) take a byte array as a argument and there is no means of passing byte[18] in that. So instead of byte[18] pass block which is an byte array of length 18.

    If you will face any problem then please paste the full error code.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Block division in cryptography

    Also posted at: Block division
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Block division in cryptography

    //this is the code wat v have modifed..we have binary values such as 0's 1's in source.txt...this has to be divided into blocks of 144bit..i mean 18byte..this is our requirement


    import java.io.*;
    import java.lang.*;
    import java.io.File;
    import java.io.FileInputStream;
    public class Ss {



    public static void main(String[] args) throws IOException {





    System.out.println("cryptography");

    File input = new File("D:\\Java\\jdk1.7.0\\bin\\source.txt");

    File output = new File("D:\\Java\\jdk1.7.0\\bin\\target.txt");
    byte[] block = new byte[18];




    try {

    FileInputStream fis = new FileInputStream(input);

    FileOutputStream fos = new FileOutputStream(output);



    int i;
    //String s;

    while ((i = fis.read(block))!=1) {

    System.out.println(block);

    fos.write(block, 0, i);
    byte[] s= Integer.toString(i).getBytes("i");
    System.out.println(s);
    }

    fos.close();

    }
    catch (IndexOutOfBoundsException e) {

    System.out.println("I/O Error:" + e.getMessage());

    }

    finally {



    }

    }

    }

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Block division in cryptography

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    have binary values such as 0's 1's in source.txt
    Everything in a computer and in files is made up of binary values. Are you saying that the file contains values that are not text like what can be typed in from a keyboard?


    has to be divided into blocks of 144bit..i mean 18byte
    Read 18 bytes from the file into an array with 18 elements.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java coding for block division
    By Saranya k in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 7th, 2014, 11:24 AM
  2. Cryptography application
    By hiepa in forum File I/O & Other I/O Streams
    Replies: 15
    Last Post: January 31st, 2014, 12:41 PM
  3. java code related to unicode in cryptography
    By salinii in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 28th, 2014, 09:45 AM
  4. division
    By ericgomez in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 23rd, 2013, 10:15 AM
  5. Division by Zero
    By mael331 in forum Java Theory & Questions
    Replies: 16
    Last Post: December 6th, 2011, 06:13 PM

Tags for this Thread