help me write this c program that is a encrypting / decrypting utility Requireme
ID: 3878835 • Letter: H
Question
help me write this c program that is a encrypting / decrypting utility
Requirements
1. The utility needs to be called cryptoMagic and needs to be written in C
a. The utility has 2 command-line switches – they are –encrypt and –decrypt
b. If none of these switches is specified, then –encrypt is assumed
c. The utility also takes the name of an ASCII input file to encrypt/decrypt as an argument
d. For example: cryptoMagic –encrypt myFile.txt
will encrypt the contents of the myFile.txt file
cryptoMagic myFile.txt
will encrypt the contents of the myFile.txt file
cryptoMagic –decrypt myFile.crp
will decrypt the contents of the myFile.crp file
2. When the utility is asked to –encrypt an ASCII file, it will take the input filename and produce the encrypted file with the same base filename and an .crp file extension
a. For example: cryptoMagic –encrypt myFile.txt
will produce an encrypted file called myFile.crp
3. When the utility is asked to –decrypt an encrypted file, it will take the input filename and produce the decrypted file with the same base filename and an .txt File extension
a. For example: cryptoMagic –decrypt myFile.crp
will produce a decrypted file called myFile.txt
4. It should be noted that the input file can have any file extension. When asked to encrypt, you need to replace the existing file extension (if any) with .TXT. Similarly when asked to decrypt, you need to replace the existing file extension (if any) with .CRP
5. Each line (up to and including the carriage return (noted as <CR> below)) in the unencrypted ASCII file is guaranteed of being less than 120 characters. While processing the input ASCII file you need to process one line at a time. Continue to process the input file until you reach the end of the file.
a. Please note that it is not guaranteed that each line actually ends in a carriage return ... how will you handle that?
6. The encryption scheme is applied to each character in the line:
a. If the character is a <tab> (ASCII value 9) then simply transform it into the output character sequence TT
b. The carriage return characters are not to be encrypted– they are left as is in the resultant output file (the <CR> in the example below is meant for illustration only – do not output “<CR>”)
c. If is not a tab or a carriage return character, then apply the encryption scheme in steps d through f below
d. Take the ASCII code for the input character and subtract a value of 16 from it. Let’s call this resultant value “outChar”
e. If the resulting outChar value is less than 32, then another step must be taken:
outChar = (outChar – 32)+ 144
f. You need to write the ASCII value of the new encrypted character (i.e. outChar) to the destination file as a 2 digit hexadecimal value. Note that this will effectively double the length of the input line in terms of size ...
For example – if the input (unencrypted) file is:
Hello There how are you? <CR>
My name is Sean Clarke. <tab> I like software! <CR>
Then the encrypted file is:
38555C5C5F80445855625580585F678051625580695F652F<CR>
3D69805E515D55805963804355515E80335C51625B558ETT39805C595B5580635F56646751625581
<CR>
7. Each line (up to an including the carriage return (if it exists)) in the encrypted ASCII file is guaranteed of being less than 255 characters. Remember - while processing the input ASCII file you need to process one line at a time.
8. The decryption scheme is applied to each pair of characters in the input line:
a. You need to see if the pair of characters you are processing is the sequence
TT – if so, then simply transform this pair of characters into a <tab> character (ASCII value 9) in the output file.
b. If the pair of characters is not the sequence TT, then translate the first character of the pair by multiplying its face value by 16. Remember that hex values of A through F take on the face values of 10 through 15. Then add the face value of the second character in the pair. Let’s call the resulting value “outChar”. For example:
i. Reading the pair of characters “38” from the encrypted file will translate into an outChar value of 56 decimal.
ii. Reading the pair of characters “5C” from the encrypted file will translate into an outChar value of 92 decimal.
c.Now you need to add 16 to outChar.
d. If the resulting outChar value is greater than 127, then another step must be taken: outChar = (outChar - 144) + 32
e. The outChar value now contains the decrypted ASCII code for the character that you have just decoded. So take this decrypted character value (i.e. outChar) and write it to the destination file as a character.
f. The carriage return characters are not to be decrypted – they are left as is in the resultant file.
For example – if the input (encrypted) file is:
4458596380555E5362696064595F5E80635358555D55805963806062556464698067555962548E<CR>
39635E87648059642F812F<CR>
Then the decrypted file is: This encryption scheme is pretty weird. <CR> Isn't it?!? <CR>
9.It is expected that your cryptoMagic utility has been tested (perhaps by using the above examples) as well as with any other encrypted / decrypted examples you can think of. Don’t forget about the extreme / boundary test cases!
10. It is expected that your cryptoMagic utility has been designed using modular techniques (i.e. the program has been written using functions that you’ve created).
a. The solution must have at least 2 source files and 1 include file
b. There should be no debugging messages present in your final submitted utility
11. Your solution structure must include a makefile and also follow the recommended Linux development directory structure as outlined in the Linux-Development-Project-Code-Structure document
Explanation / Answer
The cipher.exe utility is included with Microsoft’s most recent NT-based operating systems. It allows you to do the same tasks—encrypt and decrypt—that you can do through the GUI, but also allows you to do much more—all through the command line. Administrators and power users can take advantage of the cipher tool’s power to gather encryption information and more quickly perform encryption tasks.
This Daily Drill Down will introduce you to the cipher tool and walk you through the steps of using its various switches.
Why a command line encryption tool?
What’s the need for a command line encryption tool if it’s so easy to encrypt and decrypt files using the GUI (other than the fact that some of us just like the character-based interface)? While encryption and decryption are easy attributes to set through a file or folder’s property sheet, there are other encryption-related tasks that are difficult (or impossible) to accomplish through the GUI.
For example, what if a user wants to create a new file encryption key? You might think you could generate a new key pair by requesting a new EFS certificate. You would do this by invoking the Certificate Request Wizard via the Certificates MMC (if you’re in an Active Directory domain) or via the certification authority’s Web page. But the problem with this method is that the file encryption key that is generated by EFS is wrapped with the user’s public key during the encryption process. As a workaround, the cipher tool allows you to create a new encryption key by typing cipher /k.
What if you want to encrypt files that are already encrypted? There’s no way to do that through the graphical interface; you must first decrypt the file before you’re allowed to change its attribute back to encrypted. With the cipher tool, you can force encryption on all files and folders, including those that are already encrypted.
The cipher tool also can be used to permanently overwrite deleted data on a disk, in a fashion similar to that of “disk wiping” tools such as CyberScrub and Paragon Disk Wiper.
Tip
The original version of cipher.exe that was released with Windows 2000 does not include the data overwrite function. This was added in a version of the cipher tool that Microsoft released in June 2001 (and included in Windows 2000 SP3). The drive-wiping function is included in the cipher tool that comes with Windows XP.
Limitations of the cipher tool
Although the Cipher tool can do some things that the GUI can’t, you are still working with the same component (EFS) and must operate under some of the same limitations as when you encrypt and decrypt files the graphical way. The Cipher command doesn’t provide any way around the rule that a file or folder can’t be simultaneously encrypted and compressed, and Cipher can’t encrypt files or folders with the Read Only attribute or those with the System attribute. If you try to do so, you’ll get a message that access is denied. Click here to learn more about a potential EFS security concern.
One thing that you can’t do with the Cipher tool that you can do through the GUI is give other users cryptographic access to encrypted files or folders. Windows XP and 2003 Server (unlike Windows 2000) allow the person who encrypts a file to add other user accounts that enable others to view his/her encrypted data. This is done through the Encryption Details dialog box (accessed via the Details button on the Advanced Attributes property sheet). There is no mechanism for doing this with the cipher tool.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.