Code Review XEDecryption

(Using MS VC++ 2010)
The program i'm designing is to decypher an XECrypted message; i'm still in the process of understanding more complicated functions (pointers/Log*N/dynamic arrays/etc) so please allow me to narrow down what i'm looking for, here's what i seek:

(NOTE: Please keep in mind that it's tremendously helpful for me, and others learning, to provide some sort of guidance; don't give me the answer, but direct me to where i should look.. Saying something like "you should check out arrays" helps more than "Your syntax sucks." Thanks for taking the time)

a) Where i'm currently stuck << Sorting the algorithm for most common char. I still haven't been able to find an up-to-date tutorial / explanation on the technique.. Being specific will really help me here because i don't truly understand less logical code (e.g. O*Log*N, etc). I understand that i must store each "set" and then store a count of how frequently that number occurs; which is probably RAM intensive. A more efficient guidance would be appreciated.

b) To me, storing the int message [] ( ###, ###, ...) seems to produce errors; while this seems like standard cpp code, i'm curious if it could be producing a buffer overflow due to how many numbers are accessed, or that numbers are being accessed by the address of a number (e.g. Slot "1" = "362") causing the program to crash with garbage. Guidance on a better array / str / enum / etc would be appreciated

c) At the end of the program;
- else {...}//noobie error catch to reinput correct number
i've been wondering if this is bad practice; it seems like it wouldn't catch many errors.. for example if the user accidentally hits 7766 instead of 776 then the program may return special chars (potentially crashing the program w/ buffer overflow??).. Is there a better way to catch said problems?

And now for the code;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// XEDecrypter.cpp : Defines the entry point for the console application.
//
#include "StdAfx.h"
using namespace std;



	int a, b, x, y, z, sum; // make some temp variables
	int offset; // # to be subtracted later, from a variable, to obtain ASCII dec reference

	int message [] = {		296, 294, 255, 268, 313, ...}; //truncated, there are 1098 numbers in this array, each 3 numbers signifies 1 character in ASCII

int main () {

/*START LOOP*/
for (b=0; b<1098; b++) {
	x = message[b]; y = message[b+1]; z = message[b+2];
	sum = x+y+z

/* I need to find a way to sort the algorithm sets ("sum") for the most common occurance */
	count occurance of each set of 3 numbers
	for sum count occurance of each set of numbers 

		if (!offset) { break; } //if offset has not been defined, skip
		else {	sum-= offset
				cout << iota(sum); //print while converting integer to char (decASCII to chrASCII)
				b+=2 //increase i to skip previous numbers in set
		}
} /*END LOOP*/

//Ask if the message is readable, if not loop program again using new number as input
	cout << “if readable press y; otherwise enter the offset” << endl;
	cin >> a;

	if (a=’y’) { return EXIT_SUCCESS; } //if a is "y" exit
	else if (isdigit(a)) { offset = a; } //else check if it's a number
	else { cout << “Re-enter selection” << endl; cin >> a; } //noobie error catch to reinput correct number

} /*END MAIN*/


Updates::
5/9/2012 - Learned about what i call inheritence.. Variables need to be flushed before adding new data to said variable. Going to try rewriting this script as a class and use bools to test if variables are null; if they aren't null run script; if they are null then destruct storage.
Last edited on
Topic archived. No new replies allowed.