How do I define this?

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
http://img443.imageshack.us/my.php?image=webct6xy.jpg

From the picture, I need to assign values to each letter, A = 0, B = 1 etc etc so when my program runs, it reads the letters from an input file and changes it according to the algorithem.

Do I simply add int A = 0; int B = 0; in the main funciton or is there another way to do this? Any help would be appreciated.
 

talyn00

Golden Member
Oct 18, 2003
1,666
0
0
I'd make use of a character array.

if you had something like
char pl[] = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";

so then
pl[0] = 'A'
pl[1] = 'B'
....
pl[25] = 'Z'

the index value would match up correctly to right character.
 

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
Originally posted by: talyn00
I'd make use of a character array.

if you had something like
char pl[] = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";

so then
pl[0] = 'A'
pl[1] = 'B'
....
pl[25] = 'Z'

the index value would match up correctly to right character.

Havn't learned arrays prior to this lab, the prof told us we can use them, but the TAs won't help debug the code...so I'll need a lot of help :)

As for:

char pl[] = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";

so then
pl[0] = 'A'
pl[1] = 'B'
....
pl[25] = 'Z'

do I put it into the main function? and won't I need to use arrays throughout the whole lab?
 

talyn00

Golden Member
Oct 18, 2003
1,666
0
0
arrays aren't that hard to pickup. It's just simply a collection of items that are the same type. In this case, if you do define an array, it will simply be used as a lookup table to find the number which is equivalent to the letter.

I'm not quite following what the following is doing.



 

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
Originally posted by: talyn00
arrays aren't that hard to pickup. It's just simply a collection of items that are the same type. In this case, if you do define an array, it will simply be used as a lookup table to find the number which is equivalent to the letter.

I'm not quite following what the following is doing.

Well its a sample Caesar Cipher code I found online,

so if the characters are between a and z or A and Z, it will perform the caesar ciphe rformula, which is En = ( x +3 - n)mod26, m particular key is 56

so it will be (x + 3 - 56)mod26

where x is the letter I want to be encrypted.
 

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
Also found this code that does same thing, but how do I implement it into my lab?
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Originally posted by: talyn00
I'm not quite following what the following is doing.

I have to agree...what in god's name is going on ? lol

OK the last example makes a lot more sense. What is the lab? To create a caeser cipher or to map A to 0 and B to 1?
 

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
Originally posted by: xtknight
Originally posted by: talyn00
I'm not quite following what the following is doing.

I have to agree...what in god's name is going on ? lol

OK the last example makes a lot more sense. What is the lab? To create a caeser cipher or to map A to 0 and B to 1?

I'll just copy and paste what it says, maybe that will be better than me paraphrasing:

7.4 Laboratory Exercise
7.4.1 Purpose
The purpose of this laboratory exercise is to manipulate text data that was stored on
the computer hard disk, perform computations and analysis of data, and to store the
results on the computer hard disk using the Software Development Method.
7.4.2 Speci¯cation
The programmer is required to design and implement a program that encrypts and
decrypts messages using a Caesar/additive cipher and analyzes the ciphertext.
The program shall prompts the user with a menu choice of: 1) encryption, or 2)
decryption.
The program shall read in all the characters from an input data ¯le. A data ¯le
will be provided during the laboratory period and your program may not assume its
length, except that it will be more than one character. The fractional portion of any
displayed answer must be rounded to three decimal place accuracy. However, all
calculations must carry the full decimal accuracy.
For this cipher, only valid characters are to be encrypted/decrypted. The valid
set of characters are A, B, C, ... X, Y, Z. Any other character (e.g. a blank space)
are to be included, but not processed.
Note: n-dimensional arrays are not required for this lab. You may chose to use
them, but TAs will not assist in debugging errors related to the usage of arrays for
this lab.
1 - Encryption [2 marks]
When encrypting, the program shall assume an input ¯le name of plaintext.txt
and an output ¯lename of ciphertext.txt. The user does not need to input the ¯le
names; the programmer may hardcode them for this lab.
Each character shall be read in to the program individually, encrypted using the
assigned key (see Implementation Requirements), and written out to the hard disk.
Each time a character is encrypted, both the plaintext and ciphertext character are
Chapter 7. Lab 3: Introduction to Cryptography 61
to be displayed to the screen, clearly labeled and on a single line. The ciphertext
must also be analyzed (see Analysis of Ciphertext) and a summary report generated.
2 - Decryption [2 marks]
When decrypting, the program shall assume an input ¯le name of ciphertext.txt
and an output ¯lename of message.txt. The user does not need to input the ¯le
names; the programmer may hardcode them for this lab.
Each character shall be read in to the program individually, decrypted using the
assigned key (see Implementation Requirements), and written out to the hard disk.
Each time a character is decrypted, both the ciphertext and plaintext character are
to be displayed to the screen, clearly labeled and on a single line. The ciphertext
must also be analyzed (see Analysis of Ciphertext) and a summary report generated.
Analysis of Ciphertext [2 mark]
The following analyses are to be performed on the ciphertext and a neatly formatted
summary report displayed on the screen:
1. Sum the ASCII integer value of each character,
2. the mean of the data set (ASCII values),
3. the standard deviation of the entire data set (ASCII values),
4. the number of unique valid characters,
5. the relative frequency of all 26 valid characters as percent.