• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

File encryption / decryption retaining line feeds

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can someone please point me in the right direction. I have been at this all day and am no closer to a solution than I was first thing this morning.

I have written a simple quiz program that reads its information form a csv file. I would like to encrpt the data as the csv file indicates which asnwer is correct.

When I encrypt and decrypt the csv file I am losing any line feeds in the file which messes up the formating of the text in my text areas.

I don't know why perhaps someone would point me in the right direction.

File encryptor:


 
P White
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and this is the decryptor so that you get your csv file back.

 
P White
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found a work around to this now.

I am reading the quiz file and replacing the \r\n with a seldom used character and the \n with another seldom used character saving this file to disk then encrypting.

after decryption I am replacing the characters with \r\n and \n respectively.

Perhaps not the best solution but it is working.
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hope this helps.
I changed the code only slightly, just to extract the decrypt file name.
I added a test program, and the results indicate that both \r and \n were written to and read from the encrypted file.
Suspect that you were using readline to read the decrypted file, and readline does not read the end of line characters. I used read instead, and the end of line characters are in the decryped file.


The output from the test is shown here, and contains both \n\r.


Decrypt: "Line 1: Have a happy day.

" has \n true has \r true
Decrypt: "Line 2: It was snowing this afternoon.

" has \n true has \r true
Decrypt: "Line 3: Will it rain tommorrow.

" has \n true has \r true
Decrypt: "Line 4: It's getting late.

" has \n true has \r true
Decrypt: "" has \n false has \r false

 
P White
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,

Thank you for this information. It will come in very useful for next time.

I very much appreciate your time in helping me.

Thank you

Paul
 
Everybody's invited. Except this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic