CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2011
    Posts
    3

    Cool One-word convention

    Hi

    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <vector>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        vector<string> dic;
    
        if (argc != 2) {
            cerr << "You must specify vocabulary (E.g. c:\\voc.txt)\n";
            return 33;
        }
        ifstream a(argv[1]);
        char b[256];
        while (a.getline(b, sizeof b))
            dic.push_back(string(b));
    
        string secret = "overturnedcomma";
    
        for (int w=0; w < dic.size(); w++)
        {
            int w_len = dic[w].size();
            int f;
    
            char *flags = new char[w_len];
            for (f=0; f < w_len; f++)
                flags[f] = '-';
    
            string word = dic[w];
    
            int secr_len = secret.size();
    
            for (int n=0; n < secr_len; n++)
            {
                char d = secret[n];
                for (int s=0; s < w_len; s++)
                {
                    if (word[s] == d && flags[s] == '-')
                    {
                        flags[s] = 'x';
                        break;
                    }
                }
            }
    
            int Accumulator = 0;
    
            for (f=0; f < w_len; f++)
                Accumulator += (int) ( flags[f] == 'x' ) ;
    
            if (Accumulator == w_len)
                cout << word << endl;
    
            delete[] flags;
        }
    }

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: One-word convention

    Hi,

    Did you have a question...?
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Dec 2011
    Posts
    3

    Re: One-word convention

    Maybe question is "How this algorithm can be used in practice?".

    I see few areas, for example we can encode book/song/film title and use another words
    to refer to that title. For example Garbage song "Dog new tricks" can sound like
    "network doctrine".

    ---

  4. #4
    Join Date
    Dec 2011
    Posts
    3

    Re: One-word convention

    Quote Originally Posted by BioPhysEngr View Post
    Hi,

    Did you have a question...?
    How this algorithm can be used in practice maybe?

    If we take book/song/film their title can be encoded to set of words - Garbage song "Dog new
    tricks" will sound like "network doctrine".

    Also it is possible to create secret message (very short) that lately can be decrypted.

    If you have a letter with obvious informative words it can be collapsed to such message.

    Interesting, what type of GUI can be constructed for this kind of text processing?

    Elena and Grizzlies -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured