| | |
Encrypting and Decrypting text from file using keyword
![]() |
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
Hi all this is the 2nd exercise I can't seem to figure out how to do.Exercise goes like this :
One method of encryption is this : We pair the letters of the alphabet to the numbers 0-25.
Assuming we have a text "T" and a keyword "K" of "V" letters.
We add the number of the letter we want to encrypt with the number of the first character of the keyword.If the result is beyond the limits of the alphabet (I assume like 35 for example),we substract 26.Repeat the process with the 2nd character of the text and the 2nd character of the keyword until the end of the text.If we run out of keyword letters we start over from the first letter of the keyword.
The program will be able to take 3 parameters
- enc or - dec : choose whether it'll be encryption or decryption
- cipher <word>: the keyword we'll use (10 chars max)
- <file_name> : our file's name (i.e. test.txt)
an example is :
test.txt (contents) : Attack at dawn.
command line : crypto -enc -cipher lemon test.txt
output : lxfopv mh oeib.
test.enc (contents) : lxfopv mh oeib.
command line : crypto -dec -cipher lemon test.enc
output : Attack at dawn.
I have absolutely NO idea how to do this. Any help would be greatly appreciated.
One method of encryption is this : We pair the letters of the alphabet to the numbers 0-25.
Assuming we have a text "T" and a keyword "K" of "V" letters.
We add the number of the letter we want to encrypt with the number of the first character of the keyword.If the result is beyond the limits of the alphabet (I assume like 35 for example),we substract 26.Repeat the process with the 2nd character of the text and the 2nd character of the keyword until the end of the text.If we run out of keyword letters we start over from the first letter of the keyword.
The program will be able to take 3 parameters
- enc or - dec : choose whether it'll be encryption or decryption
- cipher <word>: the keyword we'll use (10 chars max)
- <file_name> : our file's name (i.e. test.txt)
an example is :
test.txt (contents) : Attack at dawn.
command line : crypto -enc -cipher lemon test.txt
output : lxfopv mh oeib.
test.enc (contents) : lxfopv mh oeib.
command line : crypto -dec -cipher lemon test.enc
output : Attack at dawn.
I have absolutely NO idea how to do this. Any help would be greatly appreciated.
Start by writing a program that accepts parameters on the command line and prints them out.
Once that's working, check the parameters to see what they are and output messages for each so you know you are analyzing the parameters correctly.
Then open the file, read it, and display it.
Basically, do a piece at a time...
Once that's working, check the parameters to see what they are and output messages for each so you know you are analyzing the parameters correctly.
Then open the file, read it, and display it.
Basically, do a piece at a time...
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
I'll describe the algorithm in words. It's your job to write the code. You need a string constant that is 257 characters in length. It's value is a character string containing all of the ASCII characters followed by a terminating 0). Call it ASCIITable. As you read each character from "test.txt", add its ascii value to the ascii value of the current letter of your cypher word. Bump the index of the current letter in the cypher word and if you overflow, reset to zero. Use the value obtained by by adding the ascii code for the letter you read and the letter from the cypher as an offset into ASCIITable. The ascii character at that location becomes your output character. By the way, the bytes of ASCIITable do not have to be in any particular order, so long as each byte is unique.
Hoppy
Hoppy
Last edited by hopalongcassidy; Oct 20th, 2007 at 5:25 pm.
•
•
•
•
and if you overflow, reset to zero.
•
•
•
•
If the result is beyond the limits of the alphabet (I assume like 35 for example),we substract 26.
[edit]
•
•
•
•
You need a string constant that is 257 characters in length. It's value is a character string containing all of the ASCII characters followed by a terminating 0).
Last edited by dwks; Oct 20th, 2007 at 5:45 pm.
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
![]() |
Similar Threads
- connect to text file database (Visual Basic 4 / 5 / 6)
- Saving to a file from an array in C ? (C)
- Output in the text file (C)
- Create stats from a text file (Java)
- Store Bluetooth remote address to a text file (C++)
- 10 line text file (Java)
- Read and write to an ASCII Text file (Java)
Other Threads in the C Forum
- Previous Thread: Question about my project
- Next Thread: problem in this code
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






