3. Write a class to encrypt and decrypt a text file. The encryption step is described below:
a. Find N, where N is the length of the longest line in the file, or the number of lines in the file, whichever one is higher.
b. Find M, where M is and the next odd number bigger than or equal to N.
c. Allocate a two dimensional array of characters, of size MxM. Let’s call this array T. Initialize T so that all of its MxM element is a space character.
d. Fill each row of T with the corresponding line in the text file (row 0 filled with characters from the first line, starting from column 1, row 1 filled with characters from the second line, starting from column 1, row 2 filled with characters from the third line, starting from column 1, and so on..).
e. Write the content of T, starting from the center T[X][X], where X = M/2, and moving out in a spiral motion, counter clockwise, heading towards the left direction first, as shown in the diagram below:

T:
T h e
q u i c k
b r o w n
f o x
i s v e r y
h u n g r y
t o n i g h t

Writing order:

Characters written:
“+x+ve+nworosungryr+++kciuqbfihtonight+y++++++++ehT

The + sign are just to show you the number of spaces written, in your program you should write the space character, not write the + sign. Add the capability to decrypt as well. Your program should decrypt the encrypted file, and write the output to a new file, then compare this result with the original unencrypted file (ignore the space character during the comparison).

Recommended Answers

All 3 Replies

And your question is.... ?

Please don't say "write this for me!"

Come on now, folks.

Don't ask us to do your homework for you, and don't try to put a deadline on it. That's REALLY rude.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.