#ifndef VIGN_H
#define VIGN_H

#include <String.h>
#include <iostream.h>

//============================================================
// VIGN - The class VIGN represents a Vigenere key
//============================================================

class VIGN
{
public:
    int table[256];
    int len;

    VIGN(int l) : len(l)
        {
            if( len >= 256 )
            {
                cerr << "VIGN: illegal length" << endl;
            }

            for( int i=0; i<len; i++)
                table[i] = 0;
        }

    int Length()
        {
            return len;
        }
    
    void Set(int pos, int val)
        {
            table[pos] = val;
        }

    int Get(int pos)
        {
            return table[pos];
        }

    int Translate(int c, int pos)
        {
            return (c + table[pos%len]) % 27;
        }

    void PrintVign(ostream& o)
        {
            int i;
            for( i=0; i<Length(); i++ )
                o << table[i] << " ";

            o << "(";
            for( i=0; i<Length(); i++ )
                o << char(table[i] == 0 ? ' ' : table[i] - 1 + 'a');
            o << ")";

            o << "[";
            for( i=0; i<Length(); i++ )
                o << char(table[i] == 0 ? ' ' : 26-table[i] + 'a');
            o << "]";

            o << endl;
        }
};

#endif

