/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.vutbr.feec.utko.fojtoval.krypto.sifry;

/**
 * Sifrovani a desifrovani Vigenere.
 * @author fojtoval
 */
public class Vigenere extends Polyalfa{

    private String klic = null;

    /**
     * Sifrovani pomoci Vigenere.
     * @param zdroj otevreny text
     * @return zasifrovany text
     */
    @Override
    public String sifruj(String zdroj) {
        return Utils.zmenaTextuVig (zdroj, this.klic, true);
    }

    /**
     * Nastaveni a kontrola parametru sifry.
     * @param parametr
     */
    @Override
    public void setParametr(Object parametr) {

        if (parametr == null) {
            throw (new NullPointerException ("Parametr je null!"));
        } else if (!(parametr instanceof String)) {
                   throw (new IllegalArgumentException ("Parametr neni String! (" + parametr + ")"));
               }

          String key = (String)parametr;

          if (key.length() < 1 || key.length() > 30) {
              throw (new IllegalArgumentException ("Rozsah klice je 1-30 znaku. Bylo zadano " + klic.length() + "."));
		  }

          if (!key.matches ("^[a-z]+$")) {
              throw (new IllegalArgumentException ("Klic obsahuje nepovolene znaky."));
          }

          this.klic = key;

	}

  

    
    /**
     * Desifrovani sifrou Vigenere.
     * @param zdroj zasifrovany text
     * @return otevreny text
     */
    @Override
    public String lusti(String zdroj) {
        return Utils.zmenaTextuVigLus (zdroj, this.klic, true);
    }

    /**
     * Nevyuziva se, u tohoto typu sifry nelze urcit.
     * @return
     */
    @Override
    public String abecedaLusToString() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * Nevyuziva se, u tohoto typu sifry nelze urcit.
     * @return
     */
    @Override
    public String abecedaSifToString() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * Prevod klice na String.
     * @return klic
     */
    @Override
    public String vyslednyklic() {
        return String.valueOf (this.klic);
    }

    
}
