1 /*
2  *cryptoslam: A tool for decoding cryptograms
3  *
4  *Copyright (C) 1997,2000,2003 Brian Enigma
5  *                             enigma@netninja.com
6  *                             http://sourceforge.net/projects/cryptoslam/
7  *
8  *   This program is free software; you can redistribute it and/or
9  *   modify it under the terms of the GNU General Public License as
10  *   published by the Free Software Foundation; either version 2 of
11  *   the License, or (at your option) any later version.
12  *
13  *   This program is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or EXISTANCE OF KITTEN.  See the GNU General
16  *   Public License for more details.
17  *
18  *   http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21 
22 #ifndef _CRYPTOGRAM_H_
23 #define _CRYPTOGRAM_H_
24 
25 #include <curses.h>
26 #include <string>
27 #include <map>
28 using namespace std;
29 
30 typedef multimap<int, string> wordDistribution_t;
31 typedef pair<int, string> wordDistributionPair_t;
32 
33 #define SAMPLE_TEXT \
34 "Welcome to Cryptoslam!  This program has been designed to help you solve\n" \
35 "those pencil-and-paper cryptograms found in newspapers and puzzle \n"\
36 "magazines.  Hit a key from the menu bar above.  S,U,R let you change the\n"\
37 "substitution values.  F lets you create, load, or save a file.  S gives you\n"\
38 "good statistics.  Load the file \"sample.txt\" to try it out.  (You could\n"\
39 "have also given the filename on the command line).\n"
40 
41 #define FILE_HEADER "CGFILE1"
42 
43 class Cryptogram
44 {
45 public:
46     Cryptogram();
47     ~Cryptogram();
48 
49     void reset();
50     void calcPlaintext();
51     void set(char cypherLetter, char plainLetter);
52     void unset(char cypherLetter);
53     void randomizeKeys();
54     void randomizeMessage();
55     void newRandomMessage();
56     void loadFile(const char *file);
57     void saveFileText(const char *file);
58     void saveFileBinary(const char *file);
59     void loadKeys(const char *file);
60     void saveKeys(const char *file);
61 
62     void paintAlphabet(WINDOW *w);
63     void paintMessage(WINDOW *w);
64     void paintStats(WINDOW *w);
65 
66 protected:
67     string cyphertext;
68     string plaintext;
69     char alphabet[26];
70     char textcolor[26];
71 
72     void letterDistribution(char letters[], int counts[]);
73     wordDistribution_t wordDistribution();
74 
75     static char normalize(char letter);
76     static bool isKey(char letter);
77 };
78 
79 #endif
80 
81