In C#
1. Write a program called "encrypt" that encrypts a file using a not very secure encryption method. It will read the file byte by byte and move the bits of each byte around as described below. Your program will take 2 command line arguments: an input file and an output file.
A nybble (or nibble) is a group of 4 bits, so a byte, which has 8 bits, has 2 nybbles. You will encrypt each byte by swapping adjacent pairs of bits in each nybble and reversing the nybbles. For example, if the bits are "abcdefgh", then after reversing, they will be "ghefcdab".
Of course, running the same program on an encrypted file will decrypt it.
You must have a function:
public static byte Encrypt(byte b) { ... }
that does the reversing.
You can read all the bytes in a file using File.ReadAllBytes(filename). This will return an array of bytes. After reversing all the bytes, you can write them back out using File.WriteAllBytes(filename, bytes) where "bytes" is the array containing the bytes.
You will need to check for the presence of command line arguments and catch IOExceptions and print appropriate messages and exit when errors occur. You will also need to use System.IO.
2. Write a method:
public static byte AddParity(byte b) { ... }
that returns its argument with a parity bit added. The parity bit will be the leftmost bit. It will be set to 1 if the number of other bits is odd, and left at 0 if the number of other bits is even. You may assume that the argument is an ASCII character that has a 0 in the leftmost bit. In other words, it is less than 128.
Include your method in a public class called "Parity". I will compile it together with my own test program. You can test your function by printing numbers in binary using the method Convert.ToString(b, 2).
Important: You must use bit operations for the functions (bitwise and, bitwise or, and shifts). These operations actually return ints, so you will need to typecast the return value to byte. Like this: return (byte) (...).