• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

File encryption / decryption retaining line feeds  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!