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 3 of 3

Thread: Code for Decryption

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Code for Decryption

    Hi Guys !

    i had a problem which i have solved but not sure why it works like this
    Import java.io.*; 
    Public class Decrypt{ 	
    Public static void main(String[] args){ 	
    Try { 	
    FileInputStream input= new FileInputStream (new file(“path/filename.enc”)); 	
    FileOutputStream output= new FileOutputStream(new File (“path/file2.txt”)); 	
     
    Boolean eof=false; 	
    int b=-1; 
    int EncryptedValue=0xD397B428; 
    int mulValue=0x41C64E6D; 
    int addValue=0x3039; 
     
    input.read(); 
    input.read();
    input.read();
    input.read();
    input.read();
    input.read();
    input.read();
    input.read();
     
    While(!eof){  
    b=input.read(); 
    if(b==-1){ 
    eof=true; 
    } Else {
    EncryptedValue=EncryptedValue*mulValue; 
    EncryptedValue=Encrypted+addValue; 
    output.write(b^magicValue); 
    System.out.println(integer.toHexString(b));
    }
    } 
    Output.close(); 
    Input.close();
    } 
    Catch(Exception e){ 
    System.out.println(e.getMessage());
    }
    }
    }

    i don't understand why i have to write
     input.read ();
    eight times to correctly decrypt the file?

    can anyone explain??

    Regards,

    Ewa


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Code for Decryption

    Does this program compile correctly?
    And after fixing the code, i commented all the 8 lines (input.read()) and it worked exactly similar as it worked before. I didn't find any problem.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Code for Decryption

    The 8 read() statements read and ignore 8 bytes from the file. What are in those 8 bytes that you can ignore them?
    Do you have a definition of what each byte in the enc file contains?

  4. The Following User Says Thank You to Norm For This Useful Post:

    me_newbie (June 26th, 2012)

Similar Threads

  1. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  2. describe this program code by code ....
    By izzahmed in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2011, 11:03 PM
  3. RSA Decryption with Java.security - Hex to dec to byte array conversion...
    By SeanSeanston in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 15th, 2010, 09:48 AM
  4. Decryption problem
    By hjen in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 20th, 2010, 02:58 AM