Encrypting is just a fancy term for changing the format of data so other people can't read the data easily( in the best cases, they can't read it at all). So then decrypting is just restoring the changed data back to it original format.
X -->
Encrypting
Program--> X' -->
Decrypting
Program--> X Where X is the original data and X' is the changed (or encrypted) data.
Depending on how good the algorithm used by the Encrypting/Decrypting program pair, to more (or less) secure the encrypted data is. We will use an algorithm that give us "OK" security but nothing you would want to use if you really wanted to make an unbreakable code.
To make things a little more easier (and a bit less secure), we will use an algorithm in which uses the same program for both the Encrypting program and the Decrypting program. Thus:
X -->
Encryption
Program--> X' -->
Encryption
Program--> X
We will do two changes to the sound data to encrypt it. We will
The blocks of data will consist of some number of consectutive samples from the sound object. This number will be called the block size This number will be specified by the user when encrypting or decrypting the sound object. So in order to properly decrypt the sound object, the block size used must be the same as the block size used when the sound was encrypted. A good value for the block size would be between 1000 to 15000. Since a sound object normally has 22,050 sample per second, a block size of 2205 would give us 10 blocks per second (or have each block be 0.1 second long). A block size of 11,025 would give us 2 blocks per second.
At some point we will need to translate block numbers into sample indexes. The following table should help us figure out how to do this translation. The table assumes that you are using the JES function of getSampleValueAt() or setSampleValueAt() when accessing the samples from a sound object.
Block Size 1000 2205 5000 11025 b Block Number Starting
Sample
indexEnding
Sample
IndexStarting
Sample
indexEnding
Sample
IndexStarting
Sample
indexEnding
Sample
IndexStarting
Sample
indexEnding
Sample
IndexStarting
Sample
indexEnding
Sample
Index1 1 1000 1 2205 1 5000 1 11025 1 b 2 1001 2000 2206 4410 5001 10000 11026 22050 b+1 2*b 3 2001 3000 4411 6615 10001 15000 22051 33075 (2*b)+1 3*b 4 3001 4000 6615 8820 15001 20000 33076 44100 (3*b)+1 4*b i ((i-1)*b)+1 i*b
Fib(1) = 1 Fib(2) = 1 Fib(3) = Fib(1) + Fib(2) = 2 Fib(4) = Fib(2) + Fib(3) = 3 Fib(5) = Fib(3) + Fib(4) = 5 Fib(6) = Fib(4) + Fib(5) = 8 Fib(7) = Fib(5) + Fib(6) = 13 Fib(8) = Fib(6) + Fib(7) = 21 Fib(9) = Fib(7) + Fib(8) = 44 Fib(10) = Fib(8) + Fib(9) = 65 ... Fib(n) = Fib(n-2) + Fib(n-1)
For our encryption algorithm, we will swap the (Fib(n))-th block with the (2*(Fib(n))-th block. Thus we will swap the following blocks:
Note that the first two swaps do the same thing. So the second swap undoes the first swap. We will continue to swap values as long as the value of 2*Fib(n) is less than the number of blocks in the sound object.
Swap 1: Swap block 1 with block 2 Swap 2: Swap block 1 with block 2 Swap 3: Swap block 2 with block 4 Swap 4: Swap block 3 with block 6 Swap 5: Swap block 5 with block 10 Swap 6: Swap block 8 with block 16 Swap 7: Swap block 13 with block 26 Swap 8: Swap block 21 with block 42 Swap n: Swap block Fib(n) with block 2*Fib(n)
This function called encrypt() that takes two parameters: a sound object and an integer block size. This function is to return the modified sound object.
This function will be the driver that calls encrypt(). This function is to prompt the user for sound file, create a sound object from that file, call encrypt with some block size, play the returned sound object and store in a file the returned sound object.
This function is to take an integer n as its parameter and it will return the n-th value in the fibonacci sequence. If the parameter value given is zero or less, return the value of 1.
This function will swap two blocks from a sound object. This function is to take four parameters.
This function will reverse the samples in a block of a sound object. This function will take three parameters.
Step Code Value in val1 Value in val2 Value in val3 0.1 val1 = 8 8 0.2 val1 = 5 8 5 1 val3 = val1 8 5 8 2 val1 = val2 5 5 8 3 val2 = val3 5 8 8
Your code must be commented and written in good programming style. You are to submit your final program to the digital drop box on the CS 101 Blackboard site.