Encrypt/decrypt using Polybius square

Sep 16, 2013 at 5:36pm
I have a project assignment where I have to encrypt/decrypt a phrase using a Polybius Square.

I need to place the letters in a 2-d array (polybius square), and omit the duplicated letters. Once the phrase is in the table, fill out the rest of the table with the remaining letters of the alphabet. If anyone could check my code, and maybe give some advice, that would be awesome.

Thanks!

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// This program was created to translate a group of letters into a sequence of numeric codes
// Comp 1108
// Created by: 
// Last updated: 9/16/2013

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

main()
{
    string key, noRepeat;
    string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string table[5][5];
    cout << "Please enter the key: ";
    getline(cin, key);
    cout << key << endl;
    
    for(int i=0; i<key.length();i++)
    {   
        key[i]=toupper(key[i]);
    }
        cout << key <<endl;
    
    bool isLetter=false;
    bool found=false;
    for(int i=0;i<key.length();i++)
    {
        for(int j=0;j<noRepeat.length();j++)
        {
            if (key[i]==noRepeat[j])
                found=true;
        }
        for(int k=0; k < alphabet.length(); k++)
        {
            if (key[i]==alphabet[k])
                isLetter=true;
                  
        }
        if (!found && isLetter)
            noRepeat+=key[i];
        found=false;
        isLetter=false;
        
// need it to fill in rest of table with remaining alphabet

        for(int t=0; t < noRepeat.length(); t++)
        {
            for (int m=0; m < alphabet.length(); m++)
            {
                if (noRepeat[t]==alphabet[m])
            }
        } 
    
        
    }
    
    cout << noRepeat << endl;
    
    
    
    system("PAUSE");
    return 0;
}
Sep 18, 2013 at 9:25am
Does the code not work as intended?
Topic archived. No new replies allowed.