Encryption(Code table)

deleted
Last edited on
// TESt IS CHARACTER BEEN USED,,,,,, HOW???

An array of 26 bools works just fine for that.
1
2
3
4
5
bool used[26];

bool isUsed(bool used[], char currentC)
{   return used[currentC - 'a'];  
}

Don't forget to initialize the array elements to false.

If you're adventurous, you can use std::bitset instead.

line 38: Remove the ; It terminates the if statement.

line 40: Don't you mean to use reverseAlphabet ?

line 34: reverseAlphabet really isn't needed. Just subtract index from 26.

line 34: You have two g's in reverseAlphabet.

Last edited on
I get line 38.
line 40. I want to assign UNUSED chars from reverse alphabet to a next character in alphabet.
So "i" is looping thru reverse alphabet, first true character(means is not used) will enter block and be assigned to next character in alphabet(loop above that) I know it seems confusing.

If I initialize array to false then to enter the loop I will need false value. I get logic but my logic is that if it is not been used it is true, once I use it I need to set it to false and next time I will not enter the loop if I have that character again.
The only thing about it, I still don't get you sample code for bool. What is it doing?
And is my code any good, is it doing anything and how can I check return(new code table with cout?)
Like I said, this is just part of the program, I will need to pass this new code table to another func, receive input file stream and then encrypt text.
I chose to call the array "used", because your function was already names "isUsed". If a character is not used, then the value is false. If a character is used, then the value is true. If you want to know if a character is not used, you can simply test:
 
  if (! isUsed(used,c)) 


If you don't like that, change the name of the array to "not_used" and initialize it to true.

I still don't get you sample code for bool. What is it doing?

line 1: used is a 26 element array of bools initialized to false. One bool per letter of the alphabet (or reverseAlphabet, if you wish).

line 4: Tests the element of the array corresponding to currentC. The - 'a' subtracts the ASCII value of 'a' from currentC so that the index is 0 based. The assumption here is that when you use a letter from the alphabet, you set the corresponding element of used to true.

Last edited on
Thank you for your replies, I really appritiate it.
I have to finish this assignment in 3-4 hours so I am working on it.

I just edited my post per you instructions.
Is it doing anything now? Is there any way to test it?
Why did you delete your initial post? You've just made this thread useless for others to learn from.

Please restore your post, so that this thread can be a useful resource for others.
Topic archived. No new replies allowed.