A cipher is an algorithm that will encrypt (and decrypt) data, most commonly text. Several types of
Question:
A cipher is an algorithm that will encrypt (and decrypt) data, most commonly text. Several types of cryptographic ciphers exist, but one of the simplest (albeit least secure) is the affine cipher. In an affine cipher, each letter in the unencrypted message is given a numeric representation (such as its ASCII value) and modified using a linear function of the form (ax + b) mod m, where
? x is a numeric form of the letter to encrypt
? a and b are the cryptographic keys
? m is the size of the alphabet
The values for a and b are called the keys of the cipher. The only constraint on these values is that a and m must be co-prime; that is, the greatest common divisor of a and m must be 1. Your task will be to write a program that will both encrypt any text file containing spaces, uppercase letters, and lowercase letters (you should leave all punctuation other than spaces unencrypted). You should map the input letters as follows (lower-case letters from 0 to 25; upper-case letters from 26 to 51; and whitespace to 52):
The input will be a text document containing both upper-case and lower-case letters, and the values for a and b. The value of m should be 53. The output of your program should be the encrypted contents of the input file displayed on standard output.
For example, given a = 3 and b = 4 and the text ?Hello? (note: m = 53):
1. Translate the input string to its numeric equivalent: 33 4 11 11 14
2. Perform the encryption on each of the numbers above, using the given encryption keys: 50 16 37 37 46
3. Translate the transformed numbers back to their alpha-numeric equivalent: ?YqLLU?
Place your code in a Java class called AffineCipher (the source file will be AffineCipher.java) and have it accept the value for a, the value for b, and the input file name from the command line. That is, your program should be executable from the command line by calling: ~>java AffineCipher 3 4 inputFile.txt which will output to the standard output
Discrete Mathematics and Its Applications
ISBN: 978-0073383095
7th edition
Authors: Kenneth H. Rosen