Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
intial guess class
  • Loading branch information
cowang4 committed Mar 11, 2016
1 parent a46a1cf commit 5354be4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions guess.h
@@ -0,0 +1,37 @@
#include <vector>
#include <string>

using namespace std;

class Guess {
public:
Guess();
void transform_alphabet(vector<string> &cypher_text);
void transform_letter(char oldc, char newc, vector<string> &cypher_text);
private:
char alphabet[26];
};

Guess::Guess() {
for (int i = 0; i < 26; ++i) {
alphabet[i] = static_cast<char>(i+97);
}
}

void Guess::transform_alphabet(vector<string> &cypher_text) {
for (unsigned int i = 0; i < cypher_text.size(); ++i) {
for (unsigned int k = 0; k < cypher_text[i].size(); ++k) {
cypher_text[i][k] = alphabet[static_cast<unsigned int>(cypher_text[i][k])];
}
}
}

void Guess::transform_letter(char oldc, char newc, vector<string> &cypher_text) {
alphabet[static_cast<unsigned int>(oldc)-97] = newc;
for (unsigned int i = 0; i < cypher_text.size(); ++i) {
for (unsigned int k = 0; k < cypher_text[i].size(); ++k) {
if (cypher_text[i][k] == oldc)
cypher_text[i][k] = newc;
}
}
}

0 comments on commit 5354be4

Please sign in to comment.